Skip to content

Commit 52940b5

Browse files
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
1 parent 600951b commit 52940b5

File tree

88 files changed

+8335
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+8335
-409
lines changed

allowedSnakeCase.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module.exports = [
2929
'_asset_id',
3030
'asset_id',
3131
'assigned_to',
32+
'audit_report',
33+
'audit_reports',
3234
'auth_algorithm',
3335
'auth_conf_setting',
3436
'auth_method',
@@ -248,6 +250,7 @@ module.exports = [
248250
'highest_severity',
249251
'high_per_host',
250252
'host_allow',
253+
'host_compliance',
251254
'host_cves',
252255
'hostnames_by_ip',
253256
'hosts_allow',

public/locales/gsa-de.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@
158158
"Audit made visible for:\n{{user}}\n{{role}}\n{{group}}": "Audit sichtbar gemacht für:\n{{user}}\n{{role}}\n{{group}}",
159159
"Audit: {{name}}": "Audit: {{name}}",
160160
"Audits": "Audits",
161+
"Audit Reports by Compliance (Total: {{count}})": "Audit-Berichte nach Compliance (Gesamt: {{count}})",
162+
"Audit Reports": "Audit-Berichte",
163+
"Audit Report": "Audit-Bericht",
161164
"Audits using this Policy": "Audits, die diese Richtlinie verwenden",
162165
"Auth": "Auth.",
163166
"Auth Algorithm": "Auth-Algorithmus",
@@ -243,6 +246,7 @@
243246
"Certificate in use will expire at {{date}}": "Aktuelles Zertifikat wird am {{date}} ablaufen",
244247
"Change Password": "Passwort ändern",
245248
"Changed": "Verändert",
249+
"Chart: Audit Reports by Compliance": "Diagramm: Audit-Berichte nach Compliance",
246250
"Chart: CERT-Bund Advisories by CVSS": "Diagramm: CERT-Bund-Advisories nach CVSS",
247251
"Chart: CERT-Bund Advisories by Creation Time": "Diagramm: CERT-Bund-Advisories nach Erstellungszeit",
248252
"Chart: CERT-Bund Advisories by Severity Class": "Diagramm: CERT-Bund-Advisories nach Schweregradklasse",
@@ -323,6 +327,8 @@
323327
"Complete": "Vollständig",
324328
"Complexity": "Komplexität",
325329
"Compliance Audits": "Compliance Audits",
330+
"Compliance Audit Reports": "Compliance-Audit-Berichte",
331+
"Compliance Percent": "Compliance-Prozent",
326332
"Compliance Policies": "Compliance Richtlinien",
327333
"Compliance Status": "Compliance Status",
328334
"Compose": "Zusammenstellen",
@@ -841,6 +847,7 @@
841847
"Include log messages in your filter settings.": "Log-Nachrichten in die Filtereinstellungen einbeziehen.",
842848
"Include report": "Bericht einfügen",
843849
"Included": "Beinhaltet",
850+
"Incomplete": "Unvollständig",
844851
"Info": "Info",
845852
"Information": "Informationen",
846853
"Inheriting user": "Erbender Benutzer",
@@ -1543,6 +1550,7 @@
15431550
"TLS Certificates by Modification Time (Total: {{count}})": "TLS-Zertifikate nach Änderungszeit (Gesamt: {{count}})",
15441551
"TLS Certificates by Status (Total: {{count}})": "TLS-Zertifikate nach Status (Gesamt: {{count}})",
15451552
"TLS Certificates for this Host": "TLS-Zertifikate für diesen Host",
1553+
"Table: Audit Reports by Compliance": "Tabelle: Audit-Berichte nach Compliance",
15461554
"Table: CERT-Bund Advisories by CVSS": "Tabelle: CERT-Bund-Advisories nach CVSS",
15471555
"Table: CERT-Bund Advisories by Creation Time": "Tabelle: CERT-Bund-Advisories nach Erstellungszeit",
15481556
"Table: CERT-Bund Advisories by Severity Class": "Tabelle: CERT-Bund-Advisories nach Schweregradklasse",
@@ -1908,6 +1916,7 @@
19081916
"task": "Aufgabe",
19091917
"to": "für",
19101918
"undefined": "undefiniert",
1919+
"Undefined": "Undefiniert",
19111920
"until {{- enddate}}": "bis {{- enddate}}",
19121921
"verinice Connector": "verinice-Konnektor",
19131922
"verinice.PRO Connector": "verinice.PRO-Konnektor",

src/gmp/capabilities/capabilities.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {pluralizeType} from 'gmp/utils/entitytype';
99
import {parseBoolean} from 'gmp/parser';
1010

1111
const types = {
12-
audit: 'task',
13-
audits: 'task',
12+
auditreport: 'audit_report',
13+
auditreports: 'audit_reports',
1414
host: 'asset',
1515
hosts: 'asset',
1616
os: 'asset',
@@ -42,12 +42,19 @@ const types = {
4242
tlscertificates: 'tls_certificate',
4343
};
4444

45+
const subtypes = {
46+
audit: 'task',
47+
audits: 'task',
48+
audit_report: 'report',
49+
audit_reports: 'reports',
50+
};
51+
4552
const convertType = type => {
4653
const ctype = types[type];
4754
if (isDefined(ctype)) {
48-
return ctype;
55+
type = ctype;
4956
}
50-
return type;
57+
return subtypes[type] || type;
5158
};
5259

5360
class Capabilities {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-FileCopyrightText: 2024 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import {describe, test, expect} from '@gsa/testing';
7+
import {createHttp, createEntityResponse} from 'gmp/commands/testing';
8+
import {AuditReportCommand} from 'gmp/commands/auditreports';
9+
10+
describe('AuditReportCommand tests', () => {
11+
test('should request single audit report', () => {
12+
const response = createEntityResponse('report', {_id: 'foo'});
13+
const fakeHttp = createHttp(response);
14+
15+
expect.hasAssertions();
16+
17+
const cmd = new AuditReportCommand(fakeHttp);
18+
return cmd.get({id: 'foo'}).then(resp => {
19+
expect(fakeHttp.request).toHaveBeenCalledWith('get', {
20+
args: {
21+
cmd: 'get_report',
22+
report_id: 'foo',
23+
ignore_pagination: 1,
24+
details: 1,
25+
lean: 1,
26+
},
27+
});
28+
29+
const {data} = resp;
30+
expect(data.id).toEqual('foo');
31+
});
32+
});
33+
});
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* SPDX-FileCopyrightText: 2024 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import {describe, test, expect} from '@gsa/testing';
7+
import {ALL_FILTER} from 'gmp/models/filter';
8+
9+
import {
10+
createHttp,
11+
createEntitiesResponse,
12+
createAggregatesResponse,
13+
} from '../testing';
14+
import {AuditReportsCommand} from 'gmp/commands/auditreports';
15+
16+
describe('AuditReportsCommand tests', () => {
17+
test('should return all audit reports', () => {
18+
const response = createEntitiesResponse('report', [
19+
{
20+
_id: '1',
21+
},
22+
{
23+
_id: '2',
24+
},
25+
]);
26+
27+
const fakeHttp = createHttp(response);
28+
29+
expect.hasAssertions();
30+
31+
const cmd = new AuditReportsCommand(fakeHttp);
32+
return cmd.getAll().then(resp => {
33+
expect(fakeHttp.request).toHaveBeenCalledWith('get', {
34+
args: {
35+
cmd: 'get_reports',
36+
details: 0,
37+
filter: ALL_FILTER.toFilterString(),
38+
usage_type: 'audit',
39+
},
40+
});
41+
const {data} = resp;
42+
expect(data.length).toEqual(2);
43+
});
44+
});
45+
46+
test('should return results', () => {
47+
const response = createEntitiesResponse('report', [
48+
{
49+
_id: '1',
50+
},
51+
{
52+
_id: '2',
53+
},
54+
]);
55+
56+
const fakeHttp = createHttp(response);
57+
58+
expect.hasAssertions();
59+
60+
const cmd = new AuditReportsCommand(fakeHttp);
61+
return cmd.get().then(resp => {
62+
expect(fakeHttp.request).toHaveBeenCalledWith('get', {
63+
args: {
64+
cmd: 'get_reports',
65+
details: 0,
66+
usage_type: 'audit',
67+
},
68+
});
69+
const {data} = resp;
70+
expect(data.length).toEqual(2);
71+
});
72+
});
73+
74+
test('should aggregate compliance counts', () => {
75+
const response = createAggregatesResponse();
76+
const fakeHttp = createHttp(response);
77+
78+
expect.hasAssertions();
79+
80+
const cmd = new AuditReportsCommand(fakeHttp);
81+
return cmd.getComplianceAggregates().then(resp => {
82+
expect(fakeHttp.request).toHaveBeenCalledWith('get', {
83+
args: {
84+
cmd: 'get_aggregate',
85+
aggregate_type: 'report',
86+
group_column: 'compliant',
87+
usage_type: 'audit',
88+
},
89+
});
90+
});
91+
});
92+
});

src/gmp/commands/__tests__/reports.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('ReportsCommand tests', () => {
3232
cmd: 'get_reports',
3333
details: 0,
3434
filter: ALL_FILTER.toFilterString(),
35+
usage_type: 'scan',
3536
},
3637
});
3738
const {data} = resp;
@@ -59,6 +60,7 @@ describe('ReportsCommand tests', () => {
5960
args: {
6061
cmd: 'get_reports',
6162
details: 0,
63+
usage_type: 'scan',
6264
},
6365
});
6466
const {data} = resp;

src/gmp/commands/auditreports.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* SPDX-FileCopyrightText: 2024 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import {isDefined} from 'gmp/utils/identity';
7+
8+
import registerCommand from 'gmp/command';
9+
10+
import AuditReport from 'gmp/models/auditreport';
11+
12+
import {ALL_FILTER} from 'gmp/models/filter';
13+
14+
import DefaultTransform from 'gmp/http/transform/default';
15+
16+
import {convertBoolean} from './convert';
17+
import EntitiesCommand from './entities';
18+
import EntityCommand from './entity';
19+
20+
export class AuditReportsCommand extends EntitiesCommand {
21+
constructor(http) {
22+
super(http, 'report', AuditReport);
23+
}
24+
25+
getEntitiesResponse(root) {
26+
return root.get_reports.get_reports_response;
27+
}
28+
29+
getComplianceAggregates({filter} = {}) {
30+
return this.getAggregates({
31+
aggregate_type: 'report',
32+
group_column: 'compliant',
33+
usage_type: 'audit',
34+
filter,
35+
});
36+
}
37+
38+
get(params, options) {
39+
return super.get(
40+
{
41+
details: 0,
42+
...params,
43+
usage_type: 'audit',
44+
},
45+
options,
46+
);
47+
}
48+
}
49+
50+
export class AuditReportCommand extends EntityCommand {
51+
constructor(http) {
52+
super(http, 'report', AuditReport);
53+
}
54+
55+
download({id}, {reportFormatId, deltaReportId, filter}) {
56+
return this.httpGet(
57+
{
58+
cmd: 'get_report',
59+
delta_report_id: deltaReportId,
60+
details: 1,
61+
report_id: id,
62+
report_format_id: reportFormatId,
63+
filter: isDefined(filter) ? filter.all() : ALL_FILTER,
64+
},
65+
{transform: DefaultTransform, responseType: 'arraybuffer'},
66+
);
67+
}
68+
69+
addAssets({id}, {filter = ''}) {
70+
return this.httpPost({
71+
cmd: 'create_asset',
72+
report_id: id,
73+
filter,
74+
});
75+
}
76+
77+
removeAssets({id}, {filter = ''}) {
78+
return this.httpPost({
79+
cmd: 'delete_asset',
80+
report_id: id,
81+
filter,
82+
});
83+
}
84+
85+
alert({alert_id, report_id, filter}) {
86+
return this.httpPost({
87+
cmd: 'report_alert',
88+
alert_id,
89+
report_id,
90+
filter,
91+
});
92+
}
93+
94+
getDelta(
95+
{id},
96+
{id: delta_report_id},
97+
{filter, details = true, ...options} = {},
98+
) {
99+
return this.httpGet(
100+
{
101+
id,
102+
delta_report_id,
103+
filter,
104+
ignore_pagination: 1,
105+
details: convertBoolean(details),
106+
},
107+
options,
108+
).then(this.transformResponse);
109+
}
110+
111+
get(
112+
{id},
113+
{
114+
filter,
115+
details = true,
116+
ignorePagination = true,
117+
lean = true,
118+
...options
119+
} = {},
120+
) {
121+
return this.httpGet(
122+
{
123+
id,
124+
filter,
125+
lean: convertBoolean(lean),
126+
ignore_pagination: convertBoolean(ignorePagination),
127+
details: convertBoolean(details),
128+
},
129+
options,
130+
).then(this.transformResponse);
131+
}
132+
133+
getElementFromRoot(root) {
134+
return root.get_report.get_reports_response.report;
135+
}
136+
}
137+
138+
registerCommand('auditreport', AuditReportCommand);
139+
registerCommand('auditreports', AuditReportsCommand);

src/gmp/commands/reports.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class ReportsCommand extends EntitiesCommand {
5252
{
5353
details: 0, // ensure to request no details by default
5454
...params,
55+
usage_type: 'scan',
5556
},
5657
options,
5758
);

0 commit comments

Comments
 (0)