Skip to content

Commit

Permalink
Fix workflow. Cleanup. Add license headers. Also, update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Sep 8, 2023
1 parent 6e41a33 commit 75e3cfb
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/helm-build-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ on:
branches: [main]
workflow_dispatch:

env:
API_KEY: changeme
OPENVASD: 127.0.0.1:8080

jobs:
openvasd:
runs-on: ubuntu-latest
Expand All @@ -35,6 +31,10 @@ jobs:
kubectl --namespace default port-forward ${{ steps.smoketest.outputs.POD_NAME }} 8080:3000 &
- name: smoketest
working-directory: rust/smoketest
env:
API_KEY: changeme
OPENVASD: http://127.0.0.1:8080
SCAN_CONFIG: simple_scan_ssh_only.json
run: |
make build run
- uses: greenbone/actions/helm-build-push@v3
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/rustification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
- uses: actions/checkout@v4
- run: sudo apt update && sudo apt-get install -y libpcap-dev
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} || rustup default ${{ matrix.toolchain }}
- run: cargo test
# Run unittests and integration test, but excludes the smoketest since it depends on a running openvasd server.
- run: cargo test --lib --tests --workspace --exclude smoketest
clippy:
runs-on: ubuntu-latest
defaults:
Expand Down
6 changes: 1 addition & 5 deletions rust/models/src/host_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub struct HostInfo {
pub queued: u32,
/// Number of hosts, that are already finished scanning
pub finished: u32,
#[cfg_attr(
feature = "serde_support",
serde(skip_serializing_if = "Option::is_none")
)]
/// IPs of hosts, that are currently scanned.
pub scanning: Option<Vec<String>>,
pub scanning: Vec<String>,
}
2 changes: 1 addition & 1 deletion rust/osp/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl From<Scan> for models::Status {
- i.count_alive.content.0
- i.host.len() as u32,
finished: i.count_alive.content.0,
scanning: Some(scanning),
scanning,
}),
}
}
Expand Down
3 changes: 2 additions & 1 deletion rust/smoketest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ All settings for running the smoke-tests are set via environmental variables. Th
|TARGET_USERNAME|Username for login in the target during the authenticated scan|empty string|no|Necessary for authenticated scans|
|TARGET_PASSWORD|Password for login in the target during the authenticated scan|empty string|no|Necessary for authenticated scans|
|API_KEY|API Key for authenticated communication with `openvasd`|mtls_is_preferred|yes||
|OPENVASD|Socket where openvasd listen on|127.0.0.1:3000|no|Must be specified with port|
|OPENVASD|Socket where openvasd listen on|http://127.0.0.1:3000|no|Must be specified with port|
|CLIENT_CERT|PEM file combinating public certificate and any 3rd party intermediate certificates ||yes for mTLS|Necessary for mTLS enabled|
|CLIENT_KEY|Client private key||yes for mTLS|Necessary for mTLS enabled|
|SCAN_CONFIG|Scan config in json file format to be run against the target|simple_scan_ssh_only.json|yes||


## Usage
Expand Down
4 changes: 4 additions & 0 deletions rust/smoketest/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2023 Greenbone AG
//
// SPDX-License-Identifier: AGPL-3.0-or-later

use std::env;

#[derive(Debug)]
Expand Down
20 changes: 12 additions & 8 deletions rust/smoketest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2023 Greenbone AG
//
// SPDX-License-Identifier: AGPL-3.0-or-later

pub mod config;
use models::{Phase, Result as ScanResult, Status};
use reqwest::header;
Expand Down Expand Up @@ -74,12 +78,12 @@ pub async fn create_scan(
pub async fn scan_action(
cli: &reqwest::Client,
server: &String,
id: &String,
id: &str,
action: String,
) -> bool {
let mut path = String::from(server);
path.push_str("/scans/");
path.push_str(id.as_str());
path.push_str(id);

let mut data = HashMap::new();
data.insert("action", action.as_str());
Expand All @@ -95,10 +99,10 @@ pub async fn scan_action(
}

/// Given an ScanID, it fetches the current scan status.
pub async fn scan_status(cli: &reqwest::Client, server: &String, id: &String) -> Option<Phase> {
pub async fn scan_status(cli: &reqwest::Client, server: &String, id: &str) -> Option<Phase> {
let mut path = String::from(server);
path.push_str("/scans/");
path.push_str(id.as_str());
path.push_str(id);
path.push_str("/status");

let res = cli.get(path).send().await.unwrap();
Expand Down Expand Up @@ -127,11 +131,11 @@ pub async fn scan_status(cli: &reqwest::Client, server: &String, id: &String) ->
pub async fn scan_results(
cli: &reqwest::Client,
server: &String,
id: &String,
id: &str,
) -> Option<Vec<ScanResult>> {
let mut path = String::from(server);
path.push_str("/scans/");
path.push_str(id.as_str());
path.push_str(id);
path.push_str("/results");

let res = cli.get(path).send().await.unwrap();
Expand All @@ -156,10 +160,10 @@ pub async fn scan_results(
None
}

pub async fn delete_scan(cli: &reqwest::Client, server: &String, id: &String) -> bool {
pub async fn delete_scan(cli: &reqwest::Client, server: &String, id: &str) -> bool {
let mut path = String::from(server);
path.push_str("/scans/");
path.push_str(id.as_str());
path.push_str(id);

let res = cli.delete(path).send().await.unwrap();

Expand Down
2 changes: 0 additions & 2 deletions rust/smoketest/src/tests/mod.rs

This file was deleted.

Empty file removed rust/smoketest/src/tests/mods.rs
Empty file.
18 changes: 0 additions & 18 deletions rust/smoketest/src/tests/test1.rs

This file was deleted.

46 changes: 0 additions & 46 deletions rust/smoketest/src/tests/test2.rs

This file was deleted.

10 changes: 6 additions & 4 deletions rust/smoketest/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2023 Greenbone AG
//
// SPDX-License-Identifier: AGPL-3.0-or-later

pub mod tests {
use models::Phase;
use smoketest::*;
Expand Down Expand Up @@ -42,7 +46,6 @@ pub mod tests {
loop {
match scan_status(&cli, args.openvasd(), &id).await {
Some(Phase::Succeeded) => {
tracing::info!("\tRun scan succeeded OK");
if let Some(results) = scan_results(&cli, args.openvasd(), &id).await {
assert_eq!(results.is_empty(), false)
}
Expand All @@ -54,8 +57,8 @@ pub mod tests {
success = false;
break;
}
_ => {
std::thread::sleep(std::time::Duration::from_secs(10));
Some(_) => {
std::thread::sleep(std::time::Duration::from_secs(1));
counter += 1;
assert!(counter <= 360);
}
Expand All @@ -64,5 +67,4 @@ pub mod tests {
}
assert!(success)
}

}

0 comments on commit 75e3cfb

Please sign in to comment.