Improve `http_status` validation
This commit is contained in:
parent
2714d10d62
commit
b5a30dd3e5
|
@ -3,6 +3,7 @@ package ingress
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -260,7 +261,7 @@ func validateIngress(ingress []config.UnvalidatedIngressRule, defaults OriginReq
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Ingress{}, errors.Wrap(err, "invalid HTTP status code")
|
return Ingress{}, errors.Wrap(err, "invalid HTTP status code")
|
||||||
}
|
}
|
||||||
if statusCode < 100 || statusCode > 999 {
|
if http.StatusText(statusCode) == "" {
|
||||||
return Ingress{}, fmt.Errorf("invalid HTTP status code: %d", statusCode)
|
return Ingress{}, fmt.Errorf("invalid HTTP status code: %d", statusCode)
|
||||||
}
|
}
|
||||||
srv := newStatusCode(statusCode)
|
srv := newStatusCode(statusCode)
|
||||||
|
|
|
@ -247,10 +247,18 @@ ingress:
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Invalid HTTP status code",
|
name: "Invalid HTTP status code(8080)",
|
||||||
args: args{rawYAML: `
|
args: args{rawYAML: `
|
||||||
ingress:
|
ingress:
|
||||||
- service: http_status:8080
|
- service: http_status:8080
|
||||||
|
`},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invalid HTTP status code(666)",
|
||||||
|
args: args{rawYAML: `
|
||||||
|
ingress:
|
||||||
|
- service: http_status:666
|
||||||
`},
|
`},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue