定位:身份层(IdP + IAP),不含动态域名转发 / LLM 上游代理 / 用量计费。 代码(source/rust,nginx 动态模块 + Rust,单进程零外部依赖) - IdP:authorization_code(含 PKCE)/ refresh_token / client_credentials / password 四种 grant,含 discovery / introspect / userinfo / jwks 占位 - IAP:access 阶段门禁,注入 X-Auth-* 到后端,客户端伪造同名头被覆盖 - MaxKey 互通:/oauth/v20/* 与 /oauth2.0/* 别名 + context-path 归一化 + 扁平字段 - 管理接口:账号(含角色/部门/用户组)与 OAuth 接入方注册表,热写穿共享内存 - 模块改名 ngx_http_sso_module,指令 sso_state / sso_data_dir / sso_api / sso_iap, Cookie sso_sid(终端用户)与 sso_admin_session(管理员)两套身份两套会话 配置(source/conf) - nginx.conf 生产模板(TLS、IAP 子域、含 auth_sub 的日志格式) - nginx.test.conf 本机验证配置(明文 18095-18099) - tls/README.md 证书约定与公钥比对校验 前端(source/www/admin.html) - 三 tab:账号管理 / 接入方 / 接入指南;去掉审核队列、域名、LLM 上游、用量统计 测试与脚本 - tests/ 三套端到端:协议基线 14 项 · MaxKey 互通与接入 24 项 · 管理接口 31 项,全绿 - tests/demo-system 演示业务系统(Python 标准库),覆盖应用自建客户端与 IAP 零改造两种姿势 - scripts/run-local-e2e.sh 本机一键起停;scripts/seed-data.sh 物化运行时数据目录 文档 - README.md 概览与快速开始;CLAUDE.md 硬约定与排障速查 - docs/design.md 完整设计;docs/roadmap.md 待执行任务(v2 RS256+JWKS、用户管理界面)
130 lines
2.8 KiB
Perl
130 lines
2.8 KiB
Perl
#!/usr/bin/perl
|
|
|
|
# (C) Nginx, Inc
|
|
|
|
# Tests for ngx-rust example modules.
|
|
|
|
###############################################################################
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
use Test::More;
|
|
|
|
BEGIN { use FindBin; chdir($FindBin::Bin); }
|
|
|
|
use lib 'lib';
|
|
use Test::Nginx;
|
|
|
|
###############################################################################
|
|
|
|
select STDERR; $| = 1;
|
|
select STDOUT; $| = 1;
|
|
|
|
my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(12)
|
|
->write_file_expand('nginx.conf', <<'EOF');
|
|
|
|
%%TEST_GLOBALS%%
|
|
|
|
daemon off;
|
|
|
|
worker_processes 2;
|
|
|
|
events {
|
|
}
|
|
|
|
http {
|
|
%%TEST_GLOBALS_HTTP%%
|
|
|
|
shared_dict_zone z 64k;
|
|
shared_dict $arg_key $foo;
|
|
|
|
server {
|
|
listen 127.0.0.1:8080;
|
|
server_name localhost;
|
|
|
|
add_header X-Value $foo;
|
|
add_header X-Process $pid;
|
|
|
|
location /set/ {
|
|
add_header X-Process $pid;
|
|
set $foo $arg_value;
|
|
return 200;
|
|
}
|
|
|
|
location /entries/ {
|
|
add_header X-Process $pid;
|
|
return 200 $shared_dict_entries;
|
|
}
|
|
|
|
location /clear/ {
|
|
add_header X-Process $pid;
|
|
set $shared_dict_entries "";
|
|
return 200;
|
|
}
|
|
}
|
|
}
|
|
|
|
EOF
|
|
|
|
$t->write_file('index.html', '');
|
|
$t->run();
|
|
|
|
###############################################################################
|
|
|
|
like(http_get('/set/?key=fst&value=hello'), qr/200 OK/, 'set value 1');
|
|
like(http_get('/set/?key=snd&value=world'), qr/200 OK/, 'set value 2');
|
|
|
|
ok(check('/?key=fst', qr/X-Value: hello/i), 'check value 1');
|
|
ok(check('/?key=snd', qr/X-Value: world/i), 'check value 2');
|
|
|
|
like(http_get('/set/?key=fst&value=new_value'), qr/200 OK/, 'update value 1');
|
|
ok(check('/?key=fst', qr/X-Value: new_value/i), 'check updated value');
|
|
|
|
like(http_get('/entries/'), qr/^2; ((?:fst = new_value|snd = world); ){2}$/ms,
|
|
'get entries');
|
|
|
|
like(http_delete('/set/?key=snd'), qr/200 OK/, 'delete value 2');
|
|
|
|
unlike(http_get('/?key=snd'), qr/X-Value:/i, 'check deleted value');
|
|
|
|
like(http_get('/entries/'), qr/^1; fst = new_value; $/ms,
|
|
'get entries - deleted');
|
|
|
|
like(http_get('/clear/'), qr/200 OK/, 'clear');
|
|
|
|
like(http_get('/entries/'), qr/^0; $/ms, 'get entries - clear');
|
|
|
|
###############################################################################
|
|
|
|
sub check {
|
|
my ($uri, $like) = @_;
|
|
|
|
my $r = http_get($uri);
|
|
|
|
return unless ($r =~ $like && $r =~ /X-Process: (\d+)/);
|
|
|
|
return 1 if $^O eq 'MSWin32'; # only one active worker process
|
|
|
|
my $pid = $1;
|
|
|
|
for (1 .. 25) {
|
|
$r = http_get($uri);
|
|
|
|
return unless ($r =~ $like && $r =~ /X-Process: (\d+)/);
|
|
return 1 if $pid != $1;
|
|
}
|
|
}
|
|
|
|
sub http_delete {
|
|
my ($url, %extra) = @_;
|
|
return http(<<EOF, %extra);
|
|
DELETE $url HTTP/1.0
|
|
Host: localhost
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
###############################################################################
|