Skip to content

Commit

Permalink
add integrity e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Skinner committed Nov 26, 2024
1 parent 784cdf6 commit 287bf9b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
13 changes: 13 additions & 0 deletions test/browser/features/fixtures/packages/integrity/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link href="/favicon.png" rel="shortcut icon" type="image/x-icon">
<script src="./dist/bundle.js" type="module"></script>
<title>Integrity header</title>
</head>
<body>
<h1>integrity-header</h1>
<button id="send-span">send-span</button>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "integrity",
"private": true,
"scripts": {
"build": "rollup --config ../rollup.config.mjs",
"clean": "rm -rf dist"
}
}
28 changes: 28 additions & 0 deletions test/browser/features/fixtures/packages/integrity/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import BugsnagPerformance from '@bugsnag/browser-performance'

const parameters = new URLSearchParams(window.location.search)
const apiKey = parameters.get('api_key')
const endpoint = parameters.get('endpoint')

BugsnagPerformance.start({
apiKey,
endpoint,
sendPayloadChecksums: true,
maximumBatchSize: 1,
autoInstrumentFullPageLoads: false,
autoInstrumentNetworkRequests: false,
autoInstrumentRouteChanges: false,
serviceName: 'integrity'
})

document.getElementById('send-span').onclick = () => {
const spanOptions = {}

if (parameters.has('isFirstClass')) {
spanOptions.isFirstClass = JSON.parse(parameters.get('isFirstClass'))
}

const span = BugsnagPerformance.startSpan("Custom/ManualSpanScenario", spanOptions)
span.end()
}

10 changes: 10 additions & 0 deletions test/browser/features/integrity.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Integrity header

Scenario: Integrity headers are set when setPayloadChecksums is true
Given I navigate to the test URL "/docs/integrity"
And I wait to receive a sampling request
Then I click the element "send-span"
And I wait for 1 span

Then the sampling request "bugsnag-integrity" header matches the regex "^sha1 (\d|[abcdef]){40}$"
Then the trace "bugsnag-integrity" header matches the regex "^sha1 (\d|[abcdef]){40}$"
6 changes: 1 addition & 5 deletions test/browser/features/support/maze-config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ def get_test_url()
maze_address = "#{host}:9339"
end

if Maze.config.https
protocol = 'https'
else
protocol = 'http'
end
protocol = Maze.config.https ? 'https' : 'http'

UrlGenerator.new(
URI("#{protocol}://#{maze_address}"),
Expand Down

0 comments on commit 287bf9b

Please sign in to comment.