mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
test: add rabbitMQ integration test (#29)
* added integration test dependencies * added rabbitMQ use case integration test * configured rabbitMQ integration test URI * fix typo, configured integration test pipeline
This commit is contained in:
31
.github/workflows/ci.yml
vendored
31
.github/workflows/ci.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
||||
with:
|
||||
go-version: 1.20.0
|
||||
|
||||
- name: Dependences
|
||||
- name: Dependencies
|
||||
run: go mod download
|
||||
|
||||
- name: Vet
|
||||
@ -33,17 +33,13 @@ jobs:
|
||||
go test ./... -v -coverprofile coverage.tmp.out -covermode count
|
||||
go tool cover -func coverage.tmp.out
|
||||
|
||||
- name: Integration tests
|
||||
run: |
|
||||
INTEGRATION=1 go test ./... -v
|
||||
|
||||
- name: Quality Gate - Test coverage shall be above threshold
|
||||
env:
|
||||
TESTCOVERAGE_THRESHOLD: 70
|
||||
run: |
|
||||
echo "Quality Gate: checking test coverage is above threshold ..."
|
||||
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
|
||||
# Excluded the concrete strategy from the coverage calculation, this will be tested in the integration tests
|
||||
# Excluded the concrete strategy from the coverage calculation, because tested by integration tests
|
||||
cat coverage.tmp.out | grep -v "secureShellStrategy.go" | grep -v "hypertextTransferProtocolStrategy.go" | grep -v "transmissionControlProtocolStrategy.go" > coverage.out
|
||||
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
|
||||
echo "Current test coverage : $totalCoverage %"
|
||||
@ -54,3 +50,26 @@ jobs:
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Start integration test dependencies
|
||||
run: |
|
||||
make test.dependencies.start
|
||||
|
||||
- name: Wait for RabbitMQ to be ready
|
||||
run: |
|
||||
sleep 2
|
||||
count=0
|
||||
until docker exec rabbitmq rabbitmqctl list_queues > /dev/null 2>&1; do
|
||||
count=$((count+1))
|
||||
if [ $count -gt 10 ]; then
|
||||
echo "RabbitMQ did not start within the specified time"
|
||||
exit 1
|
||||
fi
|
||||
echo "Waiting for RabbitMQ to start..."
|
||||
sleep 5
|
||||
done
|
||||
|
||||
- name: Integration tests
|
||||
run: |
|
||||
make test.integration.verbose
|
||||
make test.dependencies.down
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.DS_Store
|
||||
.idea
|
||||
logs
|
||||
logs
|
||||
.vscode
|
6
Makefile
6
Makefile
@ -17,6 +17,12 @@ test.unit:
|
||||
test.unit.verbose:
|
||||
go test ./... -v
|
||||
|
||||
test.dependencies.start:
|
||||
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml up -d
|
||||
|
||||
test.dependencies.down:
|
||||
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml down
|
||||
|
||||
test.integration:
|
||||
INTEGRATION=1 go test ./...
|
||||
|
||||
|
@ -5,5 +5,5 @@ core:
|
||||
logDisableTimestamp: true
|
||||
logsPath: ./logs
|
||||
tracing:
|
||||
rabbitMQEnabled: false
|
||||
rabbitMQURI: ""
|
||||
rabbitMQEnabled: true
|
||||
rabbitMQURI: "amqp://integration:integration@localhost:5672/"
|
||||
|
10
integration_test/docker-compose.yml
Normal file
10
integration_test/docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
rabbitmq:
|
||||
image: rabbitmq:3-alpine
|
||||
container_name: 'rabbitmq'
|
||||
ports:
|
||||
- 5672:5672
|
||||
environment:
|
||||
- RABBITMQ_DEFAULT_USER=integration
|
||||
- RABBITMQ_DEFAULT_PASS=integration
|
@ -3,14 +3,18 @@ package integration
|
||||
import (
|
||||
"beelzebub/builder"
|
||||
"beelzebub/parser"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/melbahja/goph"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"beelzebub/tracer"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/melbahja/goph"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
@ -19,6 +23,7 @@ type IntegrationTestSuite struct {
|
||||
httpHoneypotHost string
|
||||
tcpHoneypotHost string
|
||||
sshHoneypotHost string
|
||||
rabbitMQURI string
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
@ -41,6 +46,7 @@ func (suite *IntegrationTestSuite) SetupSuite() {
|
||||
|
||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||
suite.Require().NoError(err)
|
||||
suite.rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
||||
|
||||
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
||||
suite.Require().NoError(err)
|
||||
@ -108,7 +114,35 @@ func (suite *IntegrationTestSuite) TestInvokeSSHHoneypot() {
|
||||
suite.Equal("root@ubuntu:~$ ", string(out))
|
||||
}
|
||||
|
||||
//TODO test rabbitmq
|
||||
func (suite *IntegrationTestSuite) TestRabbitMQ() {
|
||||
conn, err := amqp.Dial(suite.rabbitMQURI)
|
||||
suite.Require().NoError(err)
|
||||
defer conn.Close()
|
||||
|
||||
ch, err := conn.Channel()
|
||||
suite.Require().NoError(err)
|
||||
defer ch.Close()
|
||||
|
||||
msgs, err := ch.Consume("event", "", true, false, false, false, nil)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
//Invoke HTTP Honeypot
|
||||
response, err := resty.New().R().Get(suite.httpHoneypotHost + "/index.php")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
|
||||
for msg := range msgs {
|
||||
var event tracer.Event
|
||||
err := json.Unmarshal(msg.Body, &event)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("GET", event.HTTPMethod)
|
||||
suite.Equal("/index.php", event.RequestURI)
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestShutdownBeelzebub() {
|
||||
suite.Require().NoError(suite.beelzebubBuilder.Close())
|
||||
|
Reference in New Issue
Block a user