Skip to content

Commit a91c7c3

Browse files
Fix/master/testing with the help of docker (#46)
* add docker-compose to make testing easier * update default version to 1.19.0 * minor readme update * fix 569JNRXZghiklms># * Print status indicator as Curity starts, use -f on curl instead of redirect to /dev/null, and add -f option to prove * Skip if debug symbols aren't configured because then debug log message that the test looks for won't be present * added note in readme about env variables for test Co-authored-by: Travis Spencer <[email protected]>
1 parent 13a1f59 commit a91c7c3

File tree

7 files changed

+364
-66
lines changed

7 files changed

+364
-66
lines changed

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ clean:
2020
rm -rf .build.info nginx-$(NGINX_VERSION) nginx-$(NGINX_VERSION).tar.gz* t/servroot
2121

2222
test: all
23-
PATH=$(NGINX_SRC_DIR)/objs:$$PATH prove -v t/
23+
docker-compose up -d
24+
@echo "Waiting for the Curity Identity Server to start..."
25+
@bash -c 'c=0; while [[ $$c -lt 25 && "$$(curl -fs -w ''%{http_code}'' localhost:8443)" != "404" ]]; do ((c++)); echo -n "."; sleep 1; done'
26+
PATH=$(NGINX_SRC_DIR)/objs:$$PATH prove -v -f t/
27+
docker-compose down
2428

2529
.build.info $(NGINX_SRC_DIR)/Makefile:
2630
$(error You need to run the configure script in the root of this directory before building the source)

README.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,20 @@ Pre-built binaries of this module are provided for the following versions of NGI
287287

288288
## Testing
289289

290-
To test this module, you'll need the [Test::Nginx Perl module](https://github.com/openresty/test-nginx) installed. Then, run `prove` passing in the test or test directory (`t`). This can be done automatically by running `make test`. If Curity isn't running or the `idsh` command can't be found in the system path, then the functional tests that require such a connection will be skipped. Curity should be configured with an OAuth profile that has:
290+
To test this module, you'll need the [Test::Nginx Perl module](https://github.com/openresty/test-nginx) and [docker-compose](https://docs.docker.com/compose/install/) installed.
291291

292-
* A run-time node listening on `localhost` port `8443` for HTTP (not HTTPS) traffic;
293-
* A token endpoint with a URI of `/dev/oauth/token`;
294-
* An introspection endpoint with a URI of `/introspection`;
295-
* An OAuth client named `client-one` with a secret of `0ne!Secret` and the client credential capability; and
296-
* An OAuth client named `test_gateway_client` and a secret of `Password1` with the introspection capability.
292+
To run the tests do the following:
297293

298-
Internet access to `httpbin.org` is required for the `curity.t` test suite to pass.
294+
* run `./configure`, make sure you select _No_ for Dynamic module
295+
* run `make`
296+
* Setup an `ADMIN_PASSWORD` and the `LICENSE_KEY` for the Curity Identity server that is used in tests*
297+
* run `make test`
298+
299+
This, will run `prove` passing in the test or test directory (`t`).
300+
301+
Internet access to `hub.docker.com` is required for the `curity.t` test suite to pass, if the images required are not present locally.
302+
303+
\* These variables can be set inline, in your environment or in the docker-compose.yaml file.
299304

300305
NGINX must be in the system path; the tests will run the first `nginx` command that's found or bail if none is located. Also, the tests assume that the module is statically linked with NGINX. Before running them, be sure that the module is linked into the NGINX binary. Also, debug logging must be compiled into NGINX for some tests in `config.t` to pass. (This is the case if `nginx -V` includes `--with-debug` in the output.)
301306

configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
SRC_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
6-
NGINX_VERSION=${NGINX_VERSION:-1.15.2}
6+
NGINX_VERSION=${NGINX_VERSION:-1.19.0}
77
BUILD_INFO_FILE="$SRC_DIR/.build.info"; test -f "$BUILD_INFO_FILE" && . "$BUILD_INFO_FILE"
88
declare -a CONFIG_OPTS=($CONFIG_OPTS --with-compat --with-cc-opt="-Wformat -Werror=format-security")
99

curity-test-config.xml

+290
Large diffs are not rendered by default.

docker-compose.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: '3.2'
2+
services:
3+
curity-service:
4+
image: curity/idsvr
5+
ports:
6+
- 6749:6749
7+
- 8443:8443
8+
environment:
9+
- ADMIN=true
10+
- SERVICE_ROLE=default
11+
- LICENSE_KEY=${LICENSE_KEY:?err}
12+
- ADMIN_PASSWORD=${ADMIN_PASSWORD:?err}
13+
volumes:
14+
- ./curity-test-config.xml:/opt/idsvr/etc/init/curity-test-config.xml
15+
16+
httpbin-service:
17+
image: kennethreitz/httpbin
18+
ports:
19+
- 8080:80

t/config.t

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/perl
22

3+
use FindBin;
34
use Test::Nginx::Socket 'no_plan';
45
run_tests();
56

@@ -84,6 +85,8 @@ GET /t
8485
--- error_log
8586
Module disabled
8687
88+
--- skip_eval: 1: open(FH, "<", "$FindBin::Bin/../.build.info"); my $skip=0; while (<FH>) { $skip = 1 if ($_ =~ /DEBUG=n/) } $skip
89+
8790
=== TEST 6: HTTP level config is overridden by location directive
8891
8992
--- http_config

t/curity.t

+34-57
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,24 @@ use lib "$FindBin::Bin/lib";
77
use Test::Nginx::Socket 'no_plan';
88

99
SKIP: {
10-
my $exit_code = 0;
10+
our $token = &get_token_from_idsvr();
1111

12-
eval {
13-
my $message = <<'EOF';
14-
configure
15-
commit
16-
17-
# Switch test server to HTTP
18-
set environments environment services service TestServer1 protocol http
19-
20-
EOF
21-
22-
$exit_code = system("echo '$message' | idsh -s");
23-
};
24-
25-
if ($@ or $exit_code != 0) {
26-
skip("could not configure idsvr; server probably isn't running or idsh isn't in path");
27-
}
28-
else {
29-
our $token = &get_token_from_idsvr();
30-
31-
if ($token) {
32-
run_tests();
33-
}
34-
else {
35-
fail("Could not get token from idsvr");
36-
}
37-
38-
# Revert the config changes
39-
system("echo 'configure\nrollback 0\ncommit\n' | idsh -s");
40-
}
12+
if ($token) {
13+
run_tests();
14+
}
15+
else {
16+
fail("Could not get token from idsvr");
17+
}
4118
}
4219

4320
sub get_token_from_idsvr {
4421
use LWP::UserAgent;
4522

4623
my $ua = LWP::UserAgent->new();
4724

48-
my $response = $ua->post("http://localhost:8443/dev/oauth/token", {
49-
"client_id" => "client-one",
50-
"client_secret" => "0ne!Secret",
25+
my $response = $ua->post("http://localhost:8443/oauth/v2/oauth-token", {
26+
"client_id" => "test-client",
27+
"client_secret" => "secret1",
5128
"grant_type" => "client_credentials"
5229
});
5330
my $content = $response->decoded_content();
@@ -76,14 +53,14 @@ __DATA__
7653
7754
--- config
7855
location tt {
79-
proxy_pass "http://localhost:8443/introspection";
56+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
8057
}
8158
8259
location /t {
83-
proxy_pass "http://httpbin.org/get";
60+
proxy_pass "http://localhost:8080/anything";
8461
8562
phantom_token on;
86-
phantom_token_client_credential "test_gateway_client" "Password1";
63+
phantom_token_client_credential "test-nginx" "secret2";
8764
phantom_token_introspection_endpoint tt;
8865
}
8966
@@ -104,14 +81,14 @@ main::process_json_from_backend()
10481
10582
--- config
10683
location tt {
107-
proxy_pass "http://localhost:8443/introspection";
84+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
10885
}
10986
11087
location /t {
111-
proxy_pass "http://httpbin.org/get";
88+
proxy_pass "http://localhost:8080/anything";
11289
11390
phantom_token on;
114-
phantom_token_client_credential "test_gateway_client" "Password1";
91+
phantom_token_client_credential "test-nginx" "secret2";
11592
phantom_token_introspection_endpoint tt;
11693
}
11794
@@ -127,14 +104,14 @@ GET /t
127104
128105
--- config
129106
location tt {
130-
proxy_pass "http://localhost:8443/introspection";
107+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
131108
}
132109
133110
location /t {
134-
proxy_pass "http://httpbin.org/get";
111+
proxy_pass "http://localhost:8080/anything";
135112
136113
phantom_token on;
137-
phantom_token_client_credential "test_gateway_client" "Password1";
114+
phantom_token_client_credential "test-nginx" "secret2";
138115
phantom_token_introspection_endpoint tt;
139116
}
140117
@@ -150,14 +127,14 @@ GET /t
150127
151128
--- config
152129
location tt {
153-
proxy_pass "http://localhost:8443/introspection";
130+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
154131
}
155132
156133
location /t {
157-
proxy_pass "http://httpbin.org/get";
134+
proxy_pass "http://localhost:8080/anything";
158135
159136
phantom_token on;
160-
phantom_token_client_credential "test_gateway_client" "Password1";
137+
phantom_token_client_credential "test-nginx" "secret2";
161138
phantom_token_introspection_endpoint tt;
162139
}
163140
@@ -170,14 +147,14 @@ GET /t
170147
171148
--- config
172149
location tt {
173-
proxy_pass "http://localhost:8443/introspection";
150+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
174151
}
175152
176153
location /t {
177-
proxy_pass "http://httpbin.org/get";
154+
proxy_pass "http://localhost:8080/anything";
178155
179156
phantom_token on;
180-
phantom_token_client_credential "test_gateway_client" "Password1";
157+
phantom_token_client_credential "test-nginx" "secret2";
181158
phantom_token_introspection_endpoint tt;
182159
}
183160
@@ -193,14 +170,14 @@ GET /t
193170
194171
--- config
195172
location tt {
196-
proxy_pass "http://localhost:8443/introspection";
173+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
197174
}
198175
199176
location /t {
200-
proxy_pass "http://httpbin.org/get";
177+
proxy_pass "http://localhost:8080/anything";
201178
202179
phantom_token on;
203-
phantom_token_client_credential "test_gateway_client" "Password1";
180+
phantom_token_client_credential "test-nginx" "secret2";
204181
phantom_token_introspection_endpoint tt;
205182
}
206183
@@ -221,14 +198,14 @@ main::process_json_from_backend()
221198
222199
--- config
223200
location tt {
224-
proxy_pass "http://localhost:8443/introspection";
201+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
225202
}
226203
227204
location /t {
228-
proxy_pass "http://httpbin.org/get";
205+
proxy_pass "http://localhost:8080/anything";
229206
230207
phantom_token on;
231-
phantom_token_client_credential "test_gateway_client" "Password1";
208+
phantom_token_client_credential "test-nginx" "secret2";
232209
phantom_token_introspection_endpoint tt;
233210
}
234211
@@ -249,14 +226,14 @@ main::process_json_from_backend()
249226
250227
--- config
251228
location tt {
252-
proxy_pass "http://localhost:8443/introspection";
229+
proxy_pass "http://localhost:8443/oauth/v2/oauth-introspect";
253230
}
254231
255232
location /t {
256-
proxy_pass "http://httpbin.org/get";
233+
proxy_pass "http://localhost:8080/anything";
257234
258235
phantom_token on;
259-
phantom_token_client_credential "test_gateway_client" "Password1";
236+
phantom_token_client_credential "test-nginx" "secret2";
260237
phantom_token_introspection_endpoint tt;
261238
}
262239

0 commit comments

Comments
 (0)