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
  • Loading branch information
chrisbreiding committed Nov 29, 2023
1 parent d5678c7 commit 075d7df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
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(`${window.location.origin}/${namespace}/add-verified-command`, {
body: stringify({
args,
name: command.name,
Expand Down
Empty file.
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": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
14 changes: 14 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,20 @@ 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', {
project: 'privileged-commands',
})
})

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

0 comments on commit 075d7df

Please sign in to comment.