|
| 1 | +local PLUGIN_NAME = "access-token-introspection" |
| 2 | + |
| 3 | +-- helper function to validate data against a schema |
| 4 | +local validate |
| 5 | +do |
| 6 | + local validate_entity = |
| 7 | + require("spec.helpers").validate_plugin_config_schema |
| 8 | + local plugin_schema = require("kong.plugins." .. PLUGIN_NAME .. ".schema") |
| 9 | + |
| 10 | + function validate(data) return validate_entity(data, plugin_schema) end |
| 11 | +end |
| 12 | + |
| 13 | +describe(PLUGIN_NAME .. ": (schema)", function() |
| 14 | + |
| 15 | + it("requires distinct client_id, client_secret, and introspection_endpoint", |
| 16 | + function() |
| 17 | + local ok, err = validate({ |
| 18 | + client_id = "CLIENT_ID", |
| 19 | + client_secret = "CLIENT_SECRET", |
| 20 | + introspection_endpoint = "http://localhost:8080" |
| 21 | + }) |
| 22 | + assert.is_nil(err) |
| 23 | + assert.is_truthy(ok) |
| 24 | + end) |
| 25 | + |
| 26 | + it("validates introspection_endpoint is a valid URL", function() |
| 27 | + local ok, err = validate({ |
| 28 | + client_id = "CLIENT_ID", |
| 29 | + client_secret = "CLIENT_SECRET", |
| 30 | + introspection_endpoint = "xyz" |
| 31 | + }) |
| 32 | + assert.falsy(ok) |
| 33 | + assert.same("Invalid URL", err.config.introspection_endpoint) |
| 34 | + end) |
| 35 | + |
| 36 | + it("validates token_cache_time is an integer", function() |
| 37 | + local ok, err = validate({ |
| 38 | + client_id = "CLIENT_ID", |
| 39 | + client_secret = "CLIENT_SECRET", |
| 40 | + introspection_endpoint = "http://localhost:8080", |
| 41 | + token_cache_time = "60" |
| 42 | + }) |
| 43 | + assert.falsy(ok) |
| 44 | + assert.same("expected a number", err.config.token_cache_time) |
| 45 | + end) |
| 46 | + |
| 47 | + it("validates introspection_map supports body, headers, and static", |
| 48 | + function() |
| 49 | + local ok, err = validate({ |
| 50 | + client_id = "CLIENT_ID", |
| 51 | + client_secret = "CLIENT_SECRET", |
| 52 | + introspection_endpoint = "http://localhost:8080", |
| 53 | + introspection_map = { |
| 54 | + body = {Header1 = "index-1"}, |
| 55 | + headers = {Header2 = "X-User"}, |
| 56 | + static = {Header3 = "zyx"} |
| 57 | + } |
| 58 | + }) |
| 59 | + assert.is_nil(err) |
| 60 | + assert.is_truthy(ok) |
| 61 | + end) |
| 62 | + |
| 63 | + it("validates introspection_map only supports body, headers, and static", |
| 64 | + function() |
| 65 | + local ok, err = validate({ |
| 66 | + client_id = "CLIENT_ID", |
| 67 | + client_secret = "CLIENT_SECRET", |
| 68 | + introspection_endpoint = "http://localhost:8080", |
| 69 | + introspection_map = {xyz = "zyx"} |
| 70 | + }) |
| 71 | + assert.falsy(ok) |
| 72 | + assert.same("unknown field", err.config.introspection_map.xyz) |
| 73 | + end) |
| 74 | + |
| 75 | +end) |
0 commit comments