Skip to content

Instantly share code, notes, and snippets.

@cdbattags
Created January 20, 2021 20:37
Show Gist options
  • Save cdbattags/7dfab7ab6691359588df512bf1c0663c to your computer and use it in GitHub Desktop.
Save cdbattags/7dfab7ab6691359588df512bf1c0663c to your computer and use it in GitHub Desktop.
openresty json string comparison
use Test::Nginx::Socket::Lua;
repeat_each(2);
plan tests => repeat_each() * (3 * blocks());
our $HttpConfig = <<'_EOC_';
lua_package_path 'lib/?.lua;;';
_EOC_
no_long_string();
run_tests();
__DATA__
=== TEST 1: Verify A256CBC-HS512 Direct Encryption with a Shared Symmetric Key
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local jwt = require "resty.jwt"
local cjson = require "cjson"
local shared_key = "12341234123412341234123412341234" ..
"12341234123412341234123412341234"
local jwt_obj = jwt:verify(
shared_key,
"eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIn0." ..
".M927Z_hNTmumFQE0rtRQCQ.nnd7AoE_2dgvws2-iay8qA.d" ..
"kyZuuks4Qm9Cd7VfEVSs07pi_Kyt0INVHTTesUC2BM"
)
ngx.say(
cjson.encode(jwt_obj)
)
';
}
--- request
GET /t
--- response_body
{"reason":"everything is awesome~ :p","valid":true,"payload":{"foo":"bar"},"header":{"alg":"dir","enc":"A256CBC-HS512"},"verified":true}
--- no_error_log
[error]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment