Fix `dig-snfe modifiers` to properly detect changes in results

This commit is contained in:
Raymond Hill 2021-12-06 08:01:05 -05:00
parent 38a96603c1
commit 3004c8832a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 18 additions and 6 deletions

View File

@ -227,7 +227,7 @@ async function matchRequestModifiers(engine, requests) {
modified = true;
if ( NEED_RESULTS ) {
const reqstop = process.hrtime.bigint();
details.f = directives.map(a => a.logData().raw).sort().join(' ');
details.f = directives.map(a => `${a.result}:${a.logData().raw}`).sort();
details.t = Math.round(Number(reqstop - reqstart) / 10) / 100;
results['csp'].push([ i, Object.assign({}, details) ]);
}
@ -240,7 +240,7 @@ async function matchRequestModifiers(engine, requests) {
modified = true;
if ( NEED_RESULTS ) {
const reqstop = process.hrtime.bigint();
details.f = directives.map(a => a.logData().raw).sort().join(' ');
details.f = directives.map(a => `${a.result}:${a.logData().raw}`).sort();
details.t = Math.round(Number(reqstop - reqstart) / 10) / 100;
results['redirect-rule'].push([ i, Object.assign({}, details) ]);
}
@ -253,7 +253,7 @@ async function matchRequestModifiers(engine, requests) {
modified = true;
if ( NEED_RESULTS ) {
const reqstop = process.hrtime.bigint();
details.f = directives.map(a => a.logData().raw).sort().join(' ');
details.f = directives.map(a => `${a.result}:${a.logData().raw}`).sort();
details.t = Math.round(Number(reqstop - reqstart) / 10) / 100;
results['removeparam'].push([ i, Object.assign({}, details) ]);
}
@ -298,13 +298,25 @@ async function compareModifiers(afterResults) {
const after = new Map(afterResults[modifier]);
for ( const [ i, b ] of before ) {
const a = after.get(i);
if ( a !== undefined && a.f === b.f ) { continue; }
diffs.push([ i, { before: b, after: a || null } ]);
if ( a !== undefined && JSON.stringify(a.f) === JSON.stringify(b.f) ) { continue; }
diffs.push([ i, {
type: b.type,
url: b.url,
originURL: b.originURL,
before: { f: b.f, t: b.t },
after: a !== undefined ? { f: a.f, t: a.t } : null,
}]);
}
for ( const [ i, a ] of after ) {
const b = before.get(i);
if ( b !== undefined ) { continue; }
diffs.push([ i, { before: b || null, after: a } ]);
diffs.push([ i, {
type: a.type,
url: a.url,
originURL: a.originURL,
before: null,
after: { f: a.f, t: a.t },
}]);
}
}
return diffs;