Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: request edit_config_family_all alongside edit_config_family #3857

Merged
40 changes: 22 additions & 18 deletions src/gmp/commands/__tests__/scanconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import {
createEntityResponse,
createHttp,
createHttpMany,
createActionResultResponse,
createResponse,
} from '../testing';
Expand Down Expand Up @@ -296,27 +297,30 @@ describe('ScanConfigCommand tests', () => {
},
],
},
all: {
get_nvts_response: {
nvt: [
{
_oid: 1,
cvss_base: 1.1,
},
{
_oid: 2,
cvss_base: 2.2,
},
{
_oid: 3,
cvss_base: 3.3,
},
],
},
},
});
const responseAll = createResponse({
get_config_family_response: {
get_nvts_response: {
nvt: [
{
_oid: 1,
cvss_base: 1.1,
},
{
_oid: 2,
cvss_base: 2.2,
},
{
_oid: 3,
cvss_base: 3.3,
},
],
},
},
});
const fakeHttp = createHttp(response);
const responses = [response, responseAll];
const fakeHttp = createHttpMany(responses);

expect.hasAssertions();

Expand Down
14 changes: 11 additions & 3 deletions src/gmp/commands/scanconfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ export class ScanConfigCommand extends EntityCommand {
}

editScanConfigFamilySettings({id, familyName}) {
return this.httpGet({
const get = this.httpGet({
cmd: 'edit_config_family',
id,
family: familyName,
}).then(response => {
});
const all = this.httpGet({
cmd: 'edit_config_family_all',
id,
family: familyName,
});
return Promise.all([get, all]).then(([response, response_all]) => {
const {data} = response;
const data_all = response_all.data;
const config_resp = data.get_config_family_response;
const config_resp_all = data_all.get_config_family_response;
const settings = {};

const nvts = {};
Expand All @@ -142,7 +150,7 @@ export class ScanConfigCommand extends EntityCommand {
nvts[oid] = true;
});

settings.nvts = map(config_resp.all.get_nvts_response.nvt, nvt => {
settings.nvts = map(config_resp_all.get_nvts_response.nvt, nvt => {
nvt.oid = nvt._oid;
delete nvt._oid;

Expand Down
9 changes: 9 additions & 0 deletions src/gmp/commands/testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ export const createHttp = response => ({
request: jest.fn().mockReturnValue(Promise.resolve(response)),
});

export const createHttpMany = responses => {
let i = 0;
return {
request: jest
.fn()
.mockImplementation(() => Promise.resolve(responses[i++])),
};
};

// vim: set ts=2 sw=2 tw=80: