File tree Expand file tree Collapse file tree 5 files changed +37
-2
lines changed Expand file tree Collapse file tree 5 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,11 @@ RUN set -x \
8
8
&& apt-get install -y --no-install-suggests \
9
9
libluajit-5.1-dev libpam0g-dev zlib1g-dev libpcre3-dev libpcre2-dev \
10
10
libexpat1-dev git curl build-essential lsb-release libxml2 libxslt1.1 libxslt1-dev autoconf libtool libssl-dev \
11
- unzip libmaxminddb-dev libbrotli-dev
11
+ unzip libmaxminddb-dev libbrotli-dev cmake pkg-config libjansson-dev
12
+
13
+ RUN git clone --depth 1 --branch v3.2.0 https://github.com/benmcollins/libjwt.git && \
14
+ mkdir libjwt/build && \
15
+ cd libjwt/build && cmake .. && make && make install
12
16
13
17
ARG openresty_package_version=1.27.1.1-1~bookworm1
14
18
RUN set -x \
@@ -86,6 +90,8 @@ COPY --from=build /usr/local/lib /usr/local/lib
86
90
COPY --from=build /usr/local/etc /usr/local/etc
87
91
COPY --from=build /usr/local/share /usr/local/share
88
92
COPY --from=build /usr/lib/nginx/modules /usr/lib/nginx/modules
93
+ COPY --from=build /usr/local/lib/libjwt.so /usr/local/lib/libjwt.so
94
+
89
95
90
96
ENV LUAJIT_LIB=/usr/local/lib \
91
97
LUAJIT_INC=/usr/local/include/luajit-2.1
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ test: check-required-vars
38
38
39
39
$(DOCKER) cp ./test/nginx-$(flavor).conf test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx/
40
40
$(DOCKER) cp ./test/nginx-$(flavor).bash test-tsuru-nginx-$(flavor)-$(nginx_version):/bin/test-nginx
41
+ $(DOCKER) cp ./test/jwks.json test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx/
41
42
42
43
$(DOCKER) cp $$PWD/test/GeoIP2-Country-Test.mmdb test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx; \
43
44
Original file line number Diff line number Diff line change 21
21
" tsuru-rpaasv2 INOTIFY_INCDIR=/usr/include/linux-gnu" ,
22
22
" lua-resty-http 0.17.2-0" ,
23
23
" lua-resty-balancer 0.04" ,
24
- " lua-resty-cookie 0.4.0-1"
24
+ " lua-resty-cookie 0.4.0-1" ,
25
+ " lua-resty-libjwt 0.1.0-1"
25
26
]
26
27
},
27
28
{
Original file line number Diff line number Diff line change @@ -37,11 +37,23 @@ test_brotli() {
37
37
assert ' BQmAPGI+QnJvdGxpIHBhZ2U8L2I+CgM=' " $response " " /brotli with brotli compression response"
38
38
}
39
39
40
+ test_libjwt_no_token () {
41
+ response=$( curl --silent --show-error http://localhost:8080/libjwt)
42
+ assert ' {"message":"token not found"}' " $response " " /libjwt with expected response"
43
+ }
44
+
45
+ test_libjwt_with_token () {
46
+ response=$( curl --fail --silent --show-error http://localhost:8080/libjwt -H " Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImtpZC10c3VydSIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6dHJ1ZSwiZW1haWwiOiJ0c3VydUB0c3VydS5jb20iLCJleHAiOjIwNTY5OTA3ODEsImlhdCI6MTc0MTYzMDc4MSwibmFtZSI6IlRzdXJ1Iiwic3ViIjoiMTIzNDU2Nzg5MCJ9.osEVAXF1ysV3pwoeOwaPSZK97AzMDMqCD-cyZ4ALHhLatBHszXrPqn6sJxUQdvET_RK0IJyJd15mw-Y1EMZ6WLKBjeV_iWuapQ9-7gh6sQoloZZ0V0ZNfXlbqCGoTXHb-xInFsGEgV6rj4R-5Sl1r96UiYpLdav8GmT3lKrRPILCLvihXFtiuhrUX1rmNhbiKqlIDyAPtG8rjqQzqEDqKkYH2bApjSrgsyevG9do31vbnEljukON-Hc5MgQK7zr4ZF3Ozi4m0JRy3jeIWVzpsWm9dRnTb9mcOfuY5EQP7NhFBXu-H4H-RwvStfZhfN8J9FbOR8jGEEDhUYHsLaRXNQ" )
47
+ assert ' OK' " $response " " /libjwt with expected response"
48
+ }
49
+
40
50
echo " Running tests"
41
51
42
52
test_nginx_serving_request
43
53
test_lua_content
44
54
test_lua_http_resty
45
55
test_brotli
56
+ test_libjwt_with_token
57
+ test_libjwt_no_token
46
58
47
59
echo " ✅ SUCESS: All tests passed"
Original file line number Diff line number Diff line change @@ -79,6 +79,21 @@ http {
79
79
}
80
80
}
81
81
82
+ location /libjwt {
83
+ content_by_lua_block {
84
+ local libjwt = require("resty.libjwt")
85
+ local claim, err = libjwt.validate({
86
+ ["jwks_files"] = {"/etc/nginx/jwks.json"},
87
+ })
88
+ if claim then
89
+ ngx.status = ngx.HTTP_OK
90
+ return ngx.say("OK")
91
+ end
92
+ ngx.status = ngx.HTTP_UNAUTHORIZED
93
+ return ngx.say("Unauthorized")
94
+ }
95
+ }
96
+
82
97
location /brotli {
83
98
brotli on;
84
99
default_type 'text/html';
You can’t perform that action at this time.
0 commit comments