Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pubsweet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Tremblay McLellan
pubsweet
Commits
5c50fda4
Commit
5c50fda4
authored
6 years ago
by
Jure
Browse files
Options
Downloads
Patches
Plain Diff
fix(model-user): fix update user mutation's password hashing
parent
4204318b
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
packages/components/model-user/src/graphql.js
+8
-1
8 additions, 1 deletion
packages/components/model-user/src/graphql.js
packages/components/model-user/test/user_graphql_test.js
+83
-0
83 additions, 0 deletions
packages/components/model-user/test/user_graphql_test.js
with
91 additions
and
1 deletion
packages/components/model-user/src/graphql.js
+
8
−
1
View file @
5c50fda4
...
@@ -30,7 +30,14 @@ const resolvers = {
...
@@ -30,7 +30,14 @@ const resolvers = {
deleteUser
(
_
,
{
id
},
ctx
)
{
deleteUser
(
_
,
{
id
},
ctx
)
{
return
ctx
.
connectors
.
User
.
delete
(
id
,
ctx
)
return
ctx
.
connectors
.
User
.
delete
(
id
,
ctx
)
},
},
updateUser
(
_
,
{
id
,
input
},
ctx
)
{
async
updateUser
(
_
,
{
id
,
input
},
ctx
)
{
if
(
input
.
password
)
{
input
.
passwordHash
=
await
ctx
.
connectors
.
User
.
model
.
hashPassword
(
input
.
password
,
)
delete
input
.
password
}
return
ctx
.
connectors
.
User
.
update
(
id
,
input
,
ctx
)
return
ctx
.
connectors
.
User
.
update
(
id
,
input
,
ctx
)
},
},
// Authentication
// Authentication
...
...
This diff is collapsed.
Click to expand it.
packages/components/model-user/test/user_graphql_test.js
0 → 100644
+
83
−
0
View file @
5c50fda4
process
.
env
.
NODE_CONFIG
=
`{"pubsweet":{
"components":[
"@pubsweet/model-user",
"@pubsweet/model-team"
]
}}`
const
User
=
require
(
'
../src/user
'
)
const
{
dbCleaner
,
api
}
=
require
(
'
pubsweet-server/test
'
)
const
{
fixtures
}
=
require
(
'
@pubsweet/model-user/test
'
)
const
authentication
=
require
(
'
pubsweet-server/src/authentication
'
)
describe
(
'
User mutations
'
,
()
=>
{
// let token
// let user
beforeEach
(
async
()
=>
{
await
dbCleaner
()
// user = await new User(fixtures.user).save()
// token = authentication.token.create(user)
})
it
(
'
a user can sign up
'
,
async
()
=>
{
const
{
body
}
=
await
api
.
graphql
.
query
(
`mutation($input: UserInput) {
createUser(input: $input) {
username
}
}`
,
{
input
:
{
username
:
'
hi
'
,
email
:
'
hi@example.com
'
,
password
:
'
hello
'
,
},
},
)
expect
(
body
).
toEqual
({
data
:
{
createUser
:
{
username
:
'
hi
'
,
},
},
})
})
it
(
'
a user can update a password
'
,
async
()
=>
{
const
user
=
await
new
User
(
fixtures
.
user
).
save
()
const
token
=
authentication
.
token
.
create
(
user
)
const
{
body
}
=
await
api
.
graphql
.
query
(
`mutation($id: ID, $input: UserInput) {
updateUser(id: $id, input: $input) {
username
}
}`
,
{
id
:
user
.
id
,
input
:
{
username
:
'
hi
'
,
email
:
'
hi@example.com
'
,
password
:
'
hello2
'
,
},
},
token
,
)
expect
(
body
).
toEqual
({
data
:
{
updateUser
:
{
username
:
'
hi
'
,
},
},
})
const
oldHash
=
user
.
passwordHash
const
newHash
=
await
User
.
find
(
user
.
id
).
passwordHash
expect
(
oldHash
).
not
.
toEqual
(
newHash
)
})
})
This diff is collapsed.
Click to expand it.
Preview
0%
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