Skip to content

Commit 0e6b2c4

Browse files
authored
test bouncer registration with tls (#75)
1 parent 236a06b commit 0e6b2c4

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/coreos/go-systemd/v22 v22.5.0
77
github.com/crowdsecurity/crowdsec v1.5.2
8-
github.com/crowdsecurity/go-cs-bouncer v0.0.5
8+
github.com/crowdsecurity/go-cs-bouncer v0.0.6
99
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788
1010
github.com/prometheus/client_golang v1.15.1
1111
github.com/sirupsen/logrus v1.9.2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
1515
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1616
github.com/crowdsecurity/crowdsec v1.5.2 h1:2wl5ULsZlD8Du9PGe415x1fYRcOfVx95KI2Si0Qeb98=
1717
github.com/crowdsecurity/crowdsec v1.5.2/go.mod h1:R1wnz8wqV4r1teYt9Yc5PVTaBb37ug2yqCffIvXEuRw=
18-
github.com/crowdsecurity/go-cs-bouncer v0.0.5 h1:vZ989qKUDTavycjGLjqm2M6UzXJpmLaq35UoaiF9474=
19-
github.com/crowdsecurity/go-cs-bouncer v0.0.5/go.mod h1:ShrcSSYmzBTKnpqON9/UFvorDMhhn5mbeQC2HXCv7kE=
18+
github.com/crowdsecurity/go-cs-bouncer v0.0.6 h1:vzHMPBVcAKH77P/93Q69pTQgYbwBJEMnrg6BxtOaM6c=
19+
github.com/crowdsecurity/go-cs-bouncer v0.0.6/go.mod h1:ShrcSSYmzBTKnpqON9/UFvorDMhhn5mbeQC2HXCv7kE=
2020
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788 h1:1tjqkYUmbkbYqa21kZsgSWaPIwGyUW0xE/sbb1zpJHg=
2121
github.com/crowdsecurity/go-cs-lib v0.0.0-20230522124854-671e895fa788/go.mod h1:9JJLSpGj1ZXnROV3xAcJvS/HTaUvuA8K3gGOpO4tfVc=
2222
github.com/crowdsecurity/grokky v0.2.1 h1:t4VYnDlAd0RjDM2SlILalbwfCrQxtJSMGdQOR0zwkE4=

test/bouncer/test_custom_bouncer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_bad_api_key(crowdsec, bouncer, cb_stream_cfg_factory):
6262
assert not cb.proc.is_running()
6363

6464

65-
def test_good_api_key(crowdsec, bouncer, cb_stream_cfg_factory, api_key_factory):
65+
def test_good_api_key(crowdsec, bouncer, cb_stream_cfg_factory, api_key_factory, bouncer_under_test):
6666
api_key = api_key_factory()
6767
env = {
6868
'BOUNCER_KEY_custom': api_key,
@@ -89,6 +89,8 @@ def test_good_api_key(crowdsec, bouncer, cb_stream_cfg_factory, api_key_factory)
8989
bouncers = json.loads(res.output)
9090
assert len(bouncers) == 1
9191
assert bouncers[0]['name'] == 'custom'
92+
assert bouncers[0]['auth_type'] == 'api-key'
93+
assert bouncers[0]['type'] == bouncer_under_test
9294

9395
# check that the bouncer can successfully connect
9496
# and receive decisions

test/bouncer/test_tls.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12

23
def test_tls_server(crowdsec, certs_dir, api_key_factory, bouncer, cb_stream_cfg_factory):
34
"""TLS with server-only certificate"""
@@ -48,7 +49,7 @@ def test_tls_server(crowdsec, certs_dir, api_key_factory, bouncer, cb_stream_cfg
4849
])
4950

5051

51-
def test_tls_mutual(crowdsec, certs_dir, api_key_factory, bouncer, cb_stream_cfg_factory):
52+
def test_tls_mutual(crowdsec, certs_dir, api_key_factory, bouncer, cb_stream_cfg_factory, bouncer_under_test):
5253
"""TLS with two-way bouncer/lapi authentication"""
5354

5455
lapi_env = {
@@ -100,3 +101,12 @@ def test_tls_mutual(crowdsec, certs_dir, api_key_factory, bouncer, cb_stream_cfg
100101
"*deleting 0 decisions*",
101102
"*adding 0 decisions*",
102103
])
104+
105+
# check that the bouncer is registered
106+
res = cs.cont.exec_run('cscli bouncers list -o json')
107+
assert res.exit_code == 0
108+
bouncers = json.loads(res.output)
109+
assert len(bouncers) == 1
110+
assert bouncers[0]['name'].startswith('@')
111+
assert bouncers[0]['auth_type'] == 'tls'
112+
assert bouncers[0]['type'] == bouncer_under_test

0 commit comments

Comments
 (0)