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
28aaa8f5
Unverified
Commit
28aaa8f5
authored
2 years ago
by
Maksim Nabokikh
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: Do not skip approval screen by default (#2897)
Signed-off-by:
m.nabokikh
<
maksim.nabokikh@flant.com
>
parent
e568cdc9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/handlers.go
+1
-1
1 addition, 1 deletion
server/handlers.go
server/handlers_test.go
+41
-17
41 additions, 17 deletions
server/handlers_test.go
with
42 additions
and
18 deletions
server/handlers.go
+
1
−
1
View file @
28aaa8f5
...
@@ -523,7 +523,7 @@ func (s *Server) finalizeLogin(identity connector.Identity, authReq storage.Auth
...
@@ -523,7 +523,7 @@ func (s *Server) finalizeLogin(identity connector.Identity, authReq storage.Auth
authReq
.
ConnectorID
,
claims
.
Username
,
claims
.
PreferredUsername
,
email
,
claims
.
Groups
)
authReq
.
ConnectorID
,
claims
.
Username
,
claims
.
PreferredUsername
,
email
,
claims
.
Groups
)
// we can skip the redirect to /approval and go ahead and send code if it's not required
// we can skip the redirect to /approval and go ahead and send code if it's not required
if
s
.
skipApproval
||
!
authReq
.
ForceApprovalPrompt
{
if
s
.
skipApproval
&&
!
authReq
.
ForceApprovalPrompt
{
return
""
,
true
,
nil
return
""
,
true
,
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
server/handlers_test.go
+
41
−
17
View file @
28aaa8f5
...
@@ -10,7 +10,6 @@ import (
...
@@ -10,7 +10,6 @@ import (
"net/http/httptest"
"net/http/httptest"
"net/url"
"net/url"
"path"
"path"
"strings"
"testing"
"testing"
"time"
"time"
...
@@ -339,6 +338,7 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
...
@@ -339,6 +338,7 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
name
string
name
string
skipApproval
bool
skipApproval
bool
authReq
storage
.
AuthRequest
authReq
storage
.
AuthRequest
expectedRes
string
}{
}{
{
{
name
:
"Force approval"
,
name
:
"Force approval"
,
...
@@ -351,6 +351,7 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
...
@@ -351,6 +351,7 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
ResponseTypes
:
resTypes
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
true
,
ForceApprovalPrompt
:
true
,
},
},
expectedRes
:
"/approval"
,
},
},
{
{
name
:
"Skip approval by server config"
,
name
:
"Skip approval by server config"
,
...
@@ -363,9 +364,10 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
...
@@ -363,9 +364,10 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
ResponseTypes
:
resTypes
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
true
,
ForceApprovalPrompt
:
true
,
},
},
expectedRes
:
"/approval"
,
},
},
{
{
name
:
"
Skip approval by auth request
"
,
name
:
"
No skip
"
,
skipApproval
:
false
,
skipApproval
:
false
,
authReq
:
storage
.
AuthRequest
{
authReq
:
storage
.
AuthRequest
{
ID
:
authReqID
,
ID
:
authReqID
,
...
@@ -375,6 +377,20 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
...
@@ -375,6 +377,20 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
ResponseTypes
:
resTypes
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
false
,
ForceApprovalPrompt
:
false
,
},
},
expectedRes
:
"/approval"
,
},
{
name
:
"Skip approval"
,
skipApproval
:
true
,
authReq
:
storage
.
AuthRequest
{
ID
:
authReqID
,
ConnectorID
:
connID
,
RedirectURI
:
"cb"
,
Expiry
:
expiry
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
false
,
},
expectedRes
:
"/auth/mockPw/cb"
,
},
},
}
}
...
@@ -410,15 +426,11 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
...
@@ -410,15 +426,11 @@ func TestHandlePasswordLoginWithSkipApproval(t *testing.T) {
require
.
Equal
(
t
,
303
,
rr
.
Code
)
require
.
Equal
(
t
,
303
,
rr
.
Code
)
resp
:=
rr
.
Result
()
resp
:=
rr
.
Result
()
cbPath
:=
strings
.
Split
(
resp
.
Header
.
Get
(
"Location"
),
"?"
)[
0
]
if
tc
.
skipApproval
||
!
tc
.
authReq
.
ForceApprovalPrompt
{
defer
resp
.
Body
.
Close
()
require
.
Equal
(
t
,
"/auth/mockPw/cb"
,
cbPath
)
}
else
{
require
.
Equal
(
t
,
"/approval"
,
cbPath
)
}
resp
.
Body
.
Close
()
cb
,
_
:=
url
.
Parse
(
resp
.
Header
.
Get
(
"Location"
))
require
.
Equal
(
t
,
tc
.
expectedRes
,
cb
.
Path
)
}
}
}
}
...
@@ -435,6 +447,7 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
...
@@ -435,6 +447,7 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
name
string
name
string
skipApproval
bool
skipApproval
bool
authReq
storage
.
AuthRequest
authReq
storage
.
AuthRequest
expectedRes
string
}{
}{
{
{
name
:
"Force approval"
,
name
:
"Force approval"
,
...
@@ -447,6 +460,7 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
...
@@ -447,6 +460,7 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
ResponseTypes
:
resTypes
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
true
,
ForceApprovalPrompt
:
true
,
},
},
expectedRes
:
"/approval"
,
},
},
{
{
name
:
"Skip approval by server config"
,
name
:
"Skip approval by server config"
,
...
@@ -459,6 +473,7 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
...
@@ -459,6 +473,7 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
ResponseTypes
:
resTypes
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
true
,
ForceApprovalPrompt
:
true
,
},
},
expectedRes
:
"/approval"
,
},
},
{
{
name
:
"Skip approval by auth request"
,
name
:
"Skip approval by auth request"
,
...
@@ -471,6 +486,20 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
...
@@ -471,6 +486,20 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
ResponseTypes
:
resTypes
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
false
,
ForceApprovalPrompt
:
false
,
},
},
expectedRes
:
"/approval"
,
},
{
name
:
"Skip approval"
,
skipApproval
:
true
,
authReq
:
storage
.
AuthRequest
{
ID
:
authReqID
,
ConnectorID
:
connID
,
RedirectURI
:
"cb"
,
Expiry
:
expiry
,
ResponseTypes
:
resTypes
,
ForceApprovalPrompt
:
false
,
},
expectedRes
:
"/callback/cb"
,
},
},
}
}
...
@@ -492,14 +521,9 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
...
@@ -492,14 +521,9 @@ func TestHandleConnectorCallbackWithSkipApproval(t *testing.T) {
require
.
Equal
(
t
,
303
,
rr
.
Code
)
require
.
Equal
(
t
,
303
,
rr
.
Code
)
resp
:=
rr
.
Result
()
resp
:=
rr
.
Result
()
cbPath
:=
strings
.
Split
(
resp
.
Header
.
Get
(
"Location"
),
"?"
)[
0
]
defer
resp
.
Body
.
Close
()
if
tc
.
skipApproval
||
!
tc
.
authReq
.
ForceApprovalPrompt
{
require
.
Equal
(
t
,
"/callback/cb"
,
cbPath
)
}
else
{
require
.
Equal
(
t
,
"/approval"
,
cbPath
)
}
resp
.
Body
.
Close
()
cb
,
_
:=
url
.
Parse
(
resp
.
Header
.
Get
(
"Location"
))
require
.
Equal
(
t
,
tc
.
expectedRes
,
cb
.
Path
)
}
}
}
}
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