Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [protocol] throw error verifying sig #29603

Merged
merged 10 commits into from
Jun 11, 2024
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.11.1

jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
_Released 6/20/2024 (PENDING)_

**Bugfixes:**

- When capture protocol script fails verification, an appropriate error is displayed. Previously, an error regarding Test Replay archive location was shown. Addressed in [#29603](https://github.com/cypress-io/cypress/pull/29603).

## 13.11.0

_Released 6/4/2024_
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/cloud/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export default {
if (!verified) {
debugProtocol(`Unable to verify protocol signature %s`, url)

return null
throw new Error('Unable to verify protocol signature')
}

debugProtocol(`Loaded protocol via url %s`, url)
Expand Down
90 changes: 90 additions & 0 deletions system-tests/__snapshots__/record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4331,3 +4331,93 @@ This error will not affect or change the exit code.


`

exports['e2e record capture-protocol enabled when capture protocol script returns with an invalid signature displays an appropriate error message 1'] = `

====================================================================================================

(Run Starting)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (record_pass.cy.js) │
│ Searched: cypress/e2e/record_pass* │
│ Params: Tag: false, Group: false, Parallel: false │
│ Run URL: https://dashboard.cypress.io/projects/cjvoj7/runs/12 │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

Running: record_pass.cy.js (1 of 1)
Estimated: X second(s)


record pass
✓ passes
- is pending


1 passing
1 pending


(Results)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 1 │
│ Skipped: 0 │
│ Screenshots: 1 │
│ Video: false │
│ Duration: X seconds │
│ Estimated: X second(s) │
│ Spec Ran: record_pass.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


(Screenshots)

- /XXX/XXX/XXX/cypress/screenshots/record_pass.cy.js/yay it passes.png (400x1022)

Warning: We encountered an error while initializing the Test Replay recording for this spec.

These results will not display Test Replay recordings.

This error will not affect or change the exit code.

Error: Error downloading capture code: Unable to verify protocol signature

(Uploading Cloud Artifacts)

- Video - Nothing to upload
- Screenshot - 1 kB /XXX/XXX/XXX/cypress/screenshots/record_pass.cy.js/yay it passes.png
- Test Replay - Failed Capturing - Error downloading capture code: Unable to verify protocol signature

Uploading Cloud Artifacts: . . . . .

(Uploaded Cloud Artifacts)

- Screenshot - Done Uploading 1 kB in Xm, Ys ZZ.ZZms 1/1 /XXX/XXX/XXX/cypress/screenshots/record_pass.cy.js/yay it passes.png

====================================================================================================

(Run Finished)


Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ record_pass.cy.js XX:XX 2 1 - 1 - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 2 1 - 1 -


───────────────────────────────────────────────────────────────────────────────────────────────────────

Recorded Run: https://dashboard.cypress.io/projects/cjvoj7/runs/12


`
13 changes: 12 additions & 1 deletion system-tests/lib/serverStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import systemTests from './system-tests'
let CAPTURE_PROTOCOL_ENABLED = false
let CAPTURE_PROTOCOL_MESSAGE: string | undefined
let CAPTURE_PROTOCOL_UPLOAD_ENABLED = true
let CAPTURE_PROTOCOL_INVALID_SIG = false

import {
TEST_PRIVATE,
Expand Down Expand Up @@ -236,7 +237,7 @@ export const routeHandlers: Record<string, RouteHandler> = {
res: async (req, res) => {
if (protocolStub) {
res.header('Content-Encoding', 'gzip')
res.header('x-cypress-signature', protocolStub.sign)
res.header('x-cypress-signature', CAPTURE_PROTOCOL_INVALID_SIG ? 'some-invalid-sig' : protocolStub.sign)
res.status(200).send(protocolStub.compressed)
} else {
res.status(404).send('')
Expand Down Expand Up @@ -467,6 +468,16 @@ export const disableCaptureProtocolWithMessage = (message: string) => {
})
}

export const enableInvalidProtocolSignature = () => {
beforeEach(() => {
CAPTURE_PROTOCOL_INVALID_SIG = true
})

afterEach(() => {
CAPTURE_PROTOCOL_INVALID_SIG = false
})
}

export const disableCaptureProtocolUploadUrl = () => {
beforeEach(() => {
CAPTURE_PROTOCOL_UPLOAD_ENABLED = false
Expand Down
18 changes: 18 additions & 0 deletions system-tests/test/record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
CAPTURE_PROTOCOL_UPLOAD_URL,
postRunResponseWithProtocolDisabled,
routeHandlers,
enableInvalidProtocolSignature,
} = require('../lib/serverStub')
const { expectRunsToHaveCorrectTimings } = require('../lib/resultsUtils')
const { randomBytes } = require('crypto')
Expand Down Expand Up @@ -2357,6 +2358,23 @@ describe('e2e record', () => {
})
})

describe('when capture protocol script returns with an invalid signature', () => {
enableCaptureProtocol()
enableInvalidProtocolSignature()

it('displays an appropriate error message', function () {
return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
browser: 'chrome',
spec: 'record_pass*',
record: true,
snapshot: true,
expectedExitCode: 0,
})
})
})

describe('when the tab crashes in chrome', () => {
enableCaptureProtocol()
it('posts accurate test results', function () {
Expand Down
Loading