mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
46fb1a2b79
This reverts commit c9a532db65.
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
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)
|
|
}
|
|
|
|
foundPowConfig := false
|
|
for _, file := range activeConfig.SupportFiles {
|
|
if file.Path != "pow_config.json" {
|
|
continue
|
|
}
|
|
foundPowConfig = true
|
|
if file.Content == "" {
|
|
t.Fatal("expected pow_config.json content to be populated")
|
|
}
|
|
}
|
|
if !foundPowConfig {
|
|
t.Fatal("expected agent config to include pow_config.json support file")
|
|
}
|
|
}
|
|
|
|
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" {
|
|
if !strings.Contains(file.Content, `"session_ttl":600`) {
|
|
t.Fatalf("expected default PoW session TTL to be 600 seconds, got %s", file.Content)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
t.Fatal("expected agent config to include pow_config.json support file")
|
|
}
|