Skip to content

Commit

Permalink
Merge pull request #364 from GSA/lc/1132-dap-scan-updates
Browse files Browse the repository at this point in the history
Revert DAP logic changes
  • Loading branch information
luke-at-flexion committed Sep 11, 2024
2 parents 4d34efb + 0fd11e8 commit 2ac90c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
9 changes: 1 addition & 8 deletions libs/core-scanner/src/scans/dap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,49 +82,42 @@ const MOCK_DAP_SCRIPT_CANDIDATES: Record<string, DapScriptCandidate> = {
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,
},
}

Expand Down Expand Up @@ -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 () => {
Expand Down
14 changes: 5 additions & 9 deletions libs/core-scanner/src/scans/dap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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[] {
Expand All @@ -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
*/
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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 {
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 2ac90c3

Please sign in to comment.