@@ -2269,3 +2269,86 @@ func TestAnalyze_mgmt(t *testing.T) {
2269
2269
})
2270
2270
}
2271
2271
}
2272
+
2273
+ //nolint:funlen
2274
+ func TestAnalyze_headers_more (t * testing.T ) {
2275
+ t .Parallel ()
2276
+ testcases := map [string ]struct {
2277
+ stmt * Directive
2278
+ ctx blockCtx
2279
+ wantErr bool
2280
+ }{
2281
+ "more_set_headers ok" : {
2282
+ & Directive {
2283
+ Directive : "more_set_headers" ,
2284
+ Args : []string {"Server: my_server" },
2285
+ Line : 5 ,
2286
+ },
2287
+ blockCtx {"http" , "location" , "location if" },
2288
+ false ,
2289
+ },
2290
+ "more_set_headers multiple args ok" : {
2291
+ & Directive {
2292
+ Directive : "more_set_headers" ,
2293
+ Args : []string {"-s" , "404" , "-s" , "500 503" , "Foo: bar" },
2294
+ Line : 5 ,
2295
+ },
2296
+ blockCtx {"http" , "location" , "location if" },
2297
+ false ,
2298
+ },
2299
+ "more_set_headers not ok" : {
2300
+ & Directive {
2301
+ Directive : "more_set_headers" ,
2302
+ Args : []string {"Server: my_server" },
2303
+ Line : 5 ,
2304
+ },
2305
+ blockCtx {"stream" },
2306
+ true ,
2307
+ },
2308
+ "more_clear_headers ok" : {
2309
+ & Directive {
2310
+ Directive : "more_clear_headers" ,
2311
+ Args : []string {"X-Hidden-*" },
2312
+ Line : 5 ,
2313
+ },
2314
+ blockCtx {"http" , "location" , "location if" },
2315
+ false ,
2316
+ },
2317
+ "more_set_input_headers ok" : {
2318
+ & Directive {
2319
+ Directive : "more_set_input_headers" ,
2320
+ Args : []string {"Authorization: $http_authorization" },
2321
+ Line : 5 ,
2322
+ },
2323
+ blockCtx {"http" , "location" , "location if" },
2324
+ false ,
2325
+ },
2326
+ "more_clear_input_headers ok" : {
2327
+ & Directive {
2328
+ Directive : "more_set_input_headers" ,
2329
+ Args : []string {"-t" , "'text/plain'" , "Foo: " , "Baz: " },
2330
+ Line : 5 ,
2331
+ },
2332
+ blockCtx {"http" , "location" , "location if" },
2333
+ false ,
2334
+ },
2335
+ }
2336
+
2337
+ for name , tc := range testcases {
2338
+ tc := tc
2339
+ t .Run (name , func (t * testing.T ) {
2340
+ t .Parallel ()
2341
+ err := analyze ("nginx.conf" , tc .stmt , ";" , tc .ctx , & ParseOptions {
2342
+ MatchFuncs : []MatchFunc {MatchHeadersMore },
2343
+ })
2344
+
2345
+ if ! tc .wantErr && err != nil {
2346
+ t .Fatal (err )
2347
+ }
2348
+
2349
+ if tc .wantErr && err == nil {
2350
+ t .Fatal ("expected error, got nil" )
2351
+ }
2352
+ })
2353
+ }
2354
+ }
0 commit comments