forked from prism4time/openvas-golang-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_task_test.go
119 lines (101 loc) · 2.35 KB
/
cmd_task_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package omp
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestTask(t *testing.T) {
Convey("new omp", t, func() {
omp, err := New(vasTestAddr, "admin", "securepassword41")
So(err, ShouldBeNil)
So(omp, ShouldNotBeNil)
Convey("create task", func() {
configs, err := omp.GetConfigs()
So(err, ShouldBeNil)
var targetID string
targets, err := omp.GetTargets()
So(err, ShouldBeNil)
if len(targets) == 0 {
targetID, err = omp.CreateTarget(&Target{
Name: "test target",
Hosts: []string{"localhost"},
})
So(err, ShouldBeNil)
} else {
targetID = targets[0].ID
}
creds, err := omp.GetCredentials()
So(err, ShouldBeNil)
var credID string
if len(creds) != 0 {
credID = creds[0].ID
} else {
credID, err = omp.CreateCredential(Credential{
Name: "credential test",
Login: "admin",
Password: "superpassword41",
Comment: "test login ",
})
So(err, ShouldBeNil)
}
scanners, err := omp.GetScanners()
So(err, ShouldBeNil)
var scannerID string
if len(scanners) == 0 {
scannerID, err = omp.CreateScanner(&Scanner{
Name: "Default Scanner",
Host: "localhost",
Port: "9391",
Type: "2",
}, credID)
So(err, ShouldBeNil)
} else {
scannerID = scanners[0].ID
}
configID := configs[0].ID
task := Task{
Name: "test task",
Comment: "test scan task",
Config: &Config{
ID: configID,
},
Target: &Target{
ID: targetID,
},
Scanner: &Scanner{
ID: scannerID,
},
}
taskID, err := omp.CreateTask(&task)
So(err, ShouldBeNil)
fmt.Println("task id: ", taskID)
Convey("modify task", func() {
task := Task{
ID: taskID,
Comment: "test new comment for modifying task",
}
err := omp.ModifyTask(&task)
So(err, ShouldBeNil)
})
Convey("start task", func() {
reportID, err := omp.StartTask(taskID)
So(err, ShouldBeNil)
fmt.Println("report id: ", reportID)
})
Convey("stop task", func() {
err := omp.StopTask(&task)
So(err, ShouldNotBeNil)
})
Convey("get task", func() {
// tasks
_, err := omp.GetTasks(taskID)
//TODO print the content of tasks
So(err, ShouldBeNil)
})
Convey("delete task", func() {
err := omp.DeleteTask(taskID)
So(err, ShouldBeNil)
})
})
})
}