Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
43d1a044
Commit
43d1a044
authored
Jul 26, 2019
by
Mike O
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for some callback handler error conditions
parent
526e0783
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
0 deletions
+72
-0
handlers_test.go
server/handlers_test.go
+72
-0
No files found.
server/handlers_test.go
View file @
43d1a044
package
server
import
(
"bytes"
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
...
...
@@ -48,3 +50,73 @@ func TestHandleHealthFailure(t *testing.T) {
t
.
Errorf
(
"expected 500 got %d"
,
rr
.
Code
)
}
}
type
emptyStorage
struct
{
storage
.
Storage
}
func
(
*
emptyStorage
)
GetAuthRequest
(
string
)
(
storage
.
AuthRequest
,
error
)
{
return
storage
.
AuthRequest
{},
storage
.
ErrNotFound
}
func
TestHandleInvalidOAuth2Callbacks
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
httpServer
,
server
:=
newTestServer
(
ctx
,
t
,
func
(
c
*
Config
)
{
c
.
Storage
=
&
emptyStorage
{
c
.
Storage
}
})
defer
httpServer
.
Close
()
tests
:=
[]
struct
{
TargetURI
string
ExpectedCode
int
}{
{
"/callback"
,
http
.
StatusBadRequest
},
{
"/callback?code=&state="
,
http
.
StatusBadRequest
},
{
"/callback?code=AAAAAAA&state=BBBBBBB"
,
http
.
StatusBadRequest
},
}
rr
:=
httptest
.
NewRecorder
()
for
i
,
r
:=
range
tests
{
server
.
ServeHTTP
(
rr
,
httptest
.
NewRequest
(
"GET"
,
r
.
TargetURI
,
nil
))
if
rr
.
Code
!=
r
.
ExpectedCode
{
t
.
Fatalf
(
"test %d expected %d, got %d"
,
i
,
r
.
ExpectedCode
,
rr
.
Code
)
}
}
}
func
TestHandleInvalidSAMLCallbacks
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
httpServer
,
server
:=
newTestServer
(
ctx
,
t
,
func
(
c
*
Config
)
{
c
.
Storage
=
&
emptyStorage
{
c
.
Storage
}
})
defer
httpServer
.
Close
()
type
requestForm
struct
{
RelayState
string
}
tests
:=
[]
struct
{
RequestForm
requestForm
ExpectedCode
int
}{
{
requestForm
{},
http
.
StatusBadRequest
},
{
requestForm
{
RelayState
:
"AAAAAAA"
},
http
.
StatusBadRequest
},
}
rr
:=
httptest
.
NewRecorder
()
for
i
,
r
:=
range
tests
{
jsonValue
,
err
:=
json
.
Marshal
(
r
.
RequestForm
)
if
err
!=
nil
{
t
.
Fatal
(
err
.
Error
())
}
server
.
ServeHTTP
(
rr
,
httptest
.
NewRequest
(
"POST"
,
"/callback"
,
bytes
.
NewBuffer
(
jsonValue
)))
if
rr
.
Code
!=
r
.
ExpectedCode
{
t
.
Fatalf
(
"test %d expected %d, got %d"
,
i
,
r
.
ExpectedCode
,
rr
.
Code
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment