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...) 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, first | |
Ilya Sherman
2014/06/11 00:19:38
nit: "table, first has" -> "table. The first has t
Lukasz Jagielski
2014/06/11 16:10:16
Done.
| |
52 // has httpRealm column filled with non-empty string, therefore resulting | |
53 // PasswordForm should have SCHEME_BASIC in scheme. Second entry has NULL | |
Ilya Sherman
2014/06/11 00:19:38
nit: "Second entry" -> "The second entry"
Lukasz Jagielski
2014/06/11 16:10:16
Done.
| |
54 // httpRealm, so it should produce a SCHEME_HTML PasswordForm. | |
55 TEST(FirefoxImporterTest, MAYBE_NSS(FirefoxNSSDecryptorDeduceAuthScheme)) { | |
56 base::ScopedTempDir temp_dir; | |
57 base::FilePath signons_path = temp_dir.path().AppendASCII("signons.sqlite"); | |
58 sql::Connection db_conn; | |
59 | |
60 ASSERT_TRUE(db_conn.Open(signons_path)); | |
61 | |
62 ASSERT_TRUE(db_conn.Execute( | |
63 "CREATE TABLE moz_logins (id INTEGER PRIMARY KEY, hostname TEXT NOT " | |
64 "NULL, httpRealm TEXT, formSubmitURL TEXT, usernameField TEXT NOT NULL," | |
65 "passwordField TEXT NOT NULL, encryptedUsername TEXT NOT NULL," | |
66 "encryptedPassword TEXT NOT NULL, guid TEXT, encType INTEGER," | |
67 "timeCreated INTEGER, timeLastUsed INTEGER, timePasswordChanged " | |
68 "INTEGER, timesUsed INTEGER)")); | |
69 | |
70 ASSERT_TRUE(db_conn.Execute( | |
71 "CREATE TABLE moz_disabledHosts (id INTEGER PRIMARY KEY, hostname TEXT " | |
72 "UNIQUE ON CONFLICT REPLACE)")); | |
73 | |
74 ASSERT_TRUE(db_conn.Execute( | |
75 "INSERT INTO 'moz_logins' VALUES(1,'http://server.com:1234'," | |
76 "'http_realm',NULL,'','','','','{bfa37106-a4dc-0a47-abb4-dafd507bf2db}'," | |
77 "1,1401883410959,1401883410959,1401883410959,1)")); | |
78 | |
79 ASSERT_TRUE(db_conn.Execute( | |
80 "INSERT INTO 'moz_logins' VALUES(2,'http://server.com:1234',NULL," | |
81 "'http://test2.server.com:1234/action','username','password','',''," | |
82 "'{71ad64fa-b5d4-cf4d-b390-2e4d56fe2aff}',1,1401883939239," | |
83 "1401883939239, 1401883939239,1)")); | |
84 | |
85 db_conn.Close(); | |
86 | |
87 base::FilePath nss_path; | |
88 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | |
89 #if defined(OS_MACOSX) | |
90 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); | |
91 #else | |
92 nss_path = nss_path.AppendASCII("firefox3_nss"); | |
93 #endif // !OS_MACOSX | |
94 base::FilePath db_path; | |
95 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | |
96 db_path = db_path.AppendASCII("firefox3_profile"); | |
97 | |
98 FFUnitTestDecryptorProxy decryptor_proxy; | |
99 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | |
100 | |
101 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | |
102 std::vector<autofill::PasswordForm> forms = | |
103 decryptor_proxy.ParseSignons(signons_path); | |
104 | |
105 ASSERT_EQ(2u, forms.size()); | |
106 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); | |
107 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); | |
108 } | |
OLD | NEW |