@@ -24,12 +24,16 @@ func init() {
2424 internal .InitSlog ("debug" )
2525}
2626
27- func loadPolicies (t * testing.T , fname string ) * policy.ParsedConfig {
27+ func loadPolicies (t * testing.T , fname string , difficulty int ) * policy.ParsedConfig {
2828 t .Helper ()
2929
3030 ctx := thothmock .WithMockThoth (t )
3131
32- anubisPolicy , err := LoadPoliciesOrDefault (ctx , fname , anubis .DefaultDifficulty )
32+ if fname == "" {
33+ fname = "./testdata/test_config.yaml"
34+ }
35+
36+ anubisPolicy , err := LoadPoliciesOrDefault (ctx , fname , difficulty )
3337 if err != nil {
3438 t .Fatal (err )
3539 }
@@ -176,8 +180,7 @@ func TestLoadPolicies(t *testing.T) {
176180
177181// Regression test for CVE-2025-24369
178182func TestCVE2025_24369 (t * testing.T ) {
179- pol := loadPolicies (t , "" )
180- pol .DefaultDifficulty = 4
183+ pol := loadPolicies (t , "" , anubis .DefaultDifficulty )
181184
182185 srv := spawnAnubis (t , Options {
183186 Next : http .NewServeMux (),
@@ -200,8 +203,7 @@ func TestCVE2025_24369(t *testing.T) {
200203}
201204
202205func TestCookieCustomExpiration (t * testing.T ) {
203- pol := loadPolicies (t , "" )
204- pol .DefaultDifficulty = 0
206+ pol := loadPolicies (t , "" , 0 )
205207 ckieExpiration := 10 * time .Minute
206208
207209 srv := spawnAnubis (t , Options {
@@ -250,8 +252,7 @@ func TestCookieCustomExpiration(t *testing.T) {
250252}
251253
252254func TestCookieSettings (t * testing.T ) {
253- pol := loadPolicies (t , "" )
254- pol .DefaultDifficulty = 0
255+ pol := loadPolicies (t , "" , 0 )
255256
256257 srv := spawnAnubis (t , Options {
257258 Next : http .NewServeMux (),
@@ -316,10 +317,7 @@ func TestCheckDefaultDifficultyMatchesPolicy(t *testing.T) {
316317
317318 for i := 1 ; i < 10 ; i ++ {
318319 t .Run (fmt .Sprint (i ), func (t * testing.T ) {
319- anubisPolicy , err := LoadPoliciesOrDefault (t .Context (), "" , i )
320- if err != nil {
321- t .Fatal (err )
322- }
320+ anubisPolicy := loadPolicies (t , "" , i )
323321
324322 s , err := New (Options {
325323 Next : h ,
@@ -337,11 +335,13 @@ func TestCheckDefaultDifficultyMatchesPolicy(t *testing.T) {
337335
338336 req .Header .Add ("X-Real-Ip" , "127.0.0.1" )
339337
340- _ , bot , err := s .check (req )
338+ cr , bot , err := s .check (req )
341339 if err != nil {
342340 t .Fatal (err )
343341 }
344342
343+ t .Log (cr .Name )
344+
345345 if bot .Challenge .Difficulty != i {
346346 t .Errorf ("Challenge.Difficulty is wrong, wanted %d, got: %d" , i , bot .Challenge .Difficulty )
347347 }
@@ -389,8 +389,7 @@ func TestBasePrefix(t *testing.T) {
389389 // Reset the global BasePrefix before each test
390390 anubis .BasePrefix = ""
391391
392- pol := loadPolicies (t , "" )
393- pol .DefaultDifficulty = 4
392+ pol := loadPolicies (t , "" , 4 )
394393
395394 srv := spawnAnubis (t , Options {
396395 Next : h ,
@@ -518,8 +517,7 @@ func TestCustomStatusCodes(t *testing.T) {
518517 "DENY" : 403 ,
519518 }
520519
521- pol := loadPolicies (t , "./testdata/aggressive_403.yaml" )
522- pol .DefaultDifficulty = 4
520+ pol := loadPolicies (t , "./testdata/aggressive_403.yaml" , 4 )
523521
524522 srv := spawnAnubis (t , Options {
525523 Next : h ,
@@ -553,7 +551,7 @@ func TestCustomStatusCodes(t *testing.T) {
553551func TestCloudflareWorkersRule (t * testing.T ) {
554552 for _ , variant := range []string {"cel" , "header" } {
555553 t .Run (variant , func (t * testing.T ) {
556- pol := loadPolicies (t , "./testdata/cloudflare-workers-" + variant + ".yaml" )
554+ pol := loadPolicies (t , "./testdata/cloudflare-workers-" + variant + ".yaml" , 0 )
557555
558556 h := http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
559557 fmt .Fprintln (w , "OK" )
@@ -609,8 +607,7 @@ func TestCloudflareWorkersRule(t *testing.T) {
609607}
610608
611609func TestRuleChange (t * testing.T ) {
612- pol := loadPolicies (t , "testdata/rule_change.yaml" )
613- pol .DefaultDifficulty = 0
610+ pol := loadPolicies (t , "testdata/rule_change.yaml" , 0 )
614611 ckieExpiration := 10 * time .Minute
615612
616613 srv := spawnAnubis (t , Options {
0 commit comments