44 "testing"
55
66 "github.com/letsencrypt/boulder/test"
7+ "net/http"
78)
89
910func TestProblemDetails (t * testing.T ) {
@@ -14,3 +15,30 @@ func TestProblemDetails(t *testing.T) {
1415 }
1516 test .AssertEquals (t , pd .Error (), "urn:acme:error:malformed :: Wat? o.O" )
1617}
18+
19+ func TestProblemDetailsToStatusCode (t * testing.T ) {
20+ testCases := []struct {
21+ pb * ProblemDetails
22+ statusCode int
23+ }{
24+ {& ProblemDetails {Type : ConnectionProblem }, http .StatusBadRequest },
25+ {& ProblemDetails {Type : MalformedProblem }, http .StatusBadRequest },
26+ {& ProblemDetails {Type : ServerInternalProblem }, http .StatusInternalServerError },
27+ {& ProblemDetails {Type : TLSProblem }, http .StatusBadRequest },
28+ {& ProblemDetails {Type : UnauthorizedProblem }, http .StatusForbidden },
29+ {& ProblemDetails {Type : UnknownHostProblem }, http .StatusBadRequest },
30+ {& ProblemDetails {Type : RateLimitedProblem }, statusTooManyRequests },
31+ {& ProblemDetails {Type : BadNonceProblem }, http .StatusBadRequest },
32+ {& ProblemDetails {Type : InvalidEmailProblem }, http .StatusBadRequest },
33+ {& ProblemDetails {Type : "foo" }, http .StatusInternalServerError },
34+ {& ProblemDetails {Type : "foo" , HTTPStatus : 200 }, 200 },
35+ {& ProblemDetails {Type : ConnectionProblem , HTTPStatus : 200 }, 200 },
36+ }
37+
38+ for _ , c := range testCases {
39+ p := ProblemDetailsToStatusCode (c .pb )
40+ if c .statusCode != p {
41+ t .Errorf ("Incorrect status code for %s. Expected %d, got %d" , c .pb .Type , c .statusCode , p )
42+ }
43+ }
44+ }
0 commit comments