Skip to content

Commit 39ad8a4

Browse files
wpjuniorinfezek
andcommitted
Co-authored-by: Ezequiel Lopes dos Reis Junior <[email protected]>
1 parent 3835d40 commit 39ad8a4

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ RUN set -x \
88
&& apt-get install -y --no-install-suggests \
99
libluajit-5.1-dev libpam0g-dev zlib1g-dev libpcre3-dev libpcre2-dev \
1010
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
1216

1317
ARG openresty_package_version=1.27.1.1-1~bookworm1
1418
RUN set -x \
@@ -86,6 +90,8 @@ COPY --from=build /usr/local/lib /usr/local/lib
8690
COPY --from=build /usr/local/etc /usr/local/etc
8791
COPY --from=build /usr/local/share /usr/local/share
8892
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+
8995

9096
ENV LUAJIT_LIB=/usr/local/lib \
9197
LUAJIT_INC=/usr/local/include/luajit-2.1

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test: check-required-vars
3838

3939
$(DOCKER) cp ./test/nginx-$(flavor).conf test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx/
4040
$(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/
4142

4243
$(DOCKER) cp $$PWD/test/GeoIP2-Country-Test.mmdb test-tsuru-nginx-$(flavor)-$(nginx_version):/etc/nginx; \
4344

flavors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"tsuru-rpaasv2 INOTIFY_INCDIR=/usr/include/linux-gnu",
2222
"lua-resty-http 0.17.2-0",
2323
"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"
2526
]
2627
},
2728
{

test/nginx-tsuru.bash

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,23 @@ test_brotli() {
3737
assert 'BQmAPGI+QnJvdGxpIHBhZ2U8L2I+CgM=' "$response" "/brotli with brotli compression response"
3838
}
3939

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+
4050
echo "Running tests"
4151

4252
test_nginx_serving_request
4353
test_lua_content
4454
test_lua_http_resty
4555
test_brotli
56+
test_libjwt_with_token
57+
test_libjwt_no_token
4658

4759
echo "✅ SUCESS: All tests passed"

test/nginx-tsuru.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ http {
7979
}
8080
}
8181

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+
8297
location /brotli {
8398
brotli on;
8499
default_type 'text/html';

0 commit comments

Comments
 (0)