@@ -317,6 +317,49 @@ spec:
317317 name: httpbin-service-e2e-test
318318 port:
319319 number: 80
320+ `
321+ allowMethods = `
322+ apiVersion: networking.k8s.io/v1
323+ kind: Ingress
324+ metadata:
325+ name: allow-methods
326+ annotations:
327+ k8s.apisix.apache.org/http-allow-methods: "GET,POST"
328+ spec:
329+ ingressClassName: %s
330+ rules:
331+ - host: httpbin.example
332+ http:
333+ paths:
334+ - path: /anything
335+ pathType: Exact
336+ backend:
337+ service:
338+ name: httpbin-service-e2e-test
339+ port:
340+ number: 80
341+ `
342+
343+ blockMethods = `
344+ apiVersion: networking.k8s.io/v1
345+ kind: Ingress
346+ metadata:
347+ name: block-methods
348+ annotations:
349+ k8s.apisix.apache.org/http-block-methods: "DELETE"
350+ spec:
351+ ingressClassName: %s
352+ rules:
353+ - host: httpbin2.example
354+ http:
355+ paths:
356+ - path: /anything
357+ pathType: Exact
358+ backend:
359+ service:
360+ name: httpbin-service-e2e-test
361+ port:
362+ number: 80
320363`
321364 )
322365 BeforeEach (func () {
@@ -359,5 +402,76 @@ spec:
359402 Status (http .StatusPermanentRedirect ).
360403 Header ("Location" ).IsEqual ("/anything/ip" )
361404 })
405+ It ("methods" , func () {
406+ Expect (s .CreateResourceFromString (fmt .Sprintf (allowMethods , s .Namespace ()))).ShouldNot (HaveOccurred (), "creating Ingress" )
407+ Expect (s .CreateResourceFromString (fmt .Sprintf (blockMethods , s .Namespace ()))).ShouldNot (HaveOccurred (), "creating Ingress" )
408+
409+ tets := []* scaffold.RequestAssert {
410+ {
411+ Method : "GET" ,
412+ Path : "/anything" ,
413+ Host : "httpbin.example" ,
414+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
415+ },
416+ {
417+ Method : "POST" ,
418+ Path : "/anything" ,
419+ Host : "httpbin.example" ,
420+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
421+ },
422+ {
423+ Method : "PUT" ,
424+ Path : "/anything" ,
425+ Host : "httpbin.example" ,
426+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
427+ },
428+ {
429+ Method : "PATCH" ,
430+ Path : "/anything" ,
431+ Host : "httpbin.example" ,
432+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
433+ },
434+ {
435+ Method : "DELETE" ,
436+ Path : "/anything" ,
437+ Host : "httpbin.example" ,
438+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
439+ },
440+ {
441+ Method : "GET" ,
442+ Path : "/anything" ,
443+ Host : "httpbin2.example" ,
444+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
445+ },
446+ {
447+ Method : "POST" ,
448+ Path : "/anything" ,
449+ Host : "httpbin2.example" ,
450+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
451+ },
452+ {
453+ Method : "PUT" ,
454+ Path : "/anything" ,
455+ Host : "httpbin2.example" ,
456+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
457+ },
458+ {
459+ Method : "PATCH" ,
460+ Path : "/anything" ,
461+ Host : "httpbin2.example" ,
462+ Check : scaffold .WithExpectedStatus (http .StatusOK ),
463+ },
464+ {
465+ Method : "DELETE" ,
466+ Path : "/anything" ,
467+ Host : "httpbin2.example" ,
468+ Check : scaffold .WithExpectedStatus (http .StatusMethodNotAllowed ),
469+ },
470+ }
471+
472+ for _ , test := range tets {
473+ s .RequestAssert (test )
474+ }
475+ })
362476 })
363477})
0 commit comments