|
| 1 | +setmetatable(_G, nil) |
| 2 | + |
| 3 | +local AWS = require("resty.aws") |
| 4 | +local AWS_global_config = require("resty.aws.config").global |
| 5 | + |
| 6 | + |
| 7 | +local config = AWS_global_config |
| 8 | +config.tls = true |
| 9 | +local aws = AWS(config) |
| 10 | + |
| 11 | + |
| 12 | +aws.config.credentials = aws:Credentials { |
| 13 | + accessKeyId = "test_id", |
| 14 | + secretAccessKey = "test_key", |
| 15 | +} |
| 16 | + |
| 17 | +aws.config.region = "test_region" |
| 18 | +aws.config.dry_run = true |
| 19 | + |
| 20 | +describe("SNS service", function() |
| 21 | + local sns |
| 22 | + local origin_time |
| 23 | + |
| 24 | + setup(function() |
| 25 | + origin_time = ngx.time |
| 26 | + ngx.time = function () --luacheck: ignore |
| 27 | + return 1667543171 |
| 28 | + end |
| 29 | + end) |
| 30 | + |
| 31 | + teardown(function () |
| 32 | + ngx.time = origin_time --luacheck: ignore |
| 33 | + end) |
| 34 | + |
| 35 | + before_each(function() |
| 36 | + sns = assert(aws:SNS({})) |
| 37 | + end) |
| 38 | + |
| 39 | + after_each(function() |
| 40 | + end) |
| 41 | + |
| 42 | + local testcases = { |
| 43 | + publish = { |
| 44 | + { |
| 45 | + TopicArn = "arn:aws:sns:test-region:000000000000:test-topic", |
| 46 | + Message = '{"timestamp":"1980-01-02T08:11:12.123+01:00","message":"test%abc%22"}', -- this is not an urlencoded message value |
| 47 | + }, |
| 48 | + { |
| 49 | + ['headers'] = { |
| 50 | + ['Authorization'] = 'AWS4-HMAC-SHA256 Credential=test_id/20221104/test_region/sns/aws4_request, SignedHeaders=host;x-amz-date, Signature=9a83a7bafbccd6c3214091baf22eb1d1e507327be18f7ad5cf8ccc45ac335e48', |
| 51 | + ['Host'] = 'sns.test_region.amazonaws.com', |
| 52 | + ['X-Amz-Date'] = '20221104T062611Z', |
| 53 | + }, |
| 54 | + ['host'] = 'sns.test_region.amazonaws.com', |
| 55 | + ['method'] = 'POST', |
| 56 | + ['path'] = '/', |
| 57 | + ['proxy_opts'] = {}, |
| 58 | + ['port'] = 443, |
| 59 | + ['query'] = { |
| 60 | + ['Action'] = 'Publish', |
| 61 | + ['Version'] = '2010-03-31', |
| 62 | + ['Message'] = '{"timestamp":"1980-01-02T08:11:12.123+01:00","message":"test%abc%22"}', |
| 63 | + ['TopicArn'] = 'arn:aws:sns:test-region:000000000000:test-topic', |
| 64 | + }, |
| 65 | + ['tls'] = true, |
| 66 | + }, |
| 67 | + }, |
| 68 | + } |
| 69 | + |
| 70 | + for api, test in pairs(testcases) do |
| 71 | + it("SecretsManager:" .. api, function() |
| 72 | + local param = test[1] |
| 73 | + local expected_result_aws = test[2] |
| 74 | + |
| 75 | + local result_aws = assert(sns[api](sns, param)) |
| 76 | + |
| 77 | + assert.same(expected_result_aws, result_aws) |
| 78 | + end) |
| 79 | + end |
| 80 | +end) |
0 commit comments