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
7016a825
Unverified
Commit
7016a825
authored
2 years ago
by
Maksim Nabokikh
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: return 401 if password is invalid (#2796)
Signed-off-by:
m.nabokikh
<
maksim.nabokikh@flant.com
>
parent
32517331
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_test.go
+36
-23
36 additions, 23 deletions
server/handlers_test.go
server/templates.go
+3
-0
3 additions, 0 deletions
server/templates.go
with
39 additions
and
23 deletions
server/handlers_test.go
+
36
−
23
View file @
7016a825
...
...
@@ -265,7 +265,7 @@ func mockConnectorDataTestStorage(t *testing.T, s storage.Storage) {
require
.
NoError
(
t
,
err
)
}
func
TestPassword
ConnectorDataNotEmpty
(
t
*
testing
.
T
)
{
func
Test
Handle
Password
(
t
*
testing
.
T
)
{
t0
:=
time
.
Now
()
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
...
...
@@ -280,33 +280,46 @@ func TestPasswordConnectorDataNotEmpty(t *testing.T) {
mockConnectorDataTestStorage
(
t
,
s
.
storage
)
u
,
err
:=
url
.
Parse
(
s
.
issuerURL
.
String
())
require
.
NoError
(
t
,
err
)
makeReq
:=
func
(
username
,
password
string
)
*
httptest
.
ResponseRecorder
{
u
,
err
:=
url
.
Parse
(
s
.
issuerURL
.
String
())
require
.
NoError
(
t
,
err
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"/token"
)
v
:=
url
.
Values
{}
v
.
Add
(
"scope"
,
"openid offline_access email"
)
v
.
Add
(
"grant_type"
,
"password"
)
v
.
Add
(
"username"
,
"test"
)
v
.
Add
(
"password"
,
"test"
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"/token"
)
v
:=
url
.
Values
{}
v
.
Add
(
"scope"
,
"openid offline_access email"
)
v
.
Add
(
"grant_type"
,
"password"
)
v
.
Add
(
"username"
,
username
)
v
.
Add
(
"password"
,
password
)
req
,
_
:=
http
.
NewRequest
(
"POST"
,
u
.
String
(),
bytes
.
NewBufferString
(
v
.
Encode
()))
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded; param=value"
)
req
.
SetBasicAuth
(
"test"
,
"barfoo"
)
req
,
_
:=
http
.
NewRequest
(
"POST"
,
u
.
String
(),
bytes
.
NewBufferString
(
v
.
Encode
()))
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded; param=value"
)
req
.
SetBasicAuth
(
"test"
,
"barfoo"
)
rr
:=
httptest
.
NewRecorder
()
s
.
ServeHTTP
(
rr
,
req
)
rr
:=
httptest
.
NewRecorder
()
s
.
ServeHTTP
(
rr
,
req
)
require
.
Equal
(
t
,
200
,
rr
.
Code
)
return
rr
}
// Check that we received expected refresh token
var
ref
struct
{
Token
string
`json:"refresh_token"`
// Check unauthorized error
{
rr
:=
makeReq
(
"test"
,
"invalid"
)
require
.
Equal
(
t
,
401
,
rr
.
Code
)
}
err
=
json
.
Unmarshal
(
rr
.
Body
.
Bytes
(),
&
ref
)
require
.
NoError
(
t
,
err
)
newSess
,
err
:=
s
.
storage
.
GetOfflineSessions
(
"0-385-28089-0"
,
"test"
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
`{"test": "true"}`
,
string
(
newSess
.
ConnectorData
))
// Check that we received expected refresh token
{
rr
:=
makeReq
(
"test"
,
"test"
)
require
.
Equal
(
t
,
200
,
rr
.
Code
)
var
ref
struct
{
Token
string
`json:"refresh_token"`
}
err
:=
json
.
Unmarshal
(
rr
.
Body
.
Bytes
(),
&
ref
)
require
.
NoError
(
t
,
err
)
newSess
,
err
:=
s
.
storage
.
GetOfflineSessions
(
"0-385-28089-0"
,
"test"
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
`{"test": "true"}`
,
string
(
newSess
.
ConnectorData
))
}
}
This diff is collapsed.
Click to expand it.
server/templates.go
+
3
−
0
View file @
7016a825
...
...
@@ -286,6 +286,9 @@ func (t *templates) login(r *http.Request, w http.ResponseWriter, connectors []c
}
func
(
t
*
templates
)
password
(
r
*
http
.
Request
,
w
http
.
ResponseWriter
,
postURL
,
lastUsername
,
usernamePrompt
string
,
lastWasInvalid
bool
,
backLink
string
)
error
{
if
lastWasInvalid
{
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
}
data
:=
struct
{
PostURL
string
BackLink
string
...
...
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