mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 17:56:37 +08:00
[新增] POW 与 WAF 规则合并
This commit is contained in:
@@ -11,39 +11,6 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestGetActiveConfigForAgentIncludesPoWConfig(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
|
||||
_, err := CreateProxyRoute(ProxyRouteInput{
|
||||
Domain: "pow-agent.example.com",
|
||||
OriginURL: "https://origin.internal",
|
||||
Enabled: true,
|
||||
PoWEnabled: true,
|
||||
PoWConfig: `{"difficulty":4,"algorithm":"fast","session_ttl":86400,"challenge_ttl":300,"whitelist":{"paths":["/.well-known/*","/favicon.ico","/robots.txt"],"user_agents":["Googlebot","bingbot","Baiduspider"]},"blacklist":{"ips":[],"ip_cidrs":[],"paths":[],"path_regexes":[],"user_agents":[]}}`,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateProxyRoute failed: %v", err)
|
||||
}
|
||||
|
||||
if _, err := PublishConfigVersion("root", false); err != nil {
|
||||
t.Fatalf("PublishConfigVersion failed: %v", err)
|
||||
}
|
||||
|
||||
activeConfig, err := GetActiveConfigForAgent()
|
||||
if err != nil {
|
||||
t.Fatalf("GetActiveConfigForAgent failed: %v", err)
|
||||
}
|
||||
|
||||
for _, file := range activeConfig.SupportFiles {
|
||||
if file.Path == "pow_config.json" || file.Path == "waf_config.json" {
|
||||
t.Fatalf("agent config should not receive rendered runtime config file %s", file.Path)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(activeConfig.SourceConfigJSON, `"pow_enabled":true`) {
|
||||
t.Fatal("expected agent config source json to include PoW source configuration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActiveConfigForAgentIncludesWAFConfig(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
|
||||
@@ -144,39 +111,6 @@ func TestChangedWAFIPGroupsForAgentReturnsChecksumDelta(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActiveConfigForAgentUsesTenMinutePoWSessionDefault(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
|
||||
_, err := CreateProxyRoute(ProxyRouteInput{
|
||||
Domain: "pow-default.example.com",
|
||||
OriginURL: "https://origin.internal",
|
||||
Enabled: true,
|
||||
PoWEnabled: true,
|
||||
PoWConfig: `{}`,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateProxyRoute failed: %v", err)
|
||||
}
|
||||
|
||||
if _, err := PublishConfigVersion("root", false); err != nil {
|
||||
t.Fatalf("PublishConfigVersion failed: %v", err)
|
||||
}
|
||||
|
||||
activeConfig, err := GetActiveConfigForAgent()
|
||||
if err != nil {
|
||||
t.Fatalf("GetActiveConfigForAgent failed: %v", err)
|
||||
}
|
||||
|
||||
for _, file := range activeConfig.SupportFiles {
|
||||
if file.Path == "pow_config.json" {
|
||||
t.Fatal("agent config should not receive rendered pow_config.json")
|
||||
}
|
||||
}
|
||||
if !strings.Contains(activeConfig.SourceConfigJSON, `"session_ttl":600`) {
|
||||
t.Fatalf("expected default PoW session TTL to be in source json, got %s", activeConfig.SourceConfigJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterNodeWithAccessToken(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user