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:
|
with:
|
||||||
go-version: 1.20.0
|
go-version: 1.20.0
|
||||||
|
|
||||||
- name: Dependences
|
- name: Dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|
||||||
- name: Vet
|
- name: Vet
|
||||||
@ -33,17 +33,13 @@ jobs:
|
|||||||
go test ./... -v -coverprofile coverage.tmp.out -covermode count
|
go test ./... -v -coverprofile coverage.tmp.out -covermode count
|
||||||
go tool cover -func coverage.tmp.out
|
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
|
- name: Quality Gate - Test coverage shall be above threshold
|
||||||
env:
|
env:
|
||||||
TESTCOVERAGE_THRESHOLD: 70
|
TESTCOVERAGE_THRESHOLD: 70
|
||||||
run: |
|
run: |
|
||||||
echo "Quality Gate: checking test coverage is above threshold ..."
|
echo "Quality Gate: checking test coverage is above threshold ..."
|
||||||
echo "Threshold : $TESTCOVERAGE_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
|
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]+'`
|
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
|
||||||
echo "Current test coverage : $totalCoverage %"
|
echo "Current test coverage : $totalCoverage %"
|
||||||
@ -54,3 +50,26 @@ jobs:
|
|||||||
echo "Failed"
|
echo "Failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
logs
|
logs
|
||||||
|
.vscode
|
6
Makefile
6
Makefile
@ -17,6 +17,12 @@ test.unit:
|
|||||||
test.unit.verbose:
|
test.unit.verbose:
|
||||||
go test ./... -v
|
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:
|
test.integration:
|
||||||
INTEGRATION=1 go test ./...
|
INTEGRATION=1 go test ./...
|
||||||
|
|
||||||
|
@ -5,5 +5,5 @@ core:
|
|||||||
logDisableTimestamp: true
|
logDisableTimestamp: true
|
||||||
logsPath: ./logs
|
logsPath: ./logs
|
||||||
tracing:
|
tracing:
|
||||||
rabbitMQEnabled: false
|
rabbitMQEnabled: true
|
||||||
rabbitMQURI: ""
|
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 (
|
import (
|
||||||
"beelzebub/builder"
|
"beelzebub/builder"
|
||||||
"beelzebub/parser"
|
"beelzebub/parser"
|
||||||
"github.com/go-resty/resty/v2"
|
"beelzebub/tracer"
|
||||||
"github.com/melbahja/goph"
|
"encoding/json"
|
||||||
"github.com/stretchr/testify/suite"
|
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"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 {
|
type IntegrationTestSuite struct {
|
||||||
@ -19,6 +23,7 @@ type IntegrationTestSuite struct {
|
|||||||
httpHoneypotHost string
|
httpHoneypotHost string
|
||||||
tcpHoneypotHost string
|
tcpHoneypotHost string
|
||||||
sshHoneypotHost string
|
sshHoneypotHost string
|
||||||
|
rabbitMQURI string
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIntegrationTestSuite(t *testing.T) {
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
@ -41,6 +46,7 @@ func (suite *IntegrationTestSuite) SetupSuite() {
|
|||||||
|
|
||||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
suite.rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
||||||
|
|
||||||
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
@ -108,7 +114,35 @@ func (suite *IntegrationTestSuite) TestInvokeSSHHoneypot() {
|
|||||||
suite.Equal("root@ubuntu:~$ ", string(out))
|
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() {
|
func (suite *IntegrationTestSuite) TestShutdownBeelzebub() {
|
||||||
suite.Require().NoError(suite.beelzebubBuilder.Close())
|
suite.Require().NoError(suite.beelzebubBuilder.Close())
|
||||||
|
Reference in New Issue
Block a user