增加相关测试文件和例子

This commit is contained in:
wanglei 2025-10-14 14:45:47 +08:00
parent 30d16de03b
commit 9da130ca55
4 changed files with 210 additions and 3 deletions

View File

@ -7,9 +7,15 @@ events {
}
http {
lua_package_path 'src/?/?.lua;src/?.lua;src/share/?/?.lua;src/share/?.lua;;';
lua_package_path 'src/?/?.lua;src/?.lua;src/share/?/?.lua;src/share/?.lua;/home/frankly/work/AuthPlatform/src/share/lib/?/?.lub;/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth/?.lua;;';
lua_package_cpath 'src/share/lib/?.so;;';
# Path of the file with trusted CA certificates.
#lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
# The verification depth in the server certificates chain.
#lua_ssl_verify_depth 3;
server {
listen 9080;
server_name 127.0.0.1;
@ -35,5 +41,105 @@ http {
location /testObj {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testObjClass.lua';
}
location /testWsdl {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWebService.lua';
}
location /wsdl {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWsdl.lua';
}
location /jsonSchema {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testJsonSchem.lua';
}
location /checkip {
content_by_lua_block {
local ipmatcher = require("resty.ipmatcher")
local client_ip = ngx.var.remote_addr
ngx.say(ipmatcher.new({"127.0.0.1", "192.168.0.11/16"}).match(client_ip))
}
}
location /t {
rewrite_by_lua_block {
local aes = require "resty.aes"
local str = require "resty.string"
local cjson = require('cjson')
local key = "aaaaaaaaaaaaaaaa"
local text = "7614463 1574189821 175.168.224.225"
local length = 16
local count = string.len(text)
local add = length - (count % length)
local tail_str='\0'
for i=1,add-1 do
tail_str=tail_str .. '\0'
end
text = text .. tail_str
ngx.say(text)
-- 创建 AES 对象
local aes_128_cbc = aes:new(key, nil, aes.cipher(128, "cbc"), {iv=key})
-- 加密数据
local encrypted, err = aes_128_cbc:encrypt(text)
if not encrypted then
ngx.log(ngx.ERR, "Failed to encrypt: ", err)
return ngx.exit(500)
end
ngx.say(str.to_hex(encrypted))
local crc_32s, crc_32l
crc_32s = ngx.crc32_short(str)
crc_32l = ngx.crc32_long(str)
--local hmac = ngx.hmac_sha1(key, str)
local md5 = ngx.md5(str)
local md5_bin = ngx.md5_bin(str)
local sha1_bin = ngx.sha1_bin(str)
ngx.say("crc_32_short: ", crc_32s, ", crc_32_long: ", crc_32l)
ngx.say("hmac: ", ngx.encode_base64(hmac))
ngx.say("md5: ", md5, ", md5_bin: ", ngx.encode_base64(md5_bin))
ngx.say("sha1_bin: ", ngx.encode_base64(sha1_bin))
-- 将加密后的数据转换为十六进制字符串以便于查看或传输
local encrypted_hex = cjson.encode({iv = ngx.encode_base64(iv), ciphertext = ngx.encode_base64(encrypted)})
ngx.say("Encrypted: ", encrypted_hex)
}
}
}
server {
listen 1443 ssl; #修改端口443
server_name 127.0.0.1;
set $oauth_client_id '01234567-89ab-cdef-0123-456789abcdef';
set $oauth_client_secret 'very-top-secret-password';
set $oauth_redirect_uri '/_oauth/callback';
set $oauth_oaas_uri 'https://127.0.0.1/oauth';
ssl_certificate /home/frankly/work/server.crt;
ssl_certificate_key /home/frankly/work/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #֧支持TLS协议
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #支持的加密算法
ssl_prefer_server_ciphers on;
location /_oauth/login {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-login.lua';
}
location /_oauth/callback {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-redirect-handler.lua';
}
location /_oauth/logout {
content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-logout.lua';
}
location /_proxy {
access_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-proxy.lua';
rewrite ^/_proxy/(.*)$ /$1 break;
##proxy_pass https://resource-provider;
}
}
}

View File

@ -2,4 +2,33 @@
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/9/25 08:19
--- 业务逻辑
--- 业务逻辑
local db_config = require('config.database')
local pgmoon = require('share.pgmoonn')
-- 创建一个新的连接
local conn = pgmoon.new(db_config.postgres)
-- 连接到数据库
conn:connect(function(err)
if err then
print("Error connecting to database: ", err)
else
print("Connected to the PostgreSQL server.")
end
end)
-- 执行一个简单的查询
conn:query("SELECT version()")
:on_data(function(row)
print("Database Version: ", row[1])
end)
:on_error(function(err)
print("Query Error: ", err)
end)
:on_finish(function()
print("Query finished.")
-- 关闭连接
conn:close()
end)

View File

@ -0,0 +1,20 @@
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by frankly.
--- DateTime: 2025/10/14 09:07
---
local jsonSchema = require"jsonschema"
local schema = {
type = 'object',
properties = {
foo = {type = 'string'},
bar = {type = 'number'}
}
}
local validator = jsonSchema.generate_validator(schema)
local data = { foo = 'hello', bar = 42 }
local result = validator(data)
ngx.say(result)

View File

@ -2,4 +2,56 @@
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by frankly.
--- DateTime: 2025/9/29 10:14
---
---
function class(classname, super)
local cls = { __name = classname, __super = super }
-- 继承父类方法
if super then
setmetatable(cls, { __index = super })
end
-- 实例的元表指向类
cls.__index = cls
-- 构造函数(自动克隆类字段)
function cls:new(...)
local obj = {}
setmetatable(obj, self)
-- 链式调用构造函数
local function call_ctor(class, ...)
if class.__super then
call_ctor(class.__super, ...)
end
if rawget(class, "ctor") then
class.ctor(obj, ...)
end
end
call_ctor(self, ...)
return obj
end
return cls
end
-- 使用方法展示
local Parent = class("Parent", Grandfather)
Parent.defaultParentName = "defaultParentName"
function Parent:ctor(name)
self.parentName = name
end
local Child = class("Child", Parent)
function Child:ctor(name)
self.__super:ctor(name)
self.childName = name
end
local A = Child:new('A')
local B = Child:new('B')
ngx.say(A.childName) -- 输出A
ngx.say(B.childName) -- 输出B
ngx.say(A.parentName) -- 输出A
ngx.say(B.parentName) -- 输出B