Skip to content

Commit

Permalink
chore: remove document.domain usage for cross-origin testing (#24945)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding authored Dec 2, 2022
1 parent afc5e03 commit a3d3074
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
7 changes: 4 additions & 3 deletions packages/driver/src/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ class $Cypress {
configure (config: Record<string, any> = {}) {
const domainName = config.remote ? config.remote.domainName : undefined

// set domainName but allow us to turn
// off this feature in testing
if (domainName && config.testingType === 'e2e') {
// set domainName but allow us to turn off this feature in testing. not
// needed for cross-origin spec bridge, since it is strictly used
// same-origin
if (domainName && !this.isCrossOriginSpecBridge && config.testingType === 'e2e') {
document.domain = domainName
}

Expand Down
11 changes: 7 additions & 4 deletions packages/network/lib/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,14 @@ export function getOrigin (url: string) {
}

/**
* We use the super domain origin in the driver to determine whether or not we need to reload/interact with the AUT, and
* currently in the spec bridge to interact with the AUT frame, which uses document.domain set to the super domain
* Returns the super-domain of a URL
*
* The primary driver uses the super-domain origin to allow tests to
* navigate between subdomains of the same super-domain by setting
* document.domain to the super-domain
* @param url - the full absolute url
* @returns the super domain origin -
* ex: http://www.example.com:8081/my/path -> http://example.com:8081/my/path
* @returns the super domain origin
* ex: http://www.example.com:8081/my/path -> http://example.com:8081
*/
export function getSuperDomainOrigin (url: string) {
// @ts-ignore
Expand Down
4 changes: 1 addition & 3 deletions packages/proxy/lib/http/util/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ export function full (domain) {
})
}

export async function fullCrossOrigin (domain, options: FullCrossOriginOpts) {
export async function fullCrossOrigin (options: FullCrossOriginOpts) {
const contents = await getRunnerCrossOriginInjectionContents()

return oneLine`
<script type='text/javascript'>
document.domain = '${domain}';
(function (cypressConfig) {
${contents}
}(${JSON.stringify(options)}));
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/util/rewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getHtmlToInject (opts: InjectionOpts & SecurityOpts) {
case 'full':
return inject.full(domainName)
case 'fullCrossOrigin':
return inject.fullCrossOrigin(domainName, {
return inject.fullCrossOrigin({
modifyObstructiveThirdPartyCode,
modifyObstructiveCode,
simulatedCookies,
Expand Down
3 changes: 0 additions & 3 deletions packages/server/lib/html/spec-bridge-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<title>{{title}}</title>
</head>
<body>
<script type="text/javascript">
document.domain = '{{domain}}';
</script>
<script src="/{{namespace}}/runner/cypress_cross_origin_runner.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,7 @@ describe('Routes', () => {
})
})

it('injects document.domain on AUT iframe requests that do not match current superDomain', function () {
it('does not inject document.domain on AUT iframe requests that do not match current superDomain', function () {
nock('http://www.foobar.com')
.get('/')
.reply(200, '<html><head></head><body>hi</body></html>', {
Expand All @@ -2671,7 +2671,7 @@ describe('Routes', () => {

const body = cleanResponseBody(res.body)

expect(body).to.include(`<html><head> <script type='text/javascript'> document.domain = 'foobar.com';`)
expect(body).not.to.include('document.domain =')
})
})

Expand Down

5 comments on commit a3d3074

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a3d3074 Dec 2, 2022

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.0/linux-arm64/release/12.0.0-a3d3074e707ee3daceaf22cdc14fbfba3dd96896/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a3d3074 Dec 2, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.0/linux-x64/release/12.0.0-a3d3074e707ee3daceaf22cdc14fbfba3dd96896/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a3d3074 Dec 2, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.0/darwin-x64/release/12.0.0-a3d3074e707ee3daceaf22cdc14fbfba3dd96896/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a3d3074 Dec 2, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.0/darwin-arm64/release/12.0.0-a3d3074e707ee3daceaf22cdc14fbfba3dd96896/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on a3d3074 Dec 2, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.0.0/win32-x64/release/12.0.0-a3d3074e707ee3daceaf22cdc14fbfba3dd96896/cypress.tgz

Please sign in to comment.