Skip to content

Commit

Permalink
change the delta.unknown list to delta.error
Browse files Browse the repository at this point in the history
  • Loading branch information
hkong-mitre committed Sep 20, 2023
1 parent 5a22064 commit 35bf539
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/core/Delta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe(`Delta`, () => {
const delta = await Delta.newDeltaFromGitHistory(startDate, null, process.env.CVES_TEST_BASE_DIRECTORY);
const deltaNow = await Delta.newDeltaFromGitHistory(startDate, new Date().toISOString(), process.env.CVES_TEST_BASE_DIRECTORY);
expect(delta.numberOfChanges).toBe(deltaNow.numberOfChanges);
expect(delta.unknown).toEqual(deltaNow.unknown);
expect(delta.error).toEqual(deltaNow.error);
await cleanup_TestGitRepository()
});

Expand Down
24 changes: 12 additions & 12 deletions src/core/Delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export enum DeltaQueue {
kNew = 1,
kPublished,
kUpdated,
kUnknown
kError
}

/**
Expand Down Expand Up @@ -63,7 +63,7 @@ export class DeltaOutpuItem {

static replacer(key: string, value: any) {
let items = [];
if (key === 'new' || key === 'updated' || key === 'unknown') {
if (key === 'new' || key === 'updated' || key === 'error') {
value.forEach((item: CveCorePlus) => {
// Note, it is important to keep this loop as simple as possible,
// don't rely on item being an actual CveCorePlus object since
Expand Down Expand Up @@ -106,7 +106,7 @@ export class Delta {
numberOfChanges: number = 0;
new: CveCorePlus[] = [];
updated: CveCorePlus[] = [];
unknown?: CveCorePlus[] = []; // for any CVE that is not new or updated, which should never be the case except for errors
error?: CveCorePlus[] = []; // for any CVE that is not new or updated, which should never be the case except for errors

// ----- constructor and factory functions ----- -----

Expand All @@ -124,7 +124,7 @@ export class Delta {
this.new = prevDelta?.new ? cloneDeep(prevDelta.new) : [];
// this.published = prevDelta?.published ? cloneDeep(prevDelta.published) : [];
this.updated = prevDelta?.updated ? cloneDeep(prevDelta.updated) : [];
this.unknown = prevDelta?.unknown ? cloneDeep(prevDelta.unknown) : [];
this.error = prevDelta?.error ? cloneDeep(prevDelta.error) : [];
}
}

Expand All @@ -141,7 +141,7 @@ export class Delta {
const delta = await git.logDeltasInTimeWindow(start, stop);
// files.forEach(element => {
// const tuple = Delta.getCveIdMetaData(element);
// delta.add(new CveCore(tuple[0]), DeltaQueue.kUnknown);
// delta.add(new CveCore(tuple[0]), DeltaQueue.kError);
// });
return delta;
}
Expand Down Expand Up @@ -241,7 +241,7 @@ export class Delta {
return this.new.length
// + this.published.length
+ this.updated.length
+ this.unknown.length;
+ this.error.length;
}

/** adds a cveCore object into one of the queues in a delta object
Expand All @@ -266,8 +266,8 @@ export class Delta {
break;
default:
if (cve.cveId) {
console.log(`pushing into unknown: ${JSON.stringify(cve)}`);
this.unknown.push(cve);
console.log(`pushing into error list: ${JSON.stringify(cve)}`);
this.error.push(cve);
}
else {
console.log(`ignoring cve=${JSON.stringify(cve)}`);
Expand All @@ -284,16 +284,16 @@ export class Delta {
const updatedCves: string[] = [];
this.updated.forEach(item => updatedCves.push(item.cveId.id));
const unkownFiles: string[] = [];
this.unknown.forEach(item => unkownFiles.push(item.cveId.id));
this.error.forEach(item => unkownFiles.push(item.cveId.id));
let s = `${this.new.length} new | ${this.updated.length} updated`;
if (this.unknown.length > 0) {
s += ` | ${this.unknown.length} other files`;
if (this.error.length > 0) {
s += ` | ${this.error.length} other files`;
}
const retstr =
`${this.numberOfChanges} changes (${s}):
- ${this.new.length} new CVEs: ${newCves.join(', ')}
- ${this.updated.length} updated CVEs: ${updatedCves.join(', ')}
${this.unknown.length > 0 ? `- ${this.unknown.length} other files: ${unkownFiles.join(', ')}` : ``}
${this.error.length > 0 ? `- ${this.error.length} other files: ${unkownFiles.join(', ')}` : ``}
`;
return retstr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class Git {
delta.add(CveCorePlus.fromJsonFile(path), DeltaQueue.kUpdated);
break;
default:
delta.add(CveCorePlus.fromJsonFile(path), DeltaQueue.kUnknown);
delta.add(CveCorePlus.fromJsonFile(path), DeltaQueue.kError);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/activityLog/recent_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cveId": "CVE-2023-31996"
}
],
"unknown": []
"error": []
},
"steps": [
{
Expand Down Expand Up @@ -71,7 +71,7 @@
"cveId": "CVE-2022-46945"
}
],
"unknown": []
"error": []
},
"steps": [
{
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/delta/test_delta.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"dateUpdated": "1970-01-01T01:02:00.000Z"
}
],
"unknown": []
"error": []
}
6 changes: 3 additions & 3 deletions test/fixtures/delta/test_deltaLog.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dateUpdated": "2023-07-24T17:32:04.394Z"
}
],
"unknown": []
"error": []
},
{
"fetchTime": "2023-07-24T17:14:04.394Z",
Expand All @@ -38,7 +38,7 @@
"dateUpdated": "2023-07-24T17:12:04.394Z"
}
],
"unknown": []
"error": []
},
{
"fetchTime": "2023-07-24T17:02:00.394Z",
Expand All @@ -52,6 +52,6 @@
}
],
"updated": [],
"unknown": []
"error": []
}
]
2 changes: 1 addition & 1 deletion test/fixtures/delta/test_delta_min.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"cveId": "CVE-2023-3321"
}
],
"unknown": []
"error": []
}

0 comments on commit 35bf539

Please sign in to comment.