add test for base url canonicalization and fix canonicalization bug
This commit is contained in:
parent
3d79aba854
commit
4df35bdcd9
21
src/helpers-test.ts
Normal file
21
src/helpers-test.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import {test, TestLib} from "testlib/talertest";
|
||||
import * as helpers from "./helpers";
|
||||
|
||||
|
||||
test("URL canonicalization", (t: TestLib) => {
|
||||
// converts to relative, adds https
|
||||
t.assertEqualsStrict(
|
||||
"https://alice.example.com/exchange/",
|
||||
helpers.canonicalizeBaseUrl("alice.example.com/exchange"))
|
||||
|
||||
// keeps http, adds trailing slash
|
||||
t.assertEqualsStrict(
|
||||
"http://alice.example.com/exchange/",
|
||||
helpers.canonicalizeBaseUrl("http://alice.example.com/exchange"))
|
||||
|
||||
// keeps http, adds trailing slash
|
||||
t.assertEqualsStrict(
|
||||
"http://alice.example.com/exchange/",
|
||||
helpers.canonicalizeBaseUrl("http://alice.example.com/exchange#foobar"))
|
||||
t.pass();
|
||||
});
|
@ -50,7 +50,7 @@ export function canonicalizeBaseUrl(url: string) {
|
||||
x.protocol("https");
|
||||
}
|
||||
x.path(x.path() + "/").normalizePath();
|
||||
x.fragment();
|
||||
x.fragment("");
|
||||
x.query();
|
||||
return x.href()
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
<script src="/testlib/selenium/escodegen.browser.js"></script>
|
||||
<script src="/testlib/selenium/instrumenter.js"></script>
|
||||
|
||||
<script src="/src/vendor/URI.js"></script>
|
||||
|
||||
<!-- for instrumentation to work, we have to use the non-csp version -->
|
||||
<script src="/testlib/selenium/system.js"></script>
|
||||
|
||||
|
@ -30,6 +30,7 @@ export interface TestLib {
|
||||
pass(msg?: string): void;
|
||||
fail(msg?: string): void;
|
||||
assert(v: any, msg?: string): void;
|
||||
assertEqualsStrict(v1: any, v2: any, msg?: string): void;
|
||||
}
|
||||
|
||||
let tests: Test[] = [];
|
||||
@ -75,8 +76,17 @@ export async function run(statusCallback?: (m: string) => void) {
|
||||
throw Error("test failed");
|
||||
}
|
||||
};
|
||||
let assertEqualsStrict = (v1: any, v2: any, msg?: string) => {
|
||||
if (v1 !== v2) {
|
||||
console.log(`# expected: ${v1}`);
|
||||
console.log(`# actual: ${v2}`);
|
||||
lastMsg = msg;
|
||||
reject();
|
||||
throw Error("test failed");
|
||||
}
|
||||
};
|
||||
// Test might return a promise. If so, wait for it.
|
||||
let r = t.testFn({pass,fail, assert});
|
||||
let r = t.testFn({pass,fail, assert, assertEqualsStrict});
|
||||
r.then(() => resolve(), (e) => reject(e));
|
||||
});
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
"src/emscriptif-test.ts",
|
||||
"src/cryptoApi.ts",
|
||||
"decl/react-global.d.ts",
|
||||
"src/types-test.ts",
|
||||
"src/helpers-test.ts",
|
||||
"src/cryptoLib.ts",
|
||||
"src/types-test.ts",
|
||||
"decl/chrome/chrome.d.ts",
|
||||
"src/cryptoWorker.ts",
|
||||
"src/db.ts",
|
||||
|
Loading…
Reference in New Issue
Block a user