Skip to content

Commit

Permalink
chore: refactor spec bridges to strictly enforce same origin
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed Sep 19, 2022
1 parent cfef44f commit c07c596
Show file tree
Hide file tree
Showing 39 changed files with 460 additions and 450 deletions.
2 changes: 1 addition & 1 deletion packages/driver/cypress/e2e/commands/navigation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ describe('src/cy/commands/navigation', () => {
${experimentalMessage}
\`cy.visit('http://localhost:3500/fixtures/generic.html')\`
\`<commands targeting http://localhost:3500 go here>\`\n
\`cy.origin('http://foobar.com:3500', () => {\`
\`cy.origin('http://www.foobar.com:3500', () => {\`
\` cy.visit('http://www.foobar.com:3500/fixtures/generic.html')\`
\` <commands targeting http://www.foobar.com:3500 go here>\`
\`})\`\n
Expand Down
12 changes: 6 additions & 6 deletions packages/driver/cypress/e2e/e2e/origin/basic_login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Multi-step Auth', () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.url() //fail
cy.origin('http://foobar.com:3500', () => { // Parent origin is localhost
cy.origin('http://www.foobar.com:3500', () => { // Parent origin is localhost
cy.get('[data-cy="approve-orig"]').click() // takes you to idp.com
cy.origin('http://idp.com:3500', () => { // Parent origin is foobar.com
cy.get('[data-cy="username"]').type('MarkyMark')
Expand All @@ -172,7 +172,7 @@ describe('Multi-step Auth', () => {
it.skip('final-auth redirects back to localhost - flat', () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.origin('http://foobar.com:3500', () => { // Parent origin is localhost
cy.origin('http://www.foobar.com:3500', () => { // Parent origin is localhost
cy.get('[data-cy="approve-orig"]').click() // takes you to idp.com
}) // Exits and moves on to the next command

Expand All @@ -189,7 +189,7 @@ describe('Multi-step Auth', () => {

// TODO: cy.origin does not work in cy.origin yet.
it.skip('final auth redirects back to localhost - nested - approval first', () => {
cy.origin('http://foobar.com:3500', () => { // parent origin is localhost
cy.origin('http://www.foobar.com:3500', () => { // parent origin is localhost
cy.visit('http://www.foobar.com:3500/fixtures/auth/approval.html')
cy.get('[data-cy="approve-orig"]').click() // takes you to idp.com
cy.origin('http://idp.com:3500', () => { // parent origin is foobar.com
Expand All @@ -208,7 +208,7 @@ describe('Multi-step Auth', () => {
it.skip('final auth redirects back to approval page - nested', () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.origin('http://foobar.com:3500', () => { // parent origin is localhost
cy.origin('http://www.foobar.com:3500', () => { // parent origin is localhost
cy.get('[data-cy="approve-me"]').click() // takes you to idp.com
cy.origin('http://idp.com:3500', () => { // parent origin is foobar.com
cy.get('[data-cy="username"]').type('MarkyMark')
Expand All @@ -227,7 +227,7 @@ describe('Multi-step Auth', () => {
it('final auth redirects back to approval page - flat', () => {
cy.visit('/fixtures/auth/index.html')
cy.get('[data-cy="login-with-approval"]').click() // takes you to foobar.com.../approval
cy.origin('http://foobar.com:3500', () => { // parent origin is localhost
cy.origin('http://www.foobar.com:3500', () => { // parent origin is localhost
cy.get('[data-cy="approve-me"]').click() // takes you to idp.com
}) // waits on localhost forever, this breaks

Expand All @@ -236,7 +236,7 @@ describe('Multi-step Auth', () => {
cy.get('[data-cy="login"]').click() // Takes you back to foobar.com.../approval
}) // Exits and moves on to the next command

cy.origin('http://foobar.com:3500', () => { // parent origin is localhost
cy.origin('http://www.foobar.com:3500', () => { // parent origin is localhost
cy.get('[data-cy="login-success"]').click() // Takes you back to localhost
}) // Exits and moves on to the next command

Expand Down
66 changes: 33 additions & 33 deletions packages/driver/cypress/e2e/e2e/origin/commands/actions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ context('cy.origin actions', () => {
it('.type()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#input').type('foo')
.should('have.value', 'foo')
})
Expand All @@ -17,7 +17,7 @@ context('cy.origin actions', () => {
it('.focus()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#input').focus()
.should('be.focused')
})
Expand All @@ -26,7 +26,7 @@ context('cy.origin actions', () => {
it('.blur()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#input').type('foo').blur()
.should('not.be.focused')
})
Expand All @@ -35,7 +35,7 @@ context('cy.origin actions', () => {
it('.clear()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#input')
.type('foo').should('have.value', 'foo')
.clear().should('have.value', '')
Expand All @@ -45,7 +45,7 @@ context('cy.origin actions', () => {
it('.submit()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
const afterFormSubmitted = new Promise<void>((resolve) => {
cy.once('form:submitted', resolve)
})
Expand All @@ -58,7 +58,7 @@ context('cy.origin actions', () => {
it('.click()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const onClick = new Promise<void>((resolve) => {
$btn.on('click', () => resolve())
Expand All @@ -73,7 +73,7 @@ context('cy.origin actions', () => {
it('.dblclick()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const afterDblClick = new Promise<void>((resolve) => {
$btn.on('dblclick', () => resolve())
Expand All @@ -88,7 +88,7 @@ context('cy.origin actions', () => {
it('.rightclick()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const afterContextmenu = new Promise<void>((resolve) => {
$btn.on('contextmenu', () => resolve())
Expand All @@ -103,7 +103,7 @@ context('cy.origin actions', () => {
it('.check()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().should('be.checked')
})
Expand All @@ -112,7 +112,7 @@ context('cy.origin actions', () => {
it('.uncheck()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().should('be.checked')
.uncheck().should('not.be.checked')
Expand All @@ -122,7 +122,7 @@ context('cy.origin actions', () => {
it('.select()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('select[name="foods"]')
.select('Japanese').should('have.value', 'Japanese')
})
Expand All @@ -131,7 +131,7 @@ context('cy.origin actions', () => {
it('.scrollIntoView()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#scroll-into-view-vertical h5')
.should('not.be.visible')
.scrollIntoView().should('be.visible')
Expand All @@ -141,7 +141,7 @@ context('cy.origin actions', () => {
it('.scrollTo()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#scroll-into-view-vertical h5').should('not.be.visible')
cy.get('#scroll-into-view-vertical').scrollTo(0, 300)
cy.get('#scroll-into-view-vertical h5').should('be.visible')
Expand All @@ -151,7 +151,7 @@ context('cy.origin actions', () => {
it('.trigger()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').then(($btn) => {
const afterClick = new Promise<void>((resolve) => {
$btn.on('click', () => resolve())
Expand All @@ -166,7 +166,7 @@ context('cy.origin actions', () => {
it('.selectFile()', () => {
cy.get('a[data-cy="files-form-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.wrap(Cypress.Buffer.from('foo')).as('foo')

cy.get('#basic')
Expand All @@ -193,7 +193,7 @@ context('cy.origin actions', () => {
it('.get()', { defaultCommandTimeout: 50 }, (done) => {
cy.on('fail', (err) => {
expect(err.message).to.include(`Timed out retrying after 50ms:`)
expect(err.message).to.include(`The command was expected to run against origin \`http://localhost:3500\` but the application is at origin \`http://foobar.com:3500\`.`)
expect(err.message).to.include(`The command was expected to run against origin \`http://localhost:3500\` but the application is at origin \`http://www.foobar.com:3500\`.`)
expect(err.message).to.include(`This commonly happens when you have either not navigated to the expected origin or have navigated away unexpectedly.`)
// make sure that the secondary origin failures do NOT show up as spec failures or AUT failures
expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`)
Expand All @@ -220,7 +220,7 @@ context('cy.origin actions', () => {

it('.get()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button')
})

Expand All @@ -242,7 +242,7 @@ context('cy.origin actions', () => {

it('.alias()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').as('buttonAlias')
})

Expand All @@ -266,7 +266,7 @@ context('cy.origin actions', () => {

it('.click()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button-inside-a').click()
})

Expand Down Expand Up @@ -319,7 +319,7 @@ context('cy.origin actions', () => {

it('.dblclick()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').dblclick()
})

Expand Down Expand Up @@ -367,7 +367,7 @@ context('cy.origin actions', () => {

it('.rightclick()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').rightclick()
})

Expand Down Expand Up @@ -415,7 +415,7 @@ context('cy.origin actions', () => {

it('.type()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('input#input').type('foo')
})

Expand Down Expand Up @@ -487,7 +487,7 @@ context('cy.origin actions', () => {
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23480
it.skip('.submit()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('form#multiple-inputs-and-input-submit input[name="fname"]').type('foo')
cy.get('form#multiple-inputs-and-input-submit input[name="lname"]').type('bar')
cy.get('form#multiple-inputs-and-input-submit').submit()
Expand Down Expand Up @@ -522,7 +522,7 @@ context('cy.origin actions', () => {

it('.focus()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#input').focus()
})

Expand All @@ -545,7 +545,7 @@ context('cy.origin actions', () => {

it('.blur()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
// FIXME: snapshot shows the primary domain (before type). Should be secondary
cy.get('#input').type('foo').blur()
})
Expand All @@ -569,7 +569,7 @@ context('cy.origin actions', () => {

it('.clear()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
// FIXME: snapshot shows the primary domain. Should be secondary
cy.get('#input').type('foo').clear()
})
Expand All @@ -595,7 +595,7 @@ context('cy.origin actions', () => {

it('.check()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]').check()
})

Expand Down Expand Up @@ -639,7 +639,7 @@ context('cy.origin actions', () => {

it('.uncheck()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]')
.check().uncheck()
})
Expand Down Expand Up @@ -684,7 +684,7 @@ context('cy.origin actions', () => {

it('.select()', () => {
cy.get('a[data-cy="dom-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
// TODO: wrong selected value is displayed in the snapshot after
cy.get('select[name="foods"]').select('Japanese')
})
Expand Down Expand Up @@ -730,7 +730,7 @@ context('cy.origin actions', () => {

it('.scrollIntoView()', () => {
cy.get('a[data-cy="scrolling-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
// FIXME: snapshot of primary is showing for scrollIntoView
cy.get('#scroll-into-view-vertical h5')
.should('not.be.visible')
Expand Down Expand Up @@ -758,7 +758,7 @@ context('cy.origin actions', () => {
it('.scrollTo()', () => {
cy.get('a[data-cy="scrolling-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#scroll-into-view-vertical h5').should('not.be.visible')
cy.get('#scroll-into-view-vertical').scrollTo(0, 300)
})
Expand All @@ -778,7 +778,7 @@ context('cy.origin actions', () => {
it('.trigger()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').trigger('click')
})

Expand All @@ -803,7 +803,7 @@ context('cy.origin actions', () => {
it('.selectFile()', () => {
cy.get('a[data-cy="files-form-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#basic').selectFile({ contents: Cypress.Buffer.from('foo'), fileName: 'foo.txt' })
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ context('cy.origin aliasing', () => {
it('supports dom elements inside origin', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get(':checkbox[name="colors"][value="blue"]').as('checkbox')
cy.get('@checkbox').click().should('be.checked')
})
Expand All @@ -23,7 +23,7 @@ context('cy.origin aliasing', () => {

cy.get('[data-cy="cross-origin-secondary-link"]').as('link')

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('@link').click()
})
})
Expand All @@ -43,7 +43,7 @@ context('cy.origin aliasing', () => {
it('.as()', () => {
cy.get('a[data-cy="dom-link"]').click()

cy.origin('http://foobar.com:3500', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.get('#button').as('buttonAlias')
})

Expand Down
Loading

0 comments on commit c07c596

Please sign in to comment.