mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1243193 - Use Assert.throws() more in PSM tests. r=keeler
This commit is contained in:
parent
88519e1241
commit
6539d69a61
@ -53,14 +53,8 @@ function encodeCommonNameAsBytes(commonName) {
|
||||
}
|
||||
|
||||
function testInvalidDBKey(certDB, dbKey) {
|
||||
let exceptionCaught = false;
|
||||
try {
|
||||
let cert = certDB.findCertByDBKey(dbKey);
|
||||
} catch(e) {
|
||||
do_print(e);
|
||||
exceptionCaught = true;
|
||||
}
|
||||
ok(exceptionCaught, "should have thrown and caught an exception");
|
||||
throws(() => certDB.findCertByDBKey(dbKey), /NS_ERROR_ILLEGAL_INPUT/,
|
||||
`findCertByDBKey(${dbKey}) should raise NS_ERROR_ILLEGAL_INPUT`);
|
||||
}
|
||||
|
||||
function testDBKeyForNonexistentCert(certDB, dbKey) {
|
||||
|
@ -35,26 +35,22 @@ function testGood(data) {
|
||||
}
|
||||
|
||||
function testBad(data) {
|
||||
try {
|
||||
let cert = certDB.constructX509FromBase64(data.input);
|
||||
ok(false, `Should have gotten an exception for "${data.input}"`);
|
||||
} catch (e) {
|
||||
equal(e.result, data.result,
|
||||
"Actual and expected exception result should match");
|
||||
}
|
||||
throws(() => certDB.constructX509FromBase64(data.input), data.result,
|
||||
`Should get "${data.result}" for "${data.input}"`);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
const badCases = [
|
||||
// Wrong type or too short
|
||||
{ input: null, result: Cr.NS_ERROR_ILLEGAL_VALUE },
|
||||
{ input: "", result: Cr.NS_ERROR_ILLEGAL_VALUE },
|
||||
{ input: "=", result: Cr.NS_ERROR_ILLEGAL_VALUE },
|
||||
{ input: "==", result: Cr.NS_ERROR_ILLEGAL_VALUE },
|
||||
{ input: null, result: /NS_ERROR_ILLEGAL_VALUE/ },
|
||||
{ input: "", result: /NS_ERROR_ILLEGAL_VALUE/ },
|
||||
{ input: "=", result: /NS_ERROR_ILLEGAL_VALUE/ },
|
||||
{ input: "==", result: /NS_ERROR_ILLEGAL_VALUE/ },
|
||||
// Not base64
|
||||
{ input: "forty-four dead stone lions", result: Cr.NS_ERROR_ILLEGAL_VALUE },
|
||||
{ input: "forty-four dead stone lions", result: /NS_ERROR_ILLEGAL_VALUE/ },
|
||||
// Not a cert
|
||||
{ input: "Zm9ydHktZm91ciBkZWFkIHN0b25lIGxpb25z", result: Cr.NS_ERROR_FAILURE }
|
||||
{ input: "Zm9ydHktZm91ciBkZWFkIHN0b25lIGxpb25z",
|
||||
result: /NS_ERROR_FAILURE/ },
|
||||
];
|
||||
|
||||
// Real certs with all three padding levels
|
||||
|
@ -16,16 +16,10 @@ function connect_and_teardown() {
|
||||
|
||||
let reader = {
|
||||
onInputStreamReady: function(stream) {
|
||||
try {
|
||||
stream.available();
|
||||
Assert.ok(false, "stream.available() should have thrown");
|
||||
}
|
||||
catch (e) {
|
||||
Assert.equal(e.result, Components.results.NS_ERROR_FAILURE,
|
||||
"stream should be in an error state");
|
||||
Assert.ok(tearDown, "this should be as a result of logoutAndTeardown");
|
||||
run_next_test();
|
||||
}
|
||||
throws(() => stream.available(), /NS_ERROR_FAILURE/,
|
||||
"stream should be in an error state");
|
||||
ok(tearDown, "A tear down attempt should have occurred");
|
||||
run_next_test();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -149,12 +149,10 @@ function checkStateRead(aSubject, aTopic, aData) {
|
||||
checkDefaultSiteHPKPStatus();
|
||||
|
||||
// failure to insert new pin entry leaves previous pin behavior
|
||||
try {
|
||||
throws(() => {
|
||||
gSSService.setKeyPins("a.pinning2.example.com", true, 1000, 1,
|
||||
["not a hash"]);
|
||||
ok(false, "Attempting to set an invalid pin should have failed");
|
||||
} catch(e) {
|
||||
}
|
||||
}, /NS_ERROR_ILLEGAL_VALUE/, "Attempting to set an invalid pin should fail");
|
||||
checkFail(certFromFile('cn-a.pinning2.example.com-badca'), "a.pinning2.example.com");
|
||||
checkOK(certFromFile('cn-a.pinning2.example.com-pinningroot'), "a.pinning2.example.com");
|
||||
checkOK(certFromFile('cn-x.a.pinning2.example.com-badca'), "x.a.pinning2.example.com");
|
||||
@ -170,12 +168,11 @@ function checkStateRead(aSubject, aTopic, aData) {
|
||||
checkDefaultSiteHPKPStatus();
|
||||
|
||||
// Incorrect size results in failure
|
||||
try {
|
||||
throws(() => {
|
||||
gSSService.setKeyPins("a.pinning2.example.com", true, 1000, 2,
|
||||
["not a hash"]);
|
||||
ok(false, "Attempting to set a pin with an incorrect size should have failed");
|
||||
} catch(e) {
|
||||
}
|
||||
}, /NS_ERROR_XPC_NOT_ENOUGH_ELEMENTS_IN_ARRAY/,
|
||||
"Attempting to set a pin with an incorrect size should fail");
|
||||
|
||||
// Ensure built-in pins work as expected
|
||||
ok(!gSSService.isSecureHost(Ci.nsISiteSecurityService.HEADER_HPKP,
|
||||
|
@ -25,13 +25,10 @@ function checkFailParseInvalidPin(pinValue) {
|
||||
let sslStatus = new FakeSSLStatus(
|
||||
certFromFile('cn-a.pinning2.example.com-pinningroot'));
|
||||
let uri = Services.io.newURI("https://a.pinning2.example.com", null, null);
|
||||
try {
|
||||
throws(() => {
|
||||
gSSService.processHeader(Ci.nsISiteSecurityService.HEADER_HPKP, uri,
|
||||
pinValue, sslStatus, 0);
|
||||
ok(false, "Invalid pin should have been rejected");
|
||||
} catch (e) {
|
||||
ok(true, "Invalid pin should be rejected");
|
||||
}
|
||||
}, /NS_ERROR_FAILURE/, `Invalid pin "${pinValue}" should be rejected`);
|
||||
}
|
||||
|
||||
function checkPassValidPin(pinValue, settingPin) {
|
||||
|
@ -46,12 +46,6 @@ function run_test() {
|
||||
libraryFile.append("pkcs11testmodule");
|
||||
libraryFile.append(libraryName);
|
||||
ok(libraryFile.exists(), "The pkcs11testmodule file should exist");
|
||||
let exceptionCaught = false;
|
||||
try {
|
||||
pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0);
|
||||
ok(false, "addModule should have thrown an exception");
|
||||
} catch (e) {
|
||||
exceptionCaught = true;
|
||||
}
|
||||
ok(exceptionCaught, "addModule should have thrown an exception");
|
||||
throws(() => pkcs11.addModule("PKCS11 Test Module", libraryFile.path, 0, 0),
|
||||
/NS_ERROR_FAILURE/, "addModule should throw when in safe mode");
|
||||
}
|
||||
|
@ -44,10 +44,7 @@ function run_test() {
|
||||
// gracefully.
|
||||
uri = Services.io.newURI("https://../foo", null, null);
|
||||
equal(uri.host, "..");
|
||||
try {
|
||||
throws(() => {
|
||||
SSService.isSecureURI(Ci.nsISiteSecurityService.HEADER_HSTS, uri, 0);
|
||||
ok(false); // this shouldn't run
|
||||
} catch (e) {
|
||||
equal(e.result, Cr.NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
}, /NS_ERROR_UNEXPECTED/, "Malformed URI should be rejected");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user