OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/files/scoped_temp_dir.h" |
6 #include "base/path_service.h" | 7 #include "base/path_service.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/common/chrome_paths.h" | 9 #include "chrome/common/chrome_paths.h" |
9 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" | 10 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
10 #include "chrome/utility/importer/nss_decryptor.h" | 11 #include "chrome/utility/importer/nss_decryptor.h" |
| 12 #include "sql/connection.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | 15 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 |
14 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 16 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
15 #define MAYBE_NSS(x) DISABLED_##x | 17 #define MAYBE_NSS(x) DISABLED_##x |
16 #else | 18 #else |
17 #define MAYBE_NSS(x) x | 19 #define MAYBE_NSS(x) x |
18 #endif | 20 #endif |
19 | 21 |
20 // The following test requires the use of the NSSDecryptor, on OSX this needs | 22 // The following test requires the use of the NSSDecryptor, on OSX this needs |
(...skipping 16 matching lines...) Expand all Loading... |
37 | 39 |
38 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 40 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); |
39 EXPECT_EQ(base::ASCIIToUTF16("hello"), | 41 EXPECT_EQ(base::ASCIIToUTF16("hello"), |
40 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" | 42 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" |
41 "jtRg4qFSHBAhv9luFkXgDJA==")); | 43 "jtRg4qFSHBAhv9luFkXgDJA==")); |
42 // Test UTF-16 encoding. | 44 // Test UTF-16 encoding. |
43 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"), | 45 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"), |
44 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" | 46 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" |
45 "qqiccfQHWBAie74hxnULxlw==")); | 47 "qqiccfQHWBAie74hxnULxlw==")); |
46 } | 48 } |
| 49 |
| 50 // The following test verifies proper detection of authentication scheme in |
| 51 // firefox's signons db. We insert two entries into moz_logins table. The first |
| 52 // has httpRealm column filled with non-empty string, therefore resulting |
| 53 // PasswordForm should have SCHEME_BASIC in scheme. The second entry has NULL |
| 54 // httpRealm, so it should produce a SCHEME_HTML PasswordForm. |
| 55 TEST(FirefoxImporterTest, MAYBE_NSS(FirefoxNSSDecryptorDeduceAuthScheme)) { |
| 56 base::ScopedTempDir temp_dir; |
| 57 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 58 base::FilePath signons_path = temp_dir.path().AppendASCII("signons.sqlite"); |
| 59 sql::Connection db_conn; |
| 60 |
| 61 ASSERT_TRUE(db_conn.Open(signons_path)); |
| 62 |
| 63 ASSERT_TRUE(db_conn.Execute( |
| 64 "CREATE TABLE moz_logins (id INTEGER PRIMARY KEY, hostname TEXT NOT " |
| 65 "NULL, httpRealm TEXT, formSubmitURL TEXT, usernameField TEXT NOT NULL," |
| 66 "passwordField TEXT NOT NULL, encryptedUsername TEXT NOT NULL," |
| 67 "encryptedPassword TEXT NOT NULL, guid TEXT, encType INTEGER," |
| 68 "timeCreated INTEGER, timeLastUsed INTEGER, timePasswordChanged " |
| 69 "INTEGER, timesUsed INTEGER)")); |
| 70 |
| 71 ASSERT_TRUE(db_conn.Execute( |
| 72 "CREATE TABLE moz_disabledHosts (id INTEGER PRIMARY KEY, hostname TEXT " |
| 73 "UNIQUE ON CONFLICT REPLACE)")); |
| 74 |
| 75 ASSERT_TRUE(db_conn.Execute( |
| 76 "INSERT INTO 'moz_logins' VALUES(1,'http://server.com:1234'," |
| 77 "'http_realm',NULL,'','','','','{bfa37106-a4dc-0a47-abb4-dafd507bf2db}'," |
| 78 "1,1401883410959,1401883410959,1401883410959,1)")); |
| 79 |
| 80 ASSERT_TRUE(db_conn.Execute( |
| 81 "INSERT INTO 'moz_logins' VALUES(2,'http://server.com:1234',NULL," |
| 82 "'http://test2.server.com:1234/action','username','password','',''," |
| 83 "'{71ad64fa-b5d4-cf4d-b390-2e4d56fe2aff}',1,1401883939239," |
| 84 "1401883939239, 1401883939239,1)")); |
| 85 |
| 86 db_conn.Close(); |
| 87 |
| 88 base::FilePath nss_path; |
| 89 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); |
| 90 #if defined(OS_MACOSX) |
| 91 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); |
| 92 #else |
| 93 nss_path = nss_path.AppendASCII("firefox3_nss"); |
| 94 #endif // !OS_MACOSX |
| 95 base::FilePath db_path; |
| 96 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
| 97 db_path = db_path.AppendASCII("firefox3_profile"); |
| 98 |
| 99 FFUnitTestDecryptorProxy decryptor_proxy; |
| 100 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); |
| 101 |
| 102 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); |
| 103 std::vector<autofill::PasswordForm> forms = |
| 104 decryptor_proxy.ParseSignons(signons_path); |
| 105 |
| 106 ASSERT_EQ(2u, forms.size()); |
| 107 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); |
| 108 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); |
| 109 } |
OLD | NEW |