Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/**
* Test LoginHelper.isOriginMatching
*/
"use strict";
add_task(function test_isOriginMatching() {
let testcases = [
// Index 0 holds the expected return value followed by arguments to isOriginMatching.
// The formActionOrigin can be "javascript:"
[true, "javascript:", "javascript:"],
[false, "javascript:", "http://example.com"],
[false, "http://example.com", "javascript:"],
// HTTP Auth. logins have a null formActionOrigin
[true, null, null],
[false, null, "http://example.com"],
[false, "http://example.com", null],
[false, "http://example.com", ""],
[false, "", "http://example.com"],
[
true,
{ schemeUpgrades: true },
],
[
true,
{ schemeUpgrades: true },
],
[
true,
{ schemeUpgrades: true },
],
[
true,
{ schemeUpgrades: true },
],
[
false,
{ schemeUpgrades: true },
], // downgrade
[
false,
{ schemeUpgrades: true },
], // port mismatch
[
false,
{ schemeUpgrades: true },
], // port mismatch
[
false,
{ schemeUpgrades: true },
],
[
true,
{ acceptDifferentSubdomains: true },
],
[
true,
{ acceptDifferentSubdomains: true },
],
[
true,
{ acceptDifferentSubdomains: true },
],
[
true,
{ acceptDifferentSubdomains: true },
],
[
false,
{ acceptDifferentSubdomains: true, schemeUpgrades: true },
],
[
true,
{ acceptDifferentSubdomains: true, schemeUpgrades: true },
],
[
true,
{ acceptDifferentSubdomains: true },
],
[
false,
{ acceptDifferentSubdomains: true },
],
// signon.includeOtherSubdomainsInLookup allows acceptDifferentSubdomains to be false
[
false,
{ acceptDifferentSubdomains: false },
],
[
false,
{ acceptDifferentSubdomains: false },
],
[
false,
{ acceptDifferentSubdomains: false },
],
[
false,
{ acceptDifferentSubdomains: false },
],
// HTTP Auth. logins have a null formActionOrigin
[
false,
null,
{
acceptDifferentSubdomains: false,
acceptWildcardMatch: true,
schemeUpgrades: true,
},
],
];
for (let tc of testcases) {
let expected = tc.shift();
Assert.strictEqual(
LoginHelper.isOriginMatching(...tc),
expected,
"Check " + JSON.stringify(tc)
);
}
});