Skip to content

Commit d3fef7e

Browse files
committed
test: harden unit test on url matching
1 parent 730e046 commit d3fef7e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

test-app/app/src/main/assets/app/tests/testRemoteModuleSecurity.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,25 @@ describe("Remote Module Security", function() {
9797
var hasEsmSh = false;
9898
var hasCdn = false;
9999
for (var i = 0; i < allowlist.length; i++) {
100-
if (allowlist[i].indexOf("esm.sh") !== -1) hasEsmSh = true;
101-
if (allowlist[i].indexOf("cdn.example.com") !== -1) hasCdn = true;
100+
var entry = allowlist[i];
101+
try {
102+
// Prefer checking the hostname of a parsed URL entry
103+
var parsed = new URL(entry);
104+
if (parsed.hostname === "esm.sh") {
105+
hasEsmSh = true;
106+
}
107+
if (parsed.hostname === "cdn.example.com") {
108+
hasCdn = true;
109+
}
110+
} catch (e) {
111+
// Fallback: support non-URL entries that may be bare hostnames
112+
if (entry === "esm.sh") {
113+
hasEsmSh = true;
114+
}
115+
if (entry === "cdn.example.com") {
116+
hasCdn = true;
117+
}
118+
}
102119
}
103120
expect(hasEsmSh).toBe(true);
104121
expect(hasCdn).toBe(true);

0 commit comments

Comments
 (0)