Skip to content

Commit

Permalink
fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Dec 13, 2021
1 parent 4d5822d commit 16001aa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/extension/app/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const connect = function (host, path, extraOpts) {
],
}
}, { urls: ['<all_urls>'] }, ['blocking', 'requestHeaders'])

return ws.emit('automation:client:connected')
})

const fail = (id, err) => {
Expand Down Expand Up @@ -119,6 +117,8 @@ const connect = function (host, path, extraOpts) {
listenToCookieChanges()
listenToDownloads()
listenToOnBeforeHeaders()

ws.emit('automation:client:connected')
})

return ws
Expand Down
5 changes: 3 additions & 2 deletions packages/proxy/lib/http/response-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,15 @@ const SetInjectionLevel: ResponseMiddleware = function () {
}

const isHTML = resContentTypeIs(this.incomingRes, 'text/html')
const isTheAUTFrame = isAUTFrame(this.req)

if (!isReqMatchOriginPolicy && isAUTFrame(this.req) && (isHTML || isRenderedHTML)) {
if (!isReqMatchOriginPolicy && isTheAUTFrame && (isHTML || isRenderedHTML)) {
this.debug('- multidomain injection')

return 'fullMultidomain'
}

if (!isHTML) {
if (!isHTML || !isReqMatchOriginPolicy && !isTheAUTFrame) {
debug('- no injection (not html)')

return false
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export abstract class ServerBase<TSocket extends SocketE2E | SocketCt> {
this._baseUrl = null
this._fileServer = null

this._eventBus.on('delaying:cross:domain:html', (url) => {
this._eventBus.on('delaying:cross:domain:html', () => {
this.socket.localBus.once('ready:for:domain', () => {
this._eventBus.emit('ready:for:domain')
})
Expand Down
3 changes: 3 additions & 0 deletions packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,9 @@ describe('lib/cypress', () => {
setUserAgent: sinon.stub(),
on: sinon.stub(),
removeListener: sinon.stub(),
webRequest: {
onBeforeSendHeaders () {},
},
},
}

Expand Down
30 changes: 29 additions & 1 deletion packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,34 @@ describe('Routes', () => {
})
})

it('injects 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>', {
'Content-Type': 'text/html',
})

this.server._eventBus.on('delaying:cross:domain:html', () => {
this.server._eventBus.emit('ready:for:domain')
})

return this.rp({
url: 'http://www.foobar.com',
headers: {
'Cookie': '__cypress.initial=false',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'X-Cypress-Is-AUT-Frame': 'true',
},
})
.then((res) => {
expect(res.statusCode).to.eq(200)

const body = cleanResponseBody(res.body)

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

it('does not inject document.domain on non http requests', function () {
nock(this.server._remoteOrigin)
.get('/json')
Expand All @@ -3035,7 +3063,7 @@ describe('Routes', () => {
})
})

it('does not inject document.domain on http requests which do not match current superDomain', function () {
it('does not inject document.domain on http requests which do not match current superDomain and are not the AUT iframe', function () {
nock('http://www.foobar.com')
.get('/')
.reply(200, '<html><head></head><body>hi</body></html>', {
Expand Down
5 changes: 5 additions & 0 deletions packages/server/test/unit/socket_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ describe('lib/socket', () => {
query () {},
executeScript () {},
},
webRequest: {
onBeforeSendHeaders: {
addListener () {},
},
},
}

extensionBackgroundPage = require('@packages/extension/app/background')
Expand Down

0 comments on commit 16001aa

Please sign in to comment.