Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SDK-GO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
systemes-dinformation
project-template
SDK-GO
Commits
e9a50fb4
Commit
e9a50fb4
authored
5 years ago
by
Alexis Poyen
Browse files
Options
Downloads
Patches
Plain Diff
Security : don't send back password hash
parent
f6827e83
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
internal/rootmux/admin_test.go
+2
-2
2 additions, 2 deletions
internal/rootmux/admin_test.go
pkg/auth/auth.go
+1
-1
1 addition, 1 deletion
pkg/auth/auth.go
pkg/auth/inmemory.go
+1
-6
1 addition, 6 deletions
pkg/auth/inmemory.go
with
4 additions
and
9 deletions
internal/rootmux/admin_test.go
+
2
−
2
View file @
e9a50fb4
...
...
@@ -64,9 +64,9 @@ func AdminTests(t *testing.T) {
xsrfHeader
:=
tester
.
Header
{
Key
:
"XSRF-TOKEN"
,
Value
:
token
.
XSRFToken
}
// Create a Client
do
(
"POST"
,
apiAdminUsers
,
xsrfHeader
,
`{"login":"UserTest","password": "password","role":"CLIENT"}`
,
200
,
`{"id":7,"idOAuth":"","login":"UserTest","role":"CLIENT"
,"passwordHash":"
`
)
do
(
"POST"
,
apiAdminUsers
,
xsrfHeader
,
`{"login":"UserTest","password": "password","role":"CLIENT"}`
,
200
,
`{"id":7,"idOAuth":"","login":"UserTest","role":"CLIENT"`
)
// Create a Banker
do
(
"POST"
,
apiAdminUsers
,
xsrfHeader
,
`{"login":"BankerTest","password": "password","role":"BANKER"}`
,
200
,
`{"id":8,"idOAuth":"","login":"BankerTest","role":"BANKER"
,"passwordHash":"
`
)
do
(
"POST"
,
apiAdminUsers
,
xsrfHeader
,
`{"login":"BankerTest","password": "password","role":"BANKER"}`
,
200
,
`{"id":8,"idOAuth":"","login":"BankerTest","role":"BANKER"`
)
// Get all users
do
(
"GET"
,
apiAdminUsers
,
xsrfHeader
,
``
,
200
,
`[{"id":1,"idOAuth":"","login":"Dupond"`
)
// Delete created users
...
...
This diff is collapsed.
Click to expand it.
pkg/auth/auth.go
+
1
−
1
View file @
e9a50fb4
...
...
@@ -32,7 +32,7 @@ type User struct {
IsAdmin
bool
`json:"isAdmin,omitempty"`
Name
string
`json:"name,omitempty"`
Surname
string
`json:"surname,omitempty"`
PasswordHash
string
`json:"
passwordHash,omitempty
"`
PasswordHash
string
`json:"
-
"`
Password
string
`json:"password,omitempty"`
}
...
...
This diff is collapsed.
Click to expand it.
pkg/auth/inmemory.go
+
1
−
6
View file @
e9a50fb4
...
...
@@ -97,7 +97,7 @@ func (d *DataHandler) AddUser(w http.ResponseWriter, req *http.Request) {
return
}
// Encrypt the password with bcrypt
if
newUser
.
Password
==
""
&&
newUser
.
PasswordHash
==
""
{
if
newUser
.
Password
==
""
{
http
.
Error
(
w
,
"passwords cannot be blank"
,
400
)
return
}
...
...
@@ -154,11 +154,6 @@ func (d *DataHandler) UpdateUser(w http.ResponseWriter, req *http.Request) {
user
.
Name
=
newUser
.
Name
user
.
Surname
=
newUser
.
Surname
user
.
Role
=
newUser
.
Role
// Encrypt the password with bcrypt if appropriate
if
newUser
.
Password
==
""
&&
newUser
.
PasswordHash
==
""
{
http
.
Error
(
w
,
"passwords cannot be blank"
,
http
.
StatusBadRequest
)
return
}
if
newUser
.
Password
!=
""
{
hash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
newUser
.
Password
),
bcrypt
.
DefaultCost
)
if
err
!=
nil
{
...
...
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