-
Notifications
You must be signed in to change notification settings - Fork 25
/
errors_test.go
72 lines (61 loc) · 2 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package beyond
import (
"fmt"
"net/http"
"testing"
"github.com/drewolson/testflight"
"github.com/stretchr/testify/assert"
)
func init() {
*errorEmail = "[email protected]"
}
type testIntString struct {
code int
text string
}
func TestErrorQuery(t *testing.T) {
for errorQuery, expectedValues := range map[string]testIntString{
"invalid_request": {400, "400 - Bad Request"},
"access_denied": {403, "403 - Forbidden"},
"invalid_resource": {404, "404 - Not Found"},
"unknown": {500, "500 - Internal Server Error"},
"server_error": {500, "500 - Internal Server Error"},
"unsupported_response_type": {501, "501 - Not Implemented"},
"temporarily_unavailable": {503, "503 - Service Unavailable"},
} {
testflight.WithServer(testMux, func(r *testflight.Requester) {
request, err := http.NewRequest("GET", "/oidc?error="+errorQuery, nil)
assert.Nil(t, err)
request.Host = *host
response := r.Do(request)
assert.Equal(t, expectedValues.code, response.StatusCode)
assert.Contains(t, response.Body, expectedValues.text)
})
}
}
func TestErrorPlain(t *testing.T) {
*errorPlain = true
testflight.WithServer(testMux, func(r *testflight.Requester) {
request, err := http.NewRequest("GET", "/oidc?error=server_error&error_description=Foo+Biz", nil)
assert.Nil(t, err)
request.Host = *host
response := r.Do(request)
assert.Equal(t, 500, response.StatusCode)
assert.Contains(t, response.Body, "Foo Biz")
})
*errorPlain = false
}
type testResponseWriter struct {
http.ResponseWriter
}
func (w *testResponseWriter) WriteHeader(code int) {}
func (w *testResponseWriter) Header() http.Header { return http.Header{} }
func (w *testResponseWriter) Write(data []byte) (n int, err error) {
return 0, fmt.Errorf("WriteError")
}
func TestErrorExecuteWriteError(t *testing.T) {
w := &testResponseWriter{}
err := errorExecute(w, 500, "WriteError")
assert.Equal(t, "WriteError", err.Error())
errorHandler(w, 500, "WriteError")
}