-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: SPA feature respects ajax deny_list for fetch (#633)
- Loading branch information
1 parent
cff7bc4
commit ccfe510
Showing
6 changed files
with
102 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
<html> | ||
<head> | ||
<title>RUM Unit Test</title> | ||
{init} | ||
{config} | ||
{loader} | ||
</head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
<html> | ||
<head> | ||
<title>RUM Unit Test</title> | ||
{init} | ||
{config} | ||
{loader} | ||
</head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,79 @@ | ||
import { supportsFetch } from '../../../tools/browser-matcher/common-matchers.mjs' | ||
|
||
describe('Ajax events to beacon endpoint', () => { | ||
it('not captured when blocked', async () => { | ||
let url = await browser.testHandle.assetURL('spa/ajax-deny-list.html', { init: { ajax: { block_internal: true } } }) | ||
let nextAjaxReq = browser.testHandle.expectAjaxEvents(10000, true) | ||
await browser.url(url) | ||
const [ajaxEvents, interactionEvents] = await Promise.all([ | ||
browser.testHandle.expectAjaxEvents(10000, true), | ||
browser.testHandle.expectInteractionEvents(), | ||
browser.url(await browser.testHandle.assetURL('spa/ajax-deny-list.html', { init: { ajax: { block_internal: true } } })) | ||
]) | ||
|
||
await expect(nextAjaxReq).resolves.toBeUndefined() | ||
expect(ajaxEvents).toBeUndefined() | ||
expect(interactionEvents.request.body).not.toEqual(expect.arrayContaining([ | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/json', | ||
type: 'ajax', | ||
requestedWith: 'XMLHttpRequest' | ||
}), | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/text', | ||
type: 'ajax', | ||
requestedWith: 'XMLHttpRequest' | ||
}), | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/json', | ||
type: 'ajax', | ||
requestedWith: 'fetch' | ||
}), | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/text', | ||
type: 'ajax', | ||
requestedWith: 'fetch' | ||
}) | ||
])) | ||
}) | ||
|
||
it('captured when allowed', async () => { | ||
let url = await browser.testHandle.assetURL('spa/ajax-deny-list.html', { init: { ajax: { block_internal: false } } }) | ||
let nextAjaxReq = browser.testHandle.expectAjaxEvents(10000) | ||
await browser.url(url) | ||
it('is captured when not blocked', async () => { | ||
const [ajaxEvents, interactionEvents] = await Promise.all([ | ||
browser.testHandle.expectAjaxEvents(), | ||
browser.testHandle.expectInteractionEvents(), | ||
browser.url(await browser.testHandle.assetURL('spa/ajax-deny-list.html', { init: { ajax: { block_internal: false } } })) | ||
]) | ||
|
||
let correctXhrEvent = (await nextAjaxReq)?.request.body.some(ajaxNode => ajaxNode.domain.startsWith('bam-test-1.nr-local.net') && ajaxNode.path === '/json') | ||
expect(correctXhrEvent).toEqual(true) | ||
const events = [...ajaxEvents.request.body, ...interactionEvents.request.body] | ||
expect(events).toEqual(expect.arrayContaining([ | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/json', | ||
type: 'ajax', | ||
requestedWith: 'XMLHttpRequest' | ||
}), | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/text', | ||
type: 'ajax', | ||
requestedWith: 'XMLHttpRequest' | ||
}), | ||
...(browserMatch(supportsFetch) | ||
? [ | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/json', | ||
type: 'ajax', | ||
requestedWith: 'fetch' | ||
}), | ||
expect.objectContaining({ | ||
domain: expect.stringContaining('bam-test-1.nr-local.net'), | ||
path: '/text', | ||
type: 'ajax', | ||
requestedWith: 'fetch' | ||
}) | ||
] | ||
: []) | ||
])) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters