Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/use-cypress-design-button-in-lau…
Browse files Browse the repository at this point in the history
…nchpad
  • Loading branch information
Barthélémy Ledoux authored Nov 28, 2023
2 parents 6c92d2d + 650d5cb commit 6fef034
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 17 deletions.
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 13.6.1

_Released 12/5/2023 (PENDING)_

**Bugfixes:**

- Fixed an issue where pages or downloads opened in a new tab were missing basic auth headers. Fixes [#28350](https://github.com/cypress-io/cypress/issues/28350).

## 13.6.0

_Released 11/21/2023_
Expand Down
6 changes: 0 additions & 6 deletions npm/puppeteer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
# @cypress/puppeteer-v1.0.0 (2023-11-22)


### Features

* Add @cypress/puppeteer plugin ([#28370](https://github.com/cypress-io/cypress/issues/28370)) ([b34d145](https://github.com/cypress-io/cypress/commit/b34d14571689a9b36efc707a3a48f27edcb98113))
4 changes: 3 additions & 1 deletion npm/puppeteer/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# @cypress/puppeteer
# @cypress/puppeteer [beta]

Utilize [Puppeteer's browser API](https://pptr.dev/api) within Cypress with a single command.

> This plugin is in public beta, so we'd love to get your feedback to improve it. Please leave any feedback you have in [this discussion](https://github.com/cypress-io/cypress/discussions/28410).
# Table of Contents

- [Installation](#installation)
Expand Down
13 changes: 12 additions & 1 deletion npm/puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@
"dist",
"index.d.ts"
],
"types": "index.d.ts"
"types": "index.d.ts",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/cypress-io/cypress.git"
},
"homepage": "https://github.com/cypress-io/cypress/blob/develop/npm/puppeteer/#readme",
"author": "Cypress App Team",
"bugs": "https://github.com/cypress-io/cypress/issues/new?assignees=&labels=npm%3A%20%40cypress%2Fpuppeteer&template=1-bug-report.md&title=",
"publishConfig": {
"access": "public"
}
}
20 changes: 20 additions & 0 deletions packages/driver/cypress/e2e/cypress/downloads.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import $Downloads from '../../../src/cypress/downloads'
import { authCreds } from '../../fixtures/auth_creds'

describe('src/cypress/downloads', () => {
let log
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('download behavior', () => {
.should('contain', '"Joe","Smith"')
})

// NOTE: webkit opens a new window and doesn't download the file
it('downloads from anchor tag without download attribute', { browser: '!webkit' }, () => {
cy.exec(`rm -f ${Cypress.config('downloadsFolder')}/downloads_records.csv`)
cy.readFile(`${Cypress.config('downloadsFolder')}/downloads_records.csv`).should('not.exist')
Expand All @@ -110,3 +112,21 @@ describe('download behavior', () => {
cy.readFile(`${Cypress.config('downloadsFolder')}/downloads_does_not_exist.csv`).should('not.exist')
})
})

describe('basic auth download behavior', () => {
beforeEach(() => {
cy.visit('/fixtures/downloads.html', {
auth: authCreds,
})
})

// NOTE: webkit opens a new window and doesn't download the file
it('downloads basic auth protected file that opens in a new tab', { browser: '!webkit' }, () => {
cy.exec(`rm -f ${Cypress.config('downloadsFolder')}/download-basic-auth.csv`)
cy.readFile(`${Cypress.config('downloadsFolder')}/download-basic-auth.csv`).should('not.exist')

cy.get('[data-cy=download-basic-auth]').click()
cy.readFile(`${Cypress.config('downloadsFolder')}/download-basic-auth.csv`)
.should('contain', '"Joe","Smith"')
})
})
10 changes: 3 additions & 7 deletions packages/driver/cypress/e2e/e2e/origin/commands/navigation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { authCreds } from '../../../../fixtures/auth_creds'
import { findCrossOriginLogs } from '../../../../support/utils'

context('cy.origin navigation', { browser: '!webkit' }, () => {
Expand Down Expand Up @@ -309,13 +310,8 @@ context('cy.origin navigation', { browser: '!webkit' }, () => {
})

it('supports auth options and adding auth to subsequent requests', () => {
cy.origin('http://www.foobar.com:3500', () => {
cy.visit('http://www.foobar.com:3500/basic_auth', {
auth: {
username: 'cypress',
password: 'password123',
},
})
cy.origin('http://www.foobar.com:3500', { args: authCreds }, (auth) => {
cy.visit('http://www.foobar.com:3500/basic_auth', { auth })

cy.get('body').should('have.text', 'basic auth worked')

Expand Down
4 changes: 4 additions & 0 deletions packages/driver/cypress/fixtures/auth_creds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const authCreds = {
username: 'cypress',
password: 'password123',
}
3 changes: 3 additions & 0 deletions packages/driver/cypress/fixtures/downloads.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ <h3>Download CSV</h3>
<h3>Download CSV</h3>
<a data-cy="download-without-download-attr" href="downloads_records.csv">download csv from anchor tag without download attr</a>

<h3>Download Basic Auth CSV</h3>
<a data-cy="download-basic-auth" href="/download-basic-auth.csv" target="_blank">download csv that's basic auth protected</a>

<h3>Download CSV</h3>
<a data-cy="invalid-download" href="downloads_does_not_exist.csv" download>broken download link</a>
</body>
Expand Down
16 changes: 15 additions & 1 deletion packages/driver/cypress/plugins/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Promise = require('bluebird')
const multer = require('multer')
const upload = multer({ dest: 'cypress/_test-output/' })
const { cors } = require('@packages/network')
const { authCreds } = require('../fixtures/auth_creds')

const PATH_TO_SERVER_PKG = path.dirname(require.resolve('@packages/server'))

Expand Down Expand Up @@ -128,7 +129,7 @@ const createApp = (port) => {
app.get('/basic_auth', (req, res) => {
const user = auth(req)

if (user && ((user.name === 'cypress') && (user.pass === 'password123'))) {
if (user?.name === authCreds.username && user?.pass === authCreds.password) {
return res.send('<html><body>basic auth worked</body></html>')
}

Expand Down Expand Up @@ -342,6 +343,19 @@ const createApp = (port) => {
res.send(_var)
})

app.get('/download-basic-auth.csv', (req, res) => {
const user = auth(req)

if (user?.name === authCreds.username && user?.pass === authCreds.password) {
return res.sendFile(path.join(__dirname, '..', 'fixtures', 'downloads_records.csv'))
}

return res
.set('WWW-Authenticate', 'Basic')
.type('html')
.sendStatus(401)
})

app.post('/upload', (req, res) => {
res.sendStatus(200)
})
Expand Down
1 change: 1 addition & 0 deletions packages/proxy/lib/http/request-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ExtractCypressMetadataHeaders: RequestMiddleware = function () {
delete this.req.headers['x-cypress-is-from-extra-target']

this.onlyRunMiddleware([
'MaybeSetBasicAuthHeaders',
'SendRequestOutgoing',
])
}
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/test/unit/http/request-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('http/request-middleware', () => {

expect(ctx.req.headers!['x-cypress-is-from-extra-target']).not.to.exist
expect(ctx.req.isFromExtraTarget).to.be.true
expect(ctx.onlyRunMiddleware).to.be.calledWith(['SendRequestOutgoing'])
expect(ctx.onlyRunMiddleware).to.be.calledWith(['MaybeSetBasicAuthHeaders', 'SendRequestOutgoing'])
})

it('when it does not exist, removes header and sets in on the req', async () => {
Expand Down

0 comments on commit 6fef034

Please sign in to comment.