Bug 1305531 - Add test cases to test_sdr.js to ensure recommended way of using encryptString() and decryptString() works. r=keeler
MozReview-Commit-ID: 5vPxUZyzGSz
--- a/security/manager/ssl/tests/unit/test_sdr.js
+++ b/security/manager/ssl/tests/unit/test_sdr.js
@@ -29,32 +29,42 @@ function run_test() {
loginToDBWithDefaultPassword();
let sdr = Cc["@mozilla.org/security/sdr;1"]
.getService(Ci.nsISecretDecoderRing);
// Test valid inputs for encryptString() and decryptString().
let inputs = [
"",
+ " ", // First printable latin1 character (code point 32).
"foo",
- "1234567890`~!#$%^&*()-_=+{[}]|\\:;'\",<.>/?",
+ "1234567890`~!@#$%^&*()-_=+{[}]|\\:;'\",<.>/?",
+ "¡äöüÿ", // Misc + last printable latin1 character (code point 255).
+ "aaa 一二三", // Includes Unicode with code points outside [0, 255].
];
for (let input of inputs) {
- let encrypted = sdr.encryptString(input);
+ let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
+ .createInstance(Ci.nsIScriptableUnicodeConverter);
+ converter.charset = "UTF-8";
- notEqual(input, encrypted,
- "Encypted input should not just be the input itself");
+ let convertedInput = converter.ConvertFromUnicode(input);
+ convertedInput += converter.Finish();
+
+ let encrypted = sdr.encryptString(convertedInput);
+
+ notEqual(convertedInput, encrypted,
+ "Encrypted input should not just be the input itself");
try {
atob(encrypted);
} catch (e) {
ok(false, `encryptString() should have returned Base64: ${e}`);
}
- equal(input, sdr.decryptString(encrypted),
+ equal(convertedInput, sdr.decryptString(encrypted),
"decryptString(encryptString(input)) should return input");
}
// Test invalid inputs for decryptString().
throws(() => sdr.decryptString("*"), /NS_ERROR_ILLEGAL_VALUE/,
"decryptString() should throw if given non-Base64 input");
// Test calling changePassword() pops up the appropriate dialog.