diff --git a/libs/core-scanner/src/scans/dap.spec.ts b/libs/core-scanner/src/scans/dap.spec.ts index dd7efc9..6152cc4 100644 --- a/libs/core-scanner/src/scans/dap.spec.ts +++ b/libs/core-scanner/src/scans/dap.spec.ts @@ -82,49 +82,42 @@ const MOCK_DAP_SCRIPT_CANDIDATES: Record = { parameters: 'test1=1&test2=2', body: minifiedScriptContents, version: '20240712 v8.2 - GA4', - dapDetected: false, }, realNonMinifiedScript: { url: 'https://test.gov/Universal-Federated-Analytics-Min.js?test1=1&test2=2', parameters: 'test1=1&test2=2', body: nonMinifiedScriptContents, version: '20240712 v8.2 - GA4', - dapDetected: false, }, realScriptNoVersion: { url: 'https://test.gov/Universal-Federated-Analytics-Min.js?test1=1&test2=2', parameters: 'test1=1&test2=2', body: '', version: null, - dapDetected: false, }, gaTagsWithVersion: { url: 'https://abcd-def/G-CSLL4ZEK4L/xyz', parameters: null, body: null, version: '20240712 v8.2 - GA4', - dapDetected: true, }, gaTagsNoVersion: { url: 'https://abcd-def/G-CSLL4ZEK4L/xyz', parameters: null, body: null, version: null, - dapDetected: true, }, invalidUrlWithVersion: { url: 'https://no-dap/here', parameters: null, body: null, version: '20240712 v8.2 - GA4', - dapDetected: false, }, invalidCandidate: { url: 'https://no-dap/here', parameters: null, body: null, version: null, - dapDetected: false, }, } @@ -169,7 +162,7 @@ describe('dap scan', () => { describe('buildDapResult()', () => { it('should detect the presence of DAP when passed a real DAP script', async () => { const result = await executeDapScanner([ MOCK_REQUESTS.realDapScript ]); - expect(result.dapDetected).toEqual(false); + expect(result.dapDetected).toEqual(true); }); it('should detect the DAP version from a minified JS script', async () => { diff --git a/libs/core-scanner/src/scans/dap.ts b/libs/core-scanner/src/scans/dap.ts index 68b3da0..b783299 100644 --- a/libs/core-scanner/src/scans/dap.ts +++ b/libs/core-scanner/src/scans/dap.ts @@ -9,7 +9,6 @@ export type DapScriptCandidate = { body: string, postData?: string | null; version?: string; - dapDetected: boolean; } const DAP_SCRIPT_NAME = 'Universal-Federated-Analytics-Min.js'; @@ -60,7 +59,7 @@ export const buildDapResult = async ( const dapScript: DapScriptCandidate = getBestCandidate(logger, dapScriptCandidates); return { - dapDetected: dapScript.dapDetected, + dapDetected: true, dapParameters: dapScript.parameters, dapVersion: dapScript.version, gaTagIds: allGAPropertyIds, @@ -123,7 +122,7 @@ export function getG4Tag(stringToSearch: string): string[] { /** * - * @param requestUrl The string that may contain a UA tag + * @param stringToSearch The string that may contain a UA tag * @returns Returns the UA tag if found, otherwise an empty string */ export function getUATag(stringToSearch: string): string[] { @@ -137,6 +136,7 @@ export function getUATag(stringToSearch: string): string[] { * Filters a list of HTTPRequests to only include requests that contain DAP * related tags or scripts. * + * @param parentLogger A logger object * @param allRequests An object containing all HTTPRequests made from the page * @returns A pruned down lust of HTTPRequests that contain DAP related tags or scripts */ @@ -169,6 +169,7 @@ export function getDapScriptCandidateRequests(parentLogger: Logger, allRequests: * in order to promote compute efficiency and promote testability of the other functions * in this process. * + * @param parentLogger A logger object * @param dapScriptCandidateRequests An array of Puppeteer.HTTPRequest objects * @returns The requests passed in, but transformed into DapScriptCandidate objects. */ @@ -186,12 +187,6 @@ export async function getDapScriptCandidates(parentLogger: Logger, dapScriptCand postData: null, url: request.url(), version: "", - dapDetected: false, - }; - - if( checkPostDataForPropertyIdMatch(request.postData()) || checkUrlForPropertyIdMatch(request.url()) ) { - logger.debug('DAP script candidate found'); - candidate.dapDetected = true; }; try { @@ -219,6 +214,7 @@ export async function getDapScriptCandidates(parentLogger: Logger, dapScriptCand /** * This will return the best candidate for providing proper DAP analysis * + * @param parentLogger A logger object * @param dapScriptCandidates A list of DapScriptCandidates that will be analyzed to determine best option * @returns The best DAP candidate based on a series of checks */