Skip to content

Commit

Permalink
Refactor: test case for add_host_name
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtsfrei committed Aug 24, 2022
1 parent 536c47b commit 0772e48
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 24 deletions.
2 changes: 1 addition & 1 deletion smoketest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MAKEFILE_PATH := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))

ALTERNATIVE_HOSTS := smoketest.localdomain smoke.localdomain and.localdomain mirrors.localdomain
ALTERNATIVE_HOSTS := smoketest.localdomain smoke.localdomain and.localdomain mirrors.localdomain addhostname.localdomain

ADD_HOST := $(addprefix --add-host ,$(addsuffix :127.0.0.1, ${ALTERNATIVE_HOSTS}))

Expand Down
45 changes: 45 additions & 0 deletions smoketest/data/plugins/add_host_name.nasl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
if(description)
{
script_oid("0.0.0.0.0.0.0.0.0.3");
script_version("2019-11-10T15:30:28+0000");
script_name("test-add-host-name");
script_category(ACT_SCANNER);
script_family("my test family");
script_tag(name:"some", value:"tag");
script_tag(name:"last_modification", value:"2019-11-10 15:30:28 +0000 (Tue, 10 Nov 2020)");
script_tag(name:"creation_date", value:"2015-03-27 12:00:00 +0100 (Fri, 27 Mar 2015)");
script_tag(name:"cvss_base", value:"0.0");
script_tag(name:"cvss_base_vector", value:"AV:N/AC:L/Au:N/C:N/I:N/A:N");
script_tag(name:"qod_type", value:"remote_app");
script_tag(name:"qod", value:"0");

script_version("2021-08-19T02:25:52+0000");
script_cve_id("CVE-0000-0000", "CVE-0000-0001");
script_tag(name:"severity_vector", value:"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H");
script_tag(name:"severity_origin", value:"NVD");
script_tag(name:"severity_date", value:"2020-08-07 19:36:00 +0000 (Fri, 07 Aug 2020)");
script_xref(name:"Example", value:"GB-Test-1");
script_xref(name:"URL", value:"https://www.greenbone.net");


script_add_preference(name:"example", type:"entry", value:"a default string value");

script_tag(name:"vuldetect", value:"Describes what this plugin is doing to detect a vulnerability.");

script_tag(name:"summary", value:"A short description of the problem");
script_tag(name:"insight", value:"Some detailed insights of the problem");
script_tag(name:"impact", value:"Some detailed about what is impacted");

script_tag(name:"affected", value:"Affected programs, operation system, ...");

script_tag(name:"solution", value:"Solution description");
script_tag(name:"solution_type", value:"Type of solution (e.g. mitigation, vendor fix)");
script_tag(name:"solution_method", value:"how to solve it (e.g. debian apt upgrade)");
script_tag(name:"qod_type", value:"package");
exit(0);
}
add_host_name(hostname: "addhostname.localdomain", source: "magic entry");
hn = get_host_name();
log_msg = hn;
log_message(data:log_msg);
exit(0);
10 changes: 10 additions & 0 deletions smoketest/scan/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ var ConsiderAlive AliveTestMethods = AliveTestMethods{
ConsiderAlive: 1,
}


var Alive = AliveTestMethods{
ICMP: 1,
TCPSYN: 1,
TCPACK: 1,
ARP: 1,
ConsiderAlive: 0,
}


type Target struct {
XMLName xml.Name `xml:"target"`
Hosts string `xml:"hosts,omitempty"`
Expand Down
72 changes: 49 additions & 23 deletions smoketest/usecases/scan/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import (
"github.com/greenbone/ospd-openvas/smoketest/usecases"
)

var DefaultTargets = scan.Targets{Targets: []scan.Target{
{
Hosts: "localhost,smoketest.localdomain,smoke.localdomain,and.localdomain,mirrors.localdomain",
Ports: "8080,443",
AliveTestMethods: scan.ConsiderAlive,
},
},
}
var DefaultTargets = Targets(scan.ConsiderAlive)

var DefaultSelection = []scan.VTSelection{
{Single: []scan.VTSingle{{
Expand All @@ -28,25 +21,57 @@ var DefaultStart = scan.Start{
VTSelection: DefaultSelection,
}

func Targets(alive scan.AliveTestMethods) scan.Targets {
return scan.Targets{Targets: []scan.Target{
{
Hosts: "localhost,smoketest.localdomain,smoke.localdomain,and.localdomain,mirrors.localdomain",
Ports: "8080,443",
AliveTestMethods: alive,
},
},
}
}

func addHostName() usecases.Test {
return usecases.Test{
Title: "Add Host Name Function",
Run: func(o connection.OSPDSender) usecases.Response {
target := Targets(scan.Alive)
slowSelection := []scan.VTSelection{
{Single: []scan.VTSingle{{
ID: "0.0.0.0.0.0.0.0.0.3",
}}},
}
startScan := scan.Start{
ScannerParams: scan.DefaultScannerParams,
Targets: target,
VTSelection: slowSelection,
}
r := usecases.StartScanGetLastStatus(startScan, o)
if r.Resp.Scan.Status != "finished" {
return *usecases.WrongScanStatus("finished", r.Resp.Scan.Status)
}
for _, result := range r.Resp.Scan.Results.Results {
if result.HostName == "addhostname.localdomain" {
return usecases.Response{
Success: true,
}
}
}
return usecases.Response{
Description: fmt.Sprintf("addhost not found in %+v", r.Resp.Scan.Results.Results),
Success: false,
}

},
}
}

func stopDeleteWhenNoResults() usecases.Test {
return usecases.Test{
Title: "When no results: Queue->Init->Running->Stop->Delete",
Run: func(co connection.OSPDSender) usecases.Response {
testeach := scan.AliveTestMethods{
ICMP: 1,
TCPSYN: 1,
TCPACK: 1,
ARP: 1,
ConsiderAlive: 0,
}
target := scan.Targets{Targets: []scan.Target{
{
Hosts: "localhost,smoketest.localdomain,smoke.localdomain,and.localdomain,mirrors.localdomain",
Ports: "8080,443",
AliveTestMethods: testeach,
},
},
}
target := Targets(scan.Alive)
slowSelection := []scan.VTSelection{
{Single: []scan.VTSingle{{
ID: "0.0.0.0.0.0.0.0.0.2",
Expand Down Expand Up @@ -192,6 +217,7 @@ func Create() usecases.Tests {
return usecases.Tests{
Title: "Scan",
UseCases: []usecases.Test{
addHostName(),
startScan(),
transitionQueueToRunning(),
stopDeleteWhenNoResults(),
Expand Down

0 comments on commit 0772e48

Please sign in to comment.