Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1f10509
works for amqp
phillip-stephens Feb 4, 2025
9aaa400
updated makefile to use docker compose
phillip-stephens Feb 4, 2025
7aa902c
make clean now tears everything down
phillip-stephens Feb 4, 2025
2918f3d
ipp and http working
phillip-stephens Feb 5, 2025
6c7ae0c
ntp and pop
phillip-stephens Feb 6, 2025
fe3dea7
postgres
phillip-stephens Feb 6, 2025
87b1864
tests run and python script works
phillip-stephens Feb 6, 2025
86cf202
Use python instead of shell test script and fail a test immediately i…
phillip-stephens Feb 6, 2025
a159866
cleanup unused setup/cleanup scripts
phillip-stephens Feb 7, 2025
631b4cb
build runner and service_base in parallel
phillip-stephens Feb 7, 2025
6d6c9ab
make integration tests manually triggerable
phillip-stephens Feb 7, 2025
925e139
remove comment
phillip-stephens Feb 7, 2025
0e32586
integration test manual run
phillip-stephens Feb 7, 2025
daf52ba
fix caps
phillip-stephens Feb 7, 2025
fc20f3b
push an intermediate build image so ipp builds faster
phillip-stephens Feb 7, 2025
ecaf892
allow user to select a subset of modules to test
phillip-stephens Feb 7, 2025
2cba478
Allow user to select only a few test modules
phillip-stephens Feb 7, 2025
ae54823
update testing README
phillip-stephens Feb 7, 2025
e032cb9
remove extraneous scripts
phillip-stephens Feb 7, 2025
376ac60
Revert "push an intermediate build image so ipp builds faster"
phillip-stephens Feb 7, 2025
915188a
comment makefile and remove Python2 instructions in README
phillip-stephens Feb 7, 2025
42cb2b5
Merge branch 'master' into feature/test-automation-improvements
phillip-stephens Feb 7, 2025
6a80219
handle todo and typo fix
phillip-stephens Feb 7, 2025
f6cc8e3
test.py cleanup
phillip-stephens Feb 7, 2025
770b29b
Merge branch 'feature/test-automation-improvements' of github.com:phi…
phillip-stephens Feb 7, 2025
36655df
docker-compose cleanup
phillip-stephens Feb 7, 2025
766127e
add black to make lint
phillip-stephens Feb 7, 2025
e049d40
lint python
phillip-stephens Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
go-test:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Build image ##
ARG GO_VERSION=1.23
FROM golang:${GO_VERSION}-alpine3.21 as build
FROM golang:${GO_VERSION}-alpine3.21 AS build

# System dependencies
RUN apk add --no-cache make
Expand All @@ -16,7 +16,7 @@ COPY . .
RUN make all

## Runtime image ##
FROM alpine:3.21 as run
FROM alpine:3.21 AS run

COPY --from=build /usr/src/zgrab2/cmd/zgrab2/zgrab2 /usr/bin/zgrab2

Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TEST_MODULES ?=

all: zgrab2

.PHONY: all clean integration-test integration-test-clean docker-runner gofmt test
.PHONY: all clean integration-test integration-test-clean gofmt test

# Test currently only runs on the modules folder because some of the
# third-party libraries in lib (e.g. http) are failing.
Expand All @@ -19,23 +19,26 @@ test:

lint:
gofmt -s -w $(shell find . -type f -name '*.go'| grep -v "/.template/")
black .

zgrab2: $(GO_FILES)
cd cmd/zgrab2 && go build && cd ../..
rm -f zgrab2
ln -s cmd/zgrab2/zgrab2$(EXECUTABLE_EXTENSION) zgrab2

docker-runner: clean
make -C docker-runner

integration-test: docker-runner
integration-test:
rm -rf zgrab-output
TEST_MODULES=$(TEST_MODULES) ./integration_tests/test.sh
docker compose -p zgrab -f integration_tests/docker-compose.yml build --no-cache service_base # ensure the apt cache is up to date
docker compose -p zgrab -f integration_tests/docker-compose.yml build $(TEST_MODULES)
docker compose -p zgrab -f integration_tests/docker-compose.yml up -d $(TEST_MODULES)
sleep 10 # Wait for services to start
TEST_MODULES="$(TEST_MODULES)" python3 integration_tests/test.py
# Shut off the services
docker compose -p zgrab -f integration_tests/docker-compose.yml down

integration-test-clean:
rm -rf zgrab-output
./integration_tests/cleanup.sh
make -C docker-runner clean
docker compose -p zgrab -f integration_tests/docker-compose.yml down

clean:
cd cmd/zgrab2 && go clean
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,25 @@ To add a schema for the new module, add a module under schemas, and update [`zgr
See [zgrab2_schemas/README.md](zgrab2_schemas/README.md) for details.

### Integration tests
To add integration tests for the new module, run `integration_tests/new.sh [your_new_protocol_name]`.
This will add stub shell scripts in `integration_tests/your_new_protocol_name`; update these as needed.
To add integration tests for the new module, you'll need to add a test service to scan against to `integration_tests/docker-compose.yml` and a `test.sh` in a folder named after your module.
Follow the examples in `integration_tests/.template` to create the necessary files.
See [integration_tests/mysql/*](integration_tests/mysql) for an example.
The only hard requirement is that the `test.sh` script drops its output in `$ZGRAB_OUTPUT/[your-module]/*.json`, so that it can be validated against the schema.

#### How to Run Integration Tests

To run integration tests, you must have [Docker](https://www.docker.com/) and **Python 2** on host installed. Then, you can follow the following steps to run integration tests:
To run integration tests, you must have [Docker](https://www.docker.com/) and **Python 3** on host installed. Then, you can follow the following steps to run integration tests:

```shell
go get github.com/jmespath/jp && go build github.com/jmespath/jp
# or, sudo wget https://github.com/jmespath/jp/releases/download/0.2.1/jp-linux-amd64 -O /usr/local/bin/jp && sudo chmod +x /usr/local/bin/jp
pip2 install --user zschema
pip2 install --user -r requirements.txt
make integration-test
# Install Python dependencies
sudo apt update
sudo apt install -y python3 jp python3-pip
python3 -m venv venv
source venv/bin/activate
# Install Python dependencies
pip install zschema
pip install -r requirements.txt
make integration-test-clean; make integration-test
```

Running the integration tests will generate quite a bit of debug output. To ensure that tests completed successfully, you can check for a successful exit code after the tests complete:
Expand All @@ -192,6 +196,13 @@ echo $?
0
```

To just run a single/few module's integration tests, you can use the `TEST_MODULES` env. var.:

```shell
make integration-test-clean; TEST_MODULES="http" make integration-test
make integration-test-clean; TEST_MODULES="http ssh" make integration-test
```

Refer to our [Github Actions workflow](.github/workflows/integration-test.yml) for an example of how to prepare environment for integration tests.

## License
Expand Down
26 changes: 0 additions & 26 deletions docker-runner/Makefile

This file was deleted.

14 changes: 0 additions & 14 deletions docker-runner/base-apt-update.sh

This file was deleted.

2 changes: 1 addition & 1 deletion docker-runner/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
: "${CONTAINER_NAME:?}"

set -e
echo 'target' | docker run --rm -i --link $CONTAINER_NAME:target zgrab2_runner $@
echo 'target' | docker run --rm -i --network container:$CONTAINER_NAME zgrab2_runner $@
13 changes: 3 additions & 10 deletions integration_tests/.template/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
Template integration test scripts, used by `new.sh`.
Template integration test scripts

Specify your module's service in the `docker-compose.yml` file.

- All scripts start with the default `CONTAINER_NAME` variable matching
the standard format (`zgrab_<module name>`).

- `setup.sh` tries to launch the container; if it fails, then it tries
to build the docker image from the `Dockerfile` in
`integration_tests/<module_name>/container`; then it tries to launch
the container again. **This must be modified by all new modules**.

- `test.sh` runs the container using the `docker-runner.sh` script and
dumps the output in `zgrab-output/<module name>/<module_name>.json`.
Afterwards it dumps the container logs to stdout. This can be used
as-is, it only provides a single test case with no arguments.

- `cleanup.sh` runs `docker stop $CONTAINER_NAME`. This should tear
down everything started in `setup.sh`. In the case where there is
only a single container, it can be used as-is.

- `schema.py` registers the `scan_response_type` and provides a
skeleton that can be filled out. **This must be modified for all new
modules**.
Expand Down
9 changes: 0 additions & 9 deletions integration_tests/.template/cleanup.sh

This file was deleted.

25 changes: 0 additions & 25 deletions integration_tests/.template/setup.sh

This file was deleted.

15 changes: 0 additions & 15 deletions integration_tests/amqp091/cleanup.sh

This file was deleted.

37 changes: 0 additions & 37 deletions integration_tests/amqp091/setup.sh

This file was deleted.

30 changes: 0 additions & 30 deletions integration_tests/cleanup.sh

This file was deleted.

Loading