Skip to content

Commit

Permalink
Merge pull request #1220 from bjoernricks/new-task-single-requests
Browse files Browse the repository at this point in the history
New task single requests
  • Loading branch information
bjoernricks authored Mar 22, 2019
2 parents afddd22 + 7dfd74d commit 731eabb
Show file tree
Hide file tree
Showing 20 changed files with 3,090 additions and 1,049 deletions.
12 changes: 11 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ $ cd gsa && git log
* Sort alerts at task details alphanumerically #1094
* Add Alemba vFire alert to GUI #1100
* Add Sourcefire PKCS12 password support #1150

* Fix crash of Task dialog without user having get_config, get_scanner,
get_tags and get_targets permissions #1220
* Ensure host ordering is valid in task dialog #1220
* Disable tag selection if not task should be added in create task dialog #1220
* Don't show add tag fields when editing a task #1220
* Fix race condition resulting in not displaying scan config details at task
dialog when opening the dialog for the first time #1220
* Fix saving run schedule once setting from Task dialog #1220
* Don't create a container task from the task dialog accidentially #1220
* Use "Do not automatically delete reports" as default again in task dialog
#1220


## gsa 8.0+beta2 (2018-12-04)
Expand Down
268 changes: 268 additions & 0 deletions gsa/src/gmp/commands/__tests__/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import {TaskCommand} from '../tasks';

import {createActionResultResponse, createHttp} from '../testing';
import {
HOSTS_ORDERING_RANDOM,
AUTO_DELETE_KEEP_DEFAULT_VALUE,
AUTO_DELETE_KEEP,
} from 'gmp/models/task';
import {
OPENVAS_SCANNER_TYPE,
OPENVAS_DEFAULT_SCANNER_ID,
} from 'gmp/models/scanner';

describe('TaskCommand tests', () => {
test('should create new task', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new TaskCommand(fakeHttp);
return cmd
.create({
alterable: 0,
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
comment: 'comment',
config_id: 'c1',
hosts_ordering: HOSTS_ORDERING_RANDOM,
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: OPENVAS_DEFAULT_SCANNER_ID,
scanner_type: OPENVAS_SCANNER_TYPE,
target_id: 't1',
})
.then(resp => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
add_tag: undefined,
'alert_ids:': [],
alterable: 0,
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
auto_delete_data: undefined,
cmd: 'create_task',
comment: 'comment',
config_id: 'c1',
hosts_ordering: HOSTS_ORDERING_RANDOM,
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: OPENVAS_DEFAULT_SCANNER_ID,
scanner_type: OPENVAS_SCANNER_TYPE,
schedule_id: undefined,
schedule_periods: undefined,
source_iface: undefined,
tag_id: undefined,
target_id: 't1',
},
});

const {data} = resp;
expect(data.id).toEqual('foo');
});
});

test('should create new task with all parameters', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new TaskCommand(fakeHttp);
return cmd
.create({
add_tag: 1,
alterable: 0,
alert_ids: ['a1', 'a2'],
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
auto_delete_data: AUTO_DELETE_KEEP_DEFAULT_VALUE,
comment: 'comment',
config_id: 'c1',
hosts_ordering: HOSTS_ORDERING_RANDOM,
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: OPENVAS_DEFAULT_SCANNER_ID,
scanner_type: OPENVAS_SCANNER_TYPE,
schedule_id: 's1',
schedule_periods: 1,
source_iface: 'eth0',
tag_id: 't1',
target_id: 't1',
})
.then(resp => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
add_tag: 1,
'alert_ids:': ['a1', 'a2'],
alterable: 0,
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
auto_delete_data: AUTO_DELETE_KEEP_DEFAULT_VALUE,
cmd: 'create_task',
comment: 'comment',
config_id: 'c1',
hosts_ordering: HOSTS_ORDERING_RANDOM,
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: OPENVAS_DEFAULT_SCANNER_ID,
scanner_type: OPENVAS_SCANNER_TYPE,
schedule_id: 's1',
schedule_periods: 1,
source_iface: 'eth0',
tag_id: 't1',
target_id: 't1',
},
});

const {data} = resp;
expect(data.id).toEqual('foo');
});
});

test('should save task', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new TaskCommand(fakeHttp);
return cmd
.save({
alterable: 0,
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
comment: 'comment',
hosts_ordering: HOSTS_ORDERING_RANDOM,
id: 'task1',
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
})
.then(resp => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
'alert_ids:': [],
alterable: 0,
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
auto_delete_data: undefined,
cmd: 'save_task',
comment: 'comment',
config_id: 0,
hosts_ordering: HOSTS_ORDERING_RANDOM,
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: 0,
scanner_type: undefined,
schedule_id: 0,
schedule_periods: undefined,
source_iface: undefined,
task_id: 'task1',
target_id: 0,
},
});

const {data} = resp;
expect(data.id).toEqual('foo');
});
});

test('should save task with all parameters', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new TaskCommand(fakeHttp);
return cmd
.save({
alterable: 0,
alert_ids: ['a1', 'a2'],
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
auto_delete_data: AUTO_DELETE_KEEP_DEFAULT_VALUE,
comment: 'comment',
config_id: 'c1',
hosts_ordering: HOSTS_ORDERING_RANDOM,
id: 'task1',
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: OPENVAS_DEFAULT_SCANNER_ID,
scanner_type: OPENVAS_SCANNER_TYPE,
schedule_id: 's1',
schedule_periods: 1,
source_iface: 'eth0',
target_id: 't1',
})
.then(resp => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
'alert_ids:': ['a1', 'a2'],
alterable: 0,
apply_overrides: 0,
auto_delete: AUTO_DELETE_KEEP,
auto_delete_data: AUTO_DELETE_KEEP_DEFAULT_VALUE,
cmd: 'save_task',
comment: 'comment',
config_id: 'c1',
hosts_ordering: HOSTS_ORDERING_RANDOM,
in_assets: 0,
max_checks: 10,
max_hosts: 10,
min_qod: 70,
name: 'foo',
scanner_id: OPENVAS_DEFAULT_SCANNER_ID,
scanner_type: OPENVAS_SCANNER_TYPE,
schedule_id: 's1',
schedule_periods: 1,
source_iface: 'eth0',
task_id: 'task1',
target_id: 't1',
},
});

const {data} = resp;
expect(data.id).toEqual('foo');
});
});
});
Loading

0 comments on commit 731eabb

Please sign in to comment.