Skip to content

Commit

Permalink
maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 14, 2023
1 parent c036fcb commit e8dbf2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions testcafe/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fixture('posthog.js capture')
})

test('Custom events work and are accessible via /api/event', async (t) => {
const { testSessionId } = await initPosthog()
const testSessionId = await initPosthog()
await t
.wait(5000)
.click('[data-cy-custom-event-button]')
Expand All @@ -38,7 +38,7 @@ test('Custom events work and are accessible via /api/event', async (t) => {
})

test('Autocaptured events work and are accessible via /api/event', async (t) => {
const { testSessionId } = await initPosthog()
const testSessionId = await initPosthog()
await t
.wait(5000)
.click('[data-cy-link-mask-text]')
Expand Down Expand Up @@ -76,7 +76,7 @@ test('Autocaptured events work and are accessible via /api/event', async (t) =>
})

test('Config options change autocapture behavior accordingly', async (t) => {
const { testSessionId } = await initPosthog({ mask_all_text: true, mask_all_element_attributes: true })
const testSessionId = await initPosthog({ mask_all_text: true, mask_all_element_attributes: true })

await t
.wait(5000)
Expand Down
4 changes: 2 additions & 2 deletions testcafe/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export const staticFilesMock = RequestMock()

export const initPosthog = (config) => {
return ClientFunction((configParams = {}) => {
var testSessionId = Math.round(Math.random() * 10000000000).toString()
const testSessionId = Math.round(Math.random() * 10000000000).toString()

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
configParams.debug = true
window.posthog.init(configParams.api_key, configParams)
window.posthog.register({
testSessionId,
})

return { testSessionId, seekFirstNonPublicSubDomainFn: window.POSTHOG_INTERNAL_seekFirstNonPublicSubDomain }
return testSessionId
})({
...config,
api_host: POSTHOG_API_HOST,
Expand Down
9 changes: 7 additions & 2 deletions testcafe/subdomain.detection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ const testCases = [
},
]

// eslint-disable-next-line no-undef
const getSubject = ClientFunction(() => {
return window.POSTHOG_INTERNAL_seekFirstNonPublicSubDomain
})

testCases.forEach(({ location, expected }) => {
test(`location ${location} is detected as having subdomain ${expected}`, async (t) => {
const { seekFirstNonPublicSubDomainFn } = await initPosthog()
await t.expect(seekFirstNonPublicSubDomainFn(location)).eql(expected)
await initPosthog()
await t.expect(getSubject()(location)).eql(expected)
})
})

0 comments on commit e8dbf2a

Please sign in to comment.