-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Added a dedicated view for compliance audit reports (#3952)
* Compliance reports are now listed under Resilience tab and do not appear anymore under Scans tab. A dedicated view for a compliance report shows compliance of results. * This feature is currently behind a feature toggle: COMPLIANCE_REPORTS
- Loading branch information
1 parent
600951b
commit 52940b5
Showing
88 changed files
with
8,335 additions
and
409 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import {describe, test, expect} from '@gsa/testing'; | ||
import {createHttp, createEntityResponse} from 'gmp/commands/testing'; | ||
import {AuditReportCommand} from 'gmp/commands/auditreports'; | ||
|
||
describe('AuditReportCommand tests', () => { | ||
test('should request single audit report', () => { | ||
const response = createEntityResponse('report', {_id: 'foo'}); | ||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new AuditReportCommand(fakeHttp); | ||
return cmd.get({id: 'foo'}).then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_report', | ||
report_id: 'foo', | ||
ignore_pagination: 1, | ||
details: 1, | ||
lean: 1, | ||
}, | ||
}); | ||
|
||
const {data} = resp; | ||
expect(data.id).toEqual('foo'); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import {describe, test, expect} from '@gsa/testing'; | ||
import {ALL_FILTER} from 'gmp/models/filter'; | ||
|
||
import { | ||
createHttp, | ||
createEntitiesResponse, | ||
createAggregatesResponse, | ||
} from '../testing'; | ||
import {AuditReportsCommand} from 'gmp/commands/auditreports'; | ||
|
||
describe('AuditReportsCommand tests', () => { | ||
test('should return all audit reports', () => { | ||
const response = createEntitiesResponse('report', [ | ||
{ | ||
_id: '1', | ||
}, | ||
{ | ||
_id: '2', | ||
}, | ||
]); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new AuditReportsCommand(fakeHttp); | ||
return cmd.getAll().then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_reports', | ||
details: 0, | ||
filter: ALL_FILTER.toFilterString(), | ||
usage_type: 'audit', | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.length).toEqual(2); | ||
}); | ||
}); | ||
|
||
test('should return results', () => { | ||
const response = createEntitiesResponse('report', [ | ||
{ | ||
_id: '1', | ||
}, | ||
{ | ||
_id: '2', | ||
}, | ||
]); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new AuditReportsCommand(fakeHttp); | ||
return cmd.get().then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_reports', | ||
details: 0, | ||
usage_type: 'audit', | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.length).toEqual(2); | ||
}); | ||
}); | ||
|
||
test('should aggregate compliance counts', () => { | ||
const response = createAggregatesResponse(); | ||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new AuditReportsCommand(fakeHttp); | ||
return cmd.getComplianceAggregates().then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_aggregate', | ||
aggregate_type: 'report', | ||
group_column: 'compliant', | ||
usage_type: 'audit', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import {isDefined} from 'gmp/utils/identity'; | ||
|
||
import registerCommand from 'gmp/command'; | ||
|
||
import AuditReport from 'gmp/models/auditreport'; | ||
|
||
import {ALL_FILTER} from 'gmp/models/filter'; | ||
|
||
import DefaultTransform from 'gmp/http/transform/default'; | ||
|
||
import {convertBoolean} from './convert'; | ||
import EntitiesCommand from './entities'; | ||
import EntityCommand from './entity'; | ||
|
||
export class AuditReportsCommand extends EntitiesCommand { | ||
constructor(http) { | ||
super(http, 'report', AuditReport); | ||
} | ||
|
||
getEntitiesResponse(root) { | ||
return root.get_reports.get_reports_response; | ||
} | ||
|
||
getComplianceAggregates({filter} = {}) { | ||
return this.getAggregates({ | ||
aggregate_type: 'report', | ||
group_column: 'compliant', | ||
usage_type: 'audit', | ||
filter, | ||
}); | ||
} | ||
|
||
get(params, options) { | ||
return super.get( | ||
{ | ||
details: 0, | ||
...params, | ||
usage_type: 'audit', | ||
}, | ||
options, | ||
); | ||
} | ||
} | ||
|
||
export class AuditReportCommand extends EntityCommand { | ||
constructor(http) { | ||
super(http, 'report', AuditReport); | ||
} | ||
|
||
download({id}, {reportFormatId, deltaReportId, filter}) { | ||
return this.httpGet( | ||
{ | ||
cmd: 'get_report', | ||
delta_report_id: deltaReportId, | ||
details: 1, | ||
report_id: id, | ||
report_format_id: reportFormatId, | ||
filter: isDefined(filter) ? filter.all() : ALL_FILTER, | ||
}, | ||
{transform: DefaultTransform, responseType: 'arraybuffer'}, | ||
); | ||
} | ||
|
||
addAssets({id}, {filter = ''}) { | ||
return this.httpPost({ | ||
cmd: 'create_asset', | ||
report_id: id, | ||
filter, | ||
}); | ||
} | ||
|
||
removeAssets({id}, {filter = ''}) { | ||
return this.httpPost({ | ||
cmd: 'delete_asset', | ||
report_id: id, | ||
filter, | ||
}); | ||
} | ||
|
||
alert({alert_id, report_id, filter}) { | ||
return this.httpPost({ | ||
cmd: 'report_alert', | ||
alert_id, | ||
report_id, | ||
filter, | ||
}); | ||
} | ||
|
||
getDelta( | ||
{id}, | ||
{id: delta_report_id}, | ||
{filter, details = true, ...options} = {}, | ||
) { | ||
return this.httpGet( | ||
{ | ||
id, | ||
delta_report_id, | ||
filter, | ||
ignore_pagination: 1, | ||
details: convertBoolean(details), | ||
}, | ||
options, | ||
).then(this.transformResponse); | ||
} | ||
|
||
get( | ||
{id}, | ||
{ | ||
filter, | ||
details = true, | ||
ignorePagination = true, | ||
lean = true, | ||
...options | ||
} = {}, | ||
) { | ||
return this.httpGet( | ||
{ | ||
id, | ||
filter, | ||
lean: convertBoolean(lean), | ||
ignore_pagination: convertBoolean(ignorePagination), | ||
details: convertBoolean(details), | ||
}, | ||
options, | ||
).then(this.transformResponse); | ||
} | ||
|
||
getElementFromRoot(root) { | ||
return root.get_report.get_reports_response.report; | ||
} | ||
} | ||
|
||
registerCommand('auditreport', AuditReportCommand); | ||
registerCommand('auditreports', AuditReportsCommand); |
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
Oops, something went wrong.