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
b1311baa
Commit
b1311baa
authored
5 years ago
by
Tomasz Kleczek
Committed by
Tomasz Kleczek
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
abort connector login if connector was already set #1707
Signed-off-by:
Tomasz Kleczek
<
tomasz.kleczek@gmail.com
>
parent
336c73c0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/handlers.go
+4
-1
4 additions, 1 deletion
server/handlers.go
server/handlers_test.go
+85
-0
85 additions, 0 deletions
server/handlers_test.go
with
89 additions
and
1 deletion
server/handlers.go
+
4
−
1
View file @
b1311baa
...
...
@@ -283,7 +283,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
connID
:=
mux
.
Vars
(
r
)[
"connector"
]
conn
,
err
:=
s
.
getConnector
(
connID
)
if
err
!=
nil
{
s
.
logger
.
Errorf
(
"Failed to
create authorization request
: %v"
,
err
)
s
.
logger
.
Errorf
(
"Failed to
get connector
: %v"
,
err
)
s
.
renderError
(
r
,
w
,
http
.
StatusBadRequest
,
"Requested resource does not exist"
)
return
}
...
...
@@ -304,6 +304,9 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
// Set the connector being used for the login.
if
authReq
.
ConnectorID
!=
connID
{
updater
:=
func
(
a
storage
.
AuthRequest
)
(
storage
.
AuthRequest
,
error
)
{
if
a
.
ConnectorID
!=
""
{
return
a
,
fmt
.
Errorf
(
"connector is already set for this auth request"
)
}
a
.
ConnectorID
=
connID
return
a
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
server/handlers_test.go
+
85
−
0
View file @
b1311baa
...
...
@@ -8,8 +8,12 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/gorilla/mux"
"github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/memory"
)
func
TestHandleHealth
(
t
*
testing
.
T
)
{
...
...
@@ -119,3 +123,84 @@ func TestHandleInvalidSAMLCallbacks(t *testing.T) {
}
}
}
func
TestConnectorLoginDoesNotAllowToChangeConnectorForAuthRequest
(
t
*
testing
.
T
)
{
memStorage
:=
memory
.
New
(
logger
)
templates
,
err
:=
loadTemplates
(
webConfig
{},
"../web/templates"
)
if
err
!=
nil
{
t
.
Fatal
(
"failed to load tempalates"
)
}
s
:=
&
Server
{
storage
:
memStorage
,
logger
:
logger
,
templates
:
templates
,
supportedResponseTypes
:
map
[
string
]
bool
{
"code"
:
true
},
now
:
time
.
Now
,
connectors
:
make
(
map
[
string
]
Connector
),
}
r
:=
mux
.
NewRouter
()
r
.
HandleFunc
(
"/auth/{connector}"
,
s
.
handleConnectorLogin
)
s
.
mux
=
r
clientID
:=
"clientID"
clientSecret
:=
"secret"
redirectURL
:=
"localhost:5555"
+
"/callback"
client
:=
storage
.
Client
{
ID
:
clientID
,
Secret
:
clientSecret
,
RedirectURIs
:
[]
string
{
redirectURL
},
}
if
err
:=
memStorage
.
CreateClient
(
client
);
err
!=
nil
{
t
.
Fatal
(
"failed to create client"
)
}
createConnector
:=
func
(
t
*
testing
.
T
,
id
string
)
storage
.
Connector
{
connector
:=
storage
.
Connector
{
ID
:
id
,
Type
:
"mockCallback"
,
Name
:
"Mock"
,
ResourceVersion
:
"1"
,
}
if
err
:=
memStorage
.
CreateConnector
(
connector
);
err
!=
nil
{
t
.
Fatalf
(
"failed to create connector %v"
,
id
)
}
return
connector
}
connector1
:=
createConnector
(
t
,
"mock1"
)
connector2
:=
createConnector
(
t
,
"mock2"
)
authReq
:=
storage
.
AuthRequest
{
ID
:
storage
.
NewID
(),
}
if
err
:=
memStorage
.
CreateAuthRequest
(
authReq
);
err
!=
nil
{
t
.
Fatal
(
"failed to create auth request"
)
}
createConnectorLoginRequest
:=
func
(
connID
string
)
*
http
.
Request
{
req
:=
httptest
.
NewRequest
(
"GET"
,
"/auth/"
+
connID
,
nil
)
q
:=
req
.
URL
.
Query
()
q
.
Add
(
"req"
,
authReq
.
ID
)
q
.
Add
(
"redirect_uri"
,
redirectURL
)
q
.
Add
(
"scope"
,
"openid"
)
q
.
Add
(
"response_type"
,
"code"
)
req
.
URL
.
RawQuery
=
q
.
Encode
()
return
req
}
recorder
:=
httptest
.
NewRecorder
()
s
.
ServeHTTP
(
recorder
,
createConnectorLoginRequest
(
connector1
.
ID
))
if
recorder
.
Code
!=
302
{
t
.
Fatal
(
"failed to process request"
)
}
recorder2
:=
httptest
.
NewRecorder
()
s
.
ServeHTTP
(
recorder2
,
createConnectorLoginRequest
(
connector2
.
ID
))
if
recorder2
.
Code
!=
500
{
t
.
Error
(
"attempt to overwrite connector on auth request should fail"
)
}
}
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