no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / security / manager / ssl / tests / unit / test_client_auth_remember_service_read.js
blob6b8d4f6e0de2747a3f6e762a69036e19a3a5768a
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
6 // This tests that the nsIClientAuthRememberService correctly reads its backing
7 // state file.
9 function run_test() {
10   let stateFile = do_get_profile();
11   stateFile.append(CLIENT_AUTH_FILE_NAME);
12   let outputStream = FileUtils.openFileOutputStream(stateFile);
13   let keyValuePairs = [
14     {
15       key: "example.com,C9:65:33:89:EE:DC:4D:05:DA:16:3D:D0:12:61:BC:61:21:51:AF:2B:CC:C6:E1:72:B3:78:23:0F:13:B1:C7:4D,",
16       value: "AAAA",
17     },
18     {
19       key: "example.com,C9:65:33:89:EE:DC:4D:05:DA:16:3D:D0:12:61:BC:61:21:51:AF:2B:CC:C6:E1:72:B3:78:23:0F:13:B1:C7:4D,^partitionKey=%28https%2Cexample.com%29",
20       value: "BBBB",
21     },
22     { key: "example.test,,", value: "CCCC" },
23   ];
24   for (let keyValuePair of keyValuePairs) {
25     append_line_to_data_storage_file(
26       outputStream,
27       1,
28       1,
29       keyValuePair.key,
30       keyValuePair.value,
31       1024
32     );
33   }
35   let clientAuthRememberService = Cc[
36     "@mozilla.org/security/clientAuthRememberService;1"
37   ].getService(Ci.nsIClientAuthRememberService);
39   let dbKey = {};
40   ok(
41     clientAuthRememberService.hasRememberedDecisionScriptable(
42       "example.com",
43       {},
44       dbKey
45     )
46   );
47   equal(dbKey.value, "AAAA");
49   dbKey = {};
50   ok(
51     clientAuthRememberService.hasRememberedDecisionScriptable(
52       "example.com",
53       { partitionKey: "(https,example.com)" },
54       dbKey
55     )
56   );
57   equal(dbKey.value, "BBBB");
59   ok(
60     !clientAuthRememberService.hasRememberedDecisionScriptable(
61       "example.org",
62       {},
63       {}
64     )
65   );
66   ok(
67     !clientAuthRememberService.hasRememberedDecisionScriptable(
68       "example.com",
69       { partitionKey: "(https,example.org)" },
70       {}
71     )
72   );
74   dbKey = {};
75   ok(
76     clientAuthRememberService.hasRememberedDecisionScriptable(
77       "example.test",
78       {},
79       dbKey
80     )
81   );
82   equal(dbKey.value, "CCCC");