Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
bc02006b
Unverified
Commit
bc02006b
authored
5 years ago
by
Stephan Renatus
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1510 from momokatte/test-invalid-callbacks
Add tests for some callback handler error conditions
parents
526e0783
43d1a044
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/handlers_test.go
+72
-0
72 additions, 0 deletions
server/handlers_test.go
with
72 additions
and
0 deletions
server/handlers_test.go
+
72
−
0
View file @
bc02006b
package
server
package
server
import
(
import
(
"bytes"
"context"
"context"
"encoding/json"
"errors"
"errors"
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
...
@@ -48,3 +50,73 @@ func TestHandleHealthFailure(t *testing.T) {
...
@@ -48,3 +50,73 @@ func TestHandleHealthFailure(t *testing.T) {
t
.
Errorf
(
"expected 500 got %d"
,
rr
.
Code
)
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
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment