Skip to content

Commit

Permalink
fix: lowercase username on signup (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
alterx authored and gr2m committed Sep 20, 2017
1 parent c625561 commit 3e158ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/accounts/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ function addAccount (state, properties, options) {
return Promise.reject(errors.USERNAME_EMPTY)
}

var accountKey = 'org.couchdb.user:' + properties.username
var lowercaseUsername = properties.username.toLowerCase()

/*
lowercaseUsername value will be used to create the accountKey.
We require this since the user lookup is based on this key and
@hoodie/account-server looks up for the user using the lowercase
version of the accountKey.
See https://github.com/hoodiehq/hoodie-account-server/issues/271
We also need to change the name parameter inside the doc to use
the lowercase version since pouchdb-users requires the doc ID to
be of the form 'org.couchdb.user:<name>'
*/

var accountKey = 'org.couchdb.user:' + lowercaseUsername
var accountId = properties.id || uuid.v4()

var doc = {
_id: accountKey,
type: 'user',
name: properties.username,
name: lowercaseUsername,
password: properties.password,
createdAt: properties.createdAt,
signedUpAt: properties.signedUpAt,
Expand Down
22 changes: 22 additions & 0 deletions test/unit/accounts/add-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ test('addAccount', function (group) {
})
})

group.test('with username containing uppercase letters', function (t) {
t.plan(1)

var state = {
cache: {
set: simple.stub().resolveWith({})
},
setupPromise: Promise.resolve()
}

addAccount(state, {
username: 'userWithCAPS'
})

.then(function () {
var doc = state.cache.set.lastCall.arg
t.deepEqual(doc.name, 'userwithcaps')
})

.catch(t.catch)
})

group.test('with other error', function (t) {
t.plan(3)

Expand Down

0 comments on commit 3e158ed

Please sign in to comment.