Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(venmo): allow trusted domains #439

Merged
merged 5 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/child/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ export function normalizeChildProps<P, X>(
for (const key of Object.keys(props)) {
const prop = propsDef[key];

if (
prop &&
prop.sameDomain &&
(origin !== getDomain(window) || !isSameDomain(parentComponentWindow))
) {
const trustedChild: boolean =
prop && prop.trustedDomains && prop.trustedDomains.length > 0
? prop.trustedDomains.indexOf(getDomain(window)) !== -1
mnicpt marked this conversation as resolved.
Show resolved Hide resolved
: origin === getDomain(window) || isSameDomain(parentComponentWindow);

if (prop && prop.sameDomain && !trustedChild) {
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/component/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export type PropDefinitionType<T, P, S: $Values<typeof PROP_TYPE>, X> = {|
validate?: ({| value: T, props: PropsType<P> |}) => void,
sameDomain?: boolean,
serialization?: $Values<typeof PROP_SERIALIZATION>,
trustedDomains?: $ReadOnlyArray<string>,
|};

export type BOOLEAN_DEFINITION_TYPE = typeof PROP_TYPE.BOOLEAN;
Expand Down
11 changes: 6 additions & 5 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,12 @@ export function parentComponent<P, X, C>({
continue;
}

if (
prop &&
prop.sameDomain &&
!matchDomain(initialChildDomain, getDomain(window))
) {
const trustedChild: boolean =
prop && prop.trustedDomains && prop.trustedDomains.length > 0
? prop.trustedDomains.indexOf(initialChildDomain) !== -1
mnicpt marked this conversation as resolved.
Show resolved Hide resolved
: matchDomain(initialChildDomain, getDomain(window));

if (prop && prop.sameDomain && !trustedChild) {
continue;
}

Expand Down
67 changes: 67 additions & 0 deletions test/tests/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,73 @@ describe("zoid props cases", () => {
});
});

it("should pass a trustedDomain prop and have it populate on the child", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a test where the domains don't match

url: "mock://www.child.com/base/test/windows/child/index.htm",
trustedDomains: ["mock://www.different-domain.com"],

return wrapPromise(({ expect }) => {
window.__component__ = () => {
return zoid.create({
tag: "test-trusteddomain-prop-passed",
url: "mock://www.child.com/base/test/windows/child/index.htm",
domain: ["mock://www.child.com"],
props: {
foo: {
type: "string",
trustedDomains: ["mock://www.child.com"],
},
},
});
};

const component = window.__component__();
const instance = component({
foo: "bar",
passProp: expect("passProp", (val) => {
if (!val) {
throw new Error(`Expected val to be passed`);
}
}),
run: () => `
window.xprops.passProp(window.xprops.foo);
`,
});

return instance.render(getBody());
});
});

it("should pass a trustedDomain and sameDomain=true prop and have it populate on the child", () => {
return wrapPromise(({ expect }) => {
window.__component__ = () => {
return zoid.create({
tag: "test-samedomain-trusteddomain-prop-passed",
url: "mock://www.child.com/base/test/windows/child/index.htm",
domain: ["mock://www.child.com"],
props: {
foo: {
type: "string",
sameDomain: true,
trustedDomains: ["mock://www.child.com"],
},
},
});
};

const component = window.__component__();
const instance = component({
foo: "bar",
passProp: expect("passProp", (val) => {
if (!val) {
throw new Error(`Expected val to be passed`);
}
}),
run: () => `
window.xprops.passProp(window.xprops.foo);
`,
});

return instance.render(getBody());
});
});

it("should alias a prop and have it copy correctly", () => {
return wrapPromise(({ expect }) => {
window.__component__ = () => {
Expand Down
Loading