Skip to content

Commit

Permalink
fix: Fix issue with using privileged commands when baseUrl includes b…
Browse files Browse the repository at this point in the history
…asic auth credentials (#28428)
  • Loading branch information
chrisbreiding authored Nov 30, 2023
1 parent 57bb0b6 commit 257861b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ _Released 12/5/2023 (PENDING)_

- 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).
- Fixed an issue where request logging would default the `message` to the `args` of the currently running command even though those `args` would not apply to the request log and are not displayed. If the `args` are sufficiently large (e.g. when running the `cy.task` from the [code-coverage](https://github.com/cypress-io/code-coverage/) plugin) there could be performance/memory implications. Addressed in [#28411](https://github.com/cypress-io/cypress/pull/28411).
- Fixed issue where some URLs would timeout in pre-request correlation. Addressed in [#28427](https://github.com/cypress-io/cypress/pull/28427).
- Fixed an issue where commands would fail with the error `must only be invoked from the spec file or support file` if the project's `baseUrl` included basic auth credentials. Fixes [#28336](https://github.com/cypress-io/cypress/issues/28336).
- Fixed an issue where some URLs would timeout in pre-request correlation. Addressed in [#28427](https://github.com/cypress-io/cypress/pull/28427).

**Misc:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@
// send it to the server, where it's stored in state. when the command is
// run and it sends its message to the server via websocket, we check
// that verified status before allowing the command to continue running
const promise = fetch(`/${namespace}/add-verified-command`, {
//
// needs to use the fully-qualified url or else when the baseUrl includes
// basic auth, the fetch fails with a security error
// see https://github.com/cypress-io/cypress/issues/28336
const promise = fetch(`${win.location.origin}/${namespace}/add-verified-command`, {
body: stringify({
args,
name: command.name,
Expand Down
3 changes: 3 additions & 0 deletions packages/server/test/unit/browsers/privileged-channel_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ describe('privileged channel', () => {
Function: { prototype: {
toString: Function.prototype.toString,
} },
location: {
origin: 'http://localhost:1234',
},
Math: {
imul: Math.imul,
},
Expand Down
13 changes: 13 additions & 0 deletions system-tests/projects/privileged-commands/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
e2e: {
baseUrl: 'http://user:pass@localhost:9999/app',
supportFile: false,
setupNodeEvents (on) {
on('task', {
'return:arg' (arg) {
return arg
},
})
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
it('can run privileged commands with basic auth baseUrl', () => {
cy.visit('/html')
cy.exec('echo "hello"')
cy.readFile('cypress/fixtures/example.json')
cy.writeFile('cypress/_test-output/written.txt', 'contents')
cy.task('return:arg', 'arg')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
15 changes: 15 additions & 0 deletions system-tests/test/base_url_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ describe('e2e baseUrl', () => {
})
})

// https://github.com/cypress-io/cypress/issues/28336
context('basic auth + privileged commands', () => {
systemTests.setup({
servers: {
port: 9999,
onServer,
},
})

systemTests.it('passes', {
browser: 'chrome',
project: 'privileged-commands',
})
})

context('http', () => {
systemTests.setup({
servers: {
Expand Down

5 comments on commit 257861b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 257861b Nov 30, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.1/linux-arm64/develop-257861bd6e3f7de77a4c7ede64e9538370c0a2ed/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 257861b Nov 30, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.1/linux-x64/develop-257861bd6e3f7de77a4c7ede64e9538370c0a2ed/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 257861b Nov 30, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.1/darwin-x64/develop-257861bd6e3f7de77a4c7ede64e9538370c0a2ed/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 257861b Nov 30, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.1/darwin-arm64/develop-257861bd6e3f7de77a4c7ede64e9538370c0a2ed/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 257861b Nov 30, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.1/win32-x64/develop-257861bd6e3f7de77a4c7ede64e9538370c0a2ed/cypress.tgz

Please sign in to comment.