@@ -7,6 +7,7 @@ local fixtures = require "spec.fixtures.aws-lambda"
7
7
local TEST_CONF = helpers .test_conf
8
8
local server_tokens = meta ._SERVER_TOKENS
9
9
local null = ngx .null
10
+ local fmt = string.format
10
11
11
12
12
13
@@ -1182,4 +1183,96 @@ for _, strategy in helpers.each_strategy() do
1182
1183
end )
1183
1184
end )
1184
1185
end )
1186
+
1187
+ describe (" Plugin: AWS Lambda with #vault [#" .. strategy .. " ]" , function ()
1188
+ local proxy_client
1189
+ local admin_client
1190
+
1191
+ local ttl_time = 1
1192
+
1193
+ lazy_setup (function ()
1194
+ helpers .setenv (" KONG_VAULT_ROTATION_INTERVAL" , " 1" )
1195
+
1196
+ local bp = helpers .get_db_utils (strategy , {
1197
+ " routes" ,
1198
+ " services" ,
1199
+ " plugins" ,
1200
+ " vaults" ,
1201
+ }, { " aws-lambda" }, { " random" })
1202
+
1203
+ local route1 = bp .routes :insert {
1204
+ hosts = { " lambda-vault.com" },
1205
+ }
1206
+
1207
+ bp .plugins :insert {
1208
+ name = " aws-lambda" ,
1209
+ route = { id = route1 .id },
1210
+ config = {
1211
+ port = 10001 ,
1212
+ aws_key = fmt (" {vault://random/aws_key?ttl=%s&resurrect_ttl=0}" , ttl_time ),
1213
+ aws_secret = " aws_secret" ,
1214
+ aws_region = " us-east-1" ,
1215
+ function_name = " functionEcho" ,
1216
+ },
1217
+ }
1218
+
1219
+ assert (helpers .start_kong ({
1220
+ database = strategy ,
1221
+ prefix = helpers .test_conf .prefix ,
1222
+ nginx_conf = " spec/fixtures/custom_nginx.template" ,
1223
+ vaults = " random" ,
1224
+ plugins = " bundled" ,
1225
+ log_level = " error" ,
1226
+ }, nil , nil , fixtures ))
1227
+ end )
1228
+
1229
+ lazy_teardown (function ()
1230
+ helpers .unsetenv (" KONG_VAULT_ROTATION_INTERVAL" )
1231
+
1232
+ helpers .stop_kong ()
1233
+ end )
1234
+
1235
+ before_each (function ()
1236
+ proxy_client = helpers .proxy_client ()
1237
+ admin_client = helpers .admin_client ()
1238
+ end )
1239
+
1240
+ after_each (function ()
1241
+ proxy_client :close ()
1242
+ admin_client :close ()
1243
+ end )
1244
+
1245
+ it (" lambda service should use latest reference value after Vault ttl" , function ()
1246
+ local res = assert (proxy_client :send {
1247
+ method = " GET" ,
1248
+ path = " /get?key1=some_value1&key2=some_value2&key3=some_value3" ,
1249
+ headers = {
1250
+ [" Host" ] = " lambda-vault.com"
1251
+ }
1252
+ })
1253
+ assert .res_status (200 , res )
1254
+ local body = assert .response (res ).has .jsonbody ()
1255
+ local authorization_header = body .headers .authorization
1256
+ local first_aws_key = string.match (authorization_header , " Credential=(.+)/" )
1257
+
1258
+ assert .eventually (function ()
1259
+ proxy_client :close ()
1260
+ proxy_client = helpers .proxy_client ()
1261
+
1262
+ local res = assert (proxy_client :send {
1263
+ method = " GET" ,
1264
+ path = " /get?key1=some_value1&key2=some_value2&key3=some_value3" ,
1265
+ headers = {
1266
+ [" Host" ] = " lambda-vault.com"
1267
+ }
1268
+ })
1269
+ assert .res_status (200 , res )
1270
+ local body = assert .response (res ).has .jsonbody ()
1271
+ local authorization_header = body .headers .authorization
1272
+ local second_aws_key = string.match (authorization_header , " Credential=(.+)/" )
1273
+
1274
+ return first_aws_key ~= second_aws_key
1275
+ end ).ignore_exceptions (true ).with_timeout (ttl_time * 2 ).is_truthy ()
1276
+ end )
1277
+ end )
1185
1278
end
0 commit comments