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

Allow wildcard url in domain list #38

Merged
merged 2 commits into from
Aug 31, 2020

Conversation

jogelin
Copy link
Contributor

@jogelin jogelin commented Aug 27, 2020

Hello,

Just a small proposal to be able to use wildcard URL instead of having to specify the entire hostname in the domain list.

One question: what do you think about using a testing framework ? :p

Copy link
Member

@joeldenning joeldenning left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. It's a good feature - I've left a comment on how the implementation could be more complete

One question: what do you think about using a testing framework ? :p

Yeah this project should have some automated tests. Perhaps with cypress.io as the test runner? If you have interest in adding tests, I'd gladly review a PR.

src/api/js-api.js Outdated Show resolved Hide resolved
@jogelin jogelin force-pushed the wildcard-domain-list branch from 5861cd7 to e5c2d73 Compare August 31, 2020 13:12
Copy link
Member

@joeldenning joeldenning left a comment

Choose a reason for hiding this comment

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

Looking good, I think copying over the regex to string implementation is fine.

@@ -27,16 +29,16 @@ if (domainsElement) {
if (!content) {
console.warn(`Invalid ${domainsMeta} meta element - content required.`);
}

const matchHostname = (domain) =>
new RegExp(escapeStringRegexp(domain).replace("*", ".+")).test(domain);
Copy link
Member

Choose a reason for hiding this comment

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

Have you confirmed that this works for a variety of allowlists and domains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bit complicated locally but at least this is the result of manual tests on localhost:5000:

Active When:

  • content="allowlist:localhost"
  • content="denylist:localhost-*,localhost.*,*.localhost,*-localhost,*localhost,local*host,localhost*"

Inactive When:

  • content="denylist:localhost"
  • content="allowlist:localhost-*,localhost.*,*.localhost,*-localhost,*localhost,local*host,localhost*"

Copy link
Member

Choose a reason for hiding this comment

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

👍 seems reasonable. Manipulation of /etc/hosts file could allow for further testing, but it seems like we've covered most of the cases with those tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idd I tried playing with hosts but I don't know why, I couldn't access to the test server with it. I thought about a host parameter to provide to the "serve" ?

Copy link
Member

Choose a reason for hiding this comment

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

This code broke the allowlist and denylist, as reported in https://single-spa.slack.com/archives/C8R6U7MT7/p1605204526245000.

The reason is that window.location.hostname is no longer the domain being tested against.

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, wildcard domains aren't working because the * character is escaped before being replaced with .+

src/api/js-api-util.js Show resolved Hide resolved
@joeldenning joeldenning merged commit 47be99e into single-spa:master Aug 31, 2020
@joeldenning
Copy link
Member

Thanks for your work on this. Released in https://github.com/joeldenning/import-map-overrides/releases/tag/v1.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants