mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 07:36:37 +08:00
[优化] 添加 WAF 阻止逻辑以短路 PoW 处理,更新测试以验证新行为
This commit is contained in:
@@ -1265,6 +1265,9 @@ func renderAccessBlock(siteName string, powEnabled bool) string {
|
||||
return fmt.Sprintf(` set $openflare_waf_site "%s";
|
||||
access_by_lua_block {
|
||||
dofile("%s/waf/check.lua")
|
||||
if ngx.ctx.openflare_waf_blocked then
|
||||
return
|
||||
end
|
||||
dofile("%s/pow/check.lua")
|
||||
}
|
||||
`, escapedSiteName, nginxLuaDirPlaceholder, nginxLuaDirPlaceholder)
|
||||
|
||||
@@ -1025,8 +1025,8 @@ func TestPublishConfigVersionDetectsPoWChanges(t *testing.T) {
|
||||
if !strings.Contains(secondRelease.Version.RenderedConfig, "application/javascript js mjs;") {
|
||||
t.Fatal("expected rendered config to serve Anubis module scripts with a JavaScript MIME type")
|
||||
}
|
||||
if !strings.Contains(secondRelease.Version.RenderedConfig, " dofile(\"__OPENFLARE_LUA_DIR__/waf/check.lua\")\n dofile(\"__OPENFLARE_LUA_DIR__/pow/check.lua\")") {
|
||||
t.Fatal("expected combined WAF and PoW access handler to render at server scope")
|
||||
if !strings.Contains(secondRelease.Version.RenderedConfig, " dofile(\"__OPENFLARE_LUA_DIR__/waf/check.lua\")\n if ngx.ctx.openflare_waf_blocked then\n return\n end\n dofile(\"__OPENFLARE_LUA_DIR__/pow/check.lua\")") {
|
||||
t.Fatal("expected combined WAF and PoW access handler to short-circuit before PoW")
|
||||
}
|
||||
locationStart := strings.Index(secondRelease.Version.RenderedConfig, " location / {\n")
|
||||
if locationStart < 0 {
|
||||
|
||||
Reference in New Issue
Block a user