Skip to content

Commit

Permalink
chore(test): negative test case for trustedDomains
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Mask committed Jun 12, 2023
1 parent 0af4698 commit c226a35
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/child/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ export function normalizeChildProps<P, X>(
? prop.trustedDomains.includes(getDomain(window))
: origin === getDomain(window) || isSameDomain(parentComponentWindow);

// let trustedDomains override sameDomain prop
if (prop && prop.sameDomain && !trustedChild) {
continue;
}

// sameDomain was not set and trusted domains must match
if (prop && prop.trustedDomains && !trustedChild) {
continue;
}

// $FlowFixMe
const value = normalizeChildProp(propsDef, props, key, props[key], helpers);

Expand Down
6 changes: 6 additions & 0 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,16 @@ export function parentComponent<P, X, C>({
? prop.trustedDomains.includes(initialChildDomain)
: matchDomain(initialChildDomain, getDomain(window));

// let trustedDomains override sameDomain prop
if (prop && prop.sameDomain && !trustedChild) {
continue;
}

// sameDomain was not set and trusted domains must match
if (prop && prop.trustedDomains && !trustedChild) {
continue;
}

result[key] = props[key];
}

Expand Down
4 changes: 2 additions & 2 deletions test/tests/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("parent domain check", () => {
return component().render(getBody());
});

it("allowedParentDomains is specified as a regex and parent domian match", () => {
it("allowedParentDomains is specified as a regex and parent domain match", () => {
window.__component__ = () => {
return zoid.create({
tag: "test-parent-domain-regex",
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("parent domain check", () => {
});
});

it("xprops.getParentDomain should pass the correct domain", () => {
it("xprops.getParent should pass the correct domain", () => {
return wrapPromise(({ expect }) => {
window.__component__ = () => {
return zoid.create({
Expand Down
4 changes: 1 addition & 3 deletions test/tests/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ describe("zoid props cases", () => {
props: {
foo: {
type: "string",
trustedDomains: ["mock://venmo.com"],
trustedDomains: ["mock://www.child.com"],
},
},
});
Expand All @@ -817,7 +817,6 @@ describe("zoid props cases", () => {
}
}),
run: () => `
window.location = "mock://venmo.com";
window.xprops.passProp(window.xprops.foo);
`,
});
Expand Down Expand Up @@ -850,7 +849,6 @@ describe("zoid props cases", () => {
}
}),
run: () => `
window.location = "mock://venmo.com";
window.xprops.passProp(window.xprops.foo);
`,
});
Expand Down

0 comments on commit c226a35

Please sign in to comment.