mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 00:26:37 +08:00
[功能] POW 有效期优化
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetActiveConfigForAgentIncludesPoWConfig(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
@@ -39,3 +42,37 @@ func TestGetActiveConfigForAgentIncludesPoWConfig(t *testing.T) {
|
||||
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"); 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")
|
||||
}
|
||||
|
||||
@@ -1097,7 +1097,7 @@ func defaultPoWConfig() ProxyRoutePoWConfig {
|
||||
return ProxyRoutePoWConfig{
|
||||
Difficulty: 4,
|
||||
Algorithm: "fast",
|
||||
SessionTTL: 86400,
|
||||
SessionTTL: 600,
|
||||
ChallengeTTL: 300,
|
||||
Whitelist: ProxyRoutePoWListConfig{IPs: []string{}, IPCidrs: []string{}, Paths: []string{}, PathRegexes: []string{}, UserAgents: []string{}},
|
||||
Blacklist: ProxyRoutePoWListConfig{IPs: []string{}, IPCidrs: []string{}, Paths: []string{}, PathRegexes: []string{}, UserAgents: []string{}},
|
||||
|
||||
Reference in New Issue
Block a user