-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set up tests for validating various domains (#4960)
- Loading branch information
1 parent
dd05206
commit c43d02f
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
clients/privacy-center/cypress/e2e/consent-banner-cookies.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { CONSENT_COOKIE_NAME } from "fides-js"; | ||
import { stubConfig } from "~/cypress/support/stubs"; | ||
|
||
const domains: { | ||
domain: string; | ||
expected: string; | ||
}[] = require("../fixtures/domains.json"); | ||
|
||
/** | ||
* This test is for validating our cookie domain logic. We want to ensure that cookies are able to be set on the topmost domain without needing to be the full domain. | ||
* | ||
* NOTE: the reason we aren't testing for things like `example` or `example.whatever` is because the browser will *always* set the cookie on *anything* you set for those as long as the page can be visited. This is why `localhost` works for example, or `example.localhost`. | ||
* | ||
* For example, if we are on `subdomain.example.co.uk`, we want to be able to set cookies on `example.co.uk` (but not `co.uk`). | ||
* | ||
* In order to run this test, you will need to have all of the domains in the `domains.json` set up in your `/etc/hosts` file, for example: | ||
* 127.0.0.1 example.co.cr | ||
* 127.0.0.1 subdomain.example.co.cr | ||
* 127.0.0.1 xyz.subdomain.example.co.cr | ||
* ...and so forth (unfortunately, wildcard domains are not supported in `/etc/hosts`), as well as one for `example.co.invalid` to test invalid domains. | ||
* | ||
* This test will fail if you do not have the domains set up in your `/etc/hosts` file! | ||
* | ||
* Once you have the domains set up, you can remove the `.skip` below and run the test. | ||
*/ | ||
|
||
describe.skip("Consent overlay", () => { | ||
describe("when visiting valid domains", () => { | ||
Cypress.on("uncaught:exception", () => false); | ||
domains.forEach(({ domain, expected }) => { | ||
it(`allows cookie for ${domain}`, () => { | ||
Cypress.config("baseUrl", `http://${domain}:3001`); | ||
cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); | ||
stubConfig({ | ||
options: { | ||
isOverlayEnabled: true, | ||
}, | ||
}); | ||
cy.get("div#fides-banner").within(() => { | ||
cy.get("button").contains("Opt in to all").click(); | ||
}); | ||
cy.getCookie(CONSENT_COOKIE_NAME) | ||
.should("exist") | ||
.then((cookie) => { | ||
// check domain of cookie | ||
expect(cookie?.domain).to.eq(expected); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe("when visiting invalid domains", () => { | ||
it(`doesn't allow cookie for example.co.invalid`, () => { | ||
Cypress.config("baseUrl", `http://example.co.invalid:3001`); | ||
cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); | ||
stubConfig({ | ||
options: { | ||
isOverlayEnabled: true, | ||
}, | ||
}); | ||
cy.get("div#fides-banner").within(() => { | ||
cy.get("button").contains("Opt in to all").click(); | ||
}); | ||
cy.getCookie(CONSENT_COOKIE_NAME) | ||
.should("exist") | ||
.then((cookie) => { | ||
// browser allows this because it assumes it's a localhost domain, which is correct, but the test passes because it's not set to the correct domain `example.co.invalid` | ||
expect(cookie?.domain).to.eq(".co.invalid"); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[ | ||
{ "domain": "example.co.cr", "expected": ".example.co.cr" }, | ||
{ "domain": "example.co.nz", "expected": ".example.co.nz" }, | ||
{ "domain": "example.co.uk", "expected": ".example.co.uk" }, | ||
{ "domain": "example.co.za", "expected": ".example.co.za" }, | ||
{ "domain": "example.com.au", "expected": ".example.com.au" }, | ||
{ "domain": "example.com.br", "expected": ".example.com.br" }, | ||
{ "domain": "example.com.my", "expected": ".example.com.my" }, | ||
{ "domain": "subdomain.example.co.cr", "expected": ".example.co.cr" }, | ||
{ "domain": "subdomain.example.co.nz", "expected": ".example.co.nz" }, | ||
{ "domain": "subdomain.example.co.uk", "expected": ".example.co.uk" }, | ||
{ "domain": "subdomain.example.co.za", "expected": ".example.co.za" }, | ||
{ "domain": "subdomain.example.com.au", "expected": ".example.com.au" }, | ||
{ "domain": "subdomain.example.com.br", "expected": ".example.com.br" }, | ||
{ "domain": "subdomain.example.com.my", "expected": ".example.com.my" }, | ||
{ "domain": "xyz.subdomain.example.co.cr", "expected": ".example.co.cr" }, | ||
{ "domain": "xyz.subdomain.example.co.nz", "expected": ".example.co.nz" }, | ||
{ "domain": "xyz.subdomain.example.co.uk", "expected": ".example.co.uk" }, | ||
{ "domain": "xyz.subdomain.example.co.za", "expected": ".example.co.za" }, | ||
{ "domain": "xyz.subdomain.example.com.au", "expected": ".example.com.au" }, | ||
{ "domain": "xyz.subdomain.example.com.br", "expected": ".example.com.br" }, | ||
{ "domain": "xyz.subdomain.example.com.my", "expected": ".example.com.my" } | ||
] |