-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
* feat(users): change username to usernameOrEmail in signin * fix(users): toLowerCase at email in local strategy
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ describe('Article Admin CRUD tests', function () { | |
beforeEach(function (done) { | ||
// Create user credentials | ||
credentials = { | ||
username: 'username', | ||
usernameOrEmail: 'username', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
|
@@ -43,7 +43,7 @@ describe('Article Admin CRUD tests', function () { | |
displayName: 'Full Name', | ||
email: '[email protected]', | ||
roles: ['user', 'admin'], | ||
username: credentials.username, | ||
username: credentials.usernameOrEmail, | ||
password: credentials.password, | ||
provider: 'local' | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ describe('Article CRUD tests', function () { | |
beforeEach(function (done) { | ||
// Create user credentials | ||
credentials = { | ||
username: 'username', | ||
usernameOrEmail: 'username', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
|
@@ -43,7 +43,7 @@ describe('Article CRUD tests', function () { | |
lastName: 'Name', | ||
displayName: 'Full Name', | ||
email: '[email protected]', | ||
username: credentials.username, | ||
username: credentials.usernameOrEmail, | ||
password: credentials.password, | ||
provider: 'local' | ||
}); | ||
|
@@ -216,7 +216,7 @@ describe('Article CRUD tests', function () { | |
it('should be able to get a single article that has an orphaned user reference', function (done) { | ||
// Create orphan user creds | ||
var _creds = { | ||
username: 'orphan', | ||
usernameOrEmail: 'orphan', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
|
@@ -226,7 +226,7 @@ describe('Article CRUD tests', function () { | |
lastName: 'Name', | ||
displayName: 'Full Name', | ||
email: '[email protected]', | ||
username: _creds.username, | ||
username: _creds.usernameOrEmail, | ||
password: _creds.password, | ||
provider: 'local', | ||
roles: ['admin'] | ||
|
@@ -322,7 +322,7 @@ describe('Article CRUD tests', function () { | |
it('should be able to get single article, that a different user created, if logged in & verify the "isCurrentUserOwner" field is set to "false"', function (done) { | ||
// Create temporary user creds | ||
var _creds = { | ||
username: 'articleowner', | ||
usernameOrEmail: 'articleowner', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
|
@@ -332,7 +332,7 @@ describe('Article CRUD tests', function () { | |
lastName: 'Name', | ||
displayName: 'Full Name', | ||
email: '[email protected]', | ||
username: _creds.username, | ||
username: _creds.usernameOrEmail, | ||
password: _creds.password, | ||
provider: 'local', | ||
roles: ['admin', 'user'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ | |
})); | ||
|
||
describe('$scope.signin()', function () { | ||
it('should login with a correct user and password', function () { | ||
it('should login with a correct username and password', function () { | ||
// Test expected GET request | ||
$httpBackend.when('POST', 'api/auth/signin').respond(200, { username: 'Fred' }); | ||
|
||
|
@@ -60,6 +60,18 @@ | |
expect($location.url()).toEqual('/'); | ||
}); | ||
|
||
it('should login with a correct email and password', function () { | ||
// Test expected GET request | ||
$httpBackend.when('POST', 'api/auth/signin').respond(200, { email: '[email protected]' }); | ||
|
||
scope.vm.signin(true); | ||
$httpBackend.flush(); | ||
|
||
// Test scope value | ||
expect(scope.vm.authentication.user.email).toEqual('[email protected]'); | ||
expect($location.url()).toEqual('/'); | ||
}); | ||
|
||
it('should be redirected to previous state after successful login', | ||
inject(function (_$state_) { | ||
$state = _$state_; | ||
|
@@ -101,7 +113,7 @@ | |
|
||
it('should fail to log in with wrong credentials', function () { | ||
// Foo/Bar combo assumed to not exist | ||
scope.vm.authentication.user = { usersname: 'Foo' }; | ||
scope.vm.authentication.user = { username: 'Foo' }; | ||
scope.vm.credentials = 'Bar'; | ||
|
||
// Test expected POST request | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ var semver = require('semver'), | |
var app, | ||
agent, | ||
credentials, | ||
credentialsEmail, | ||
user, | ||
_user, | ||
admin; | ||
|
@@ -32,9 +33,15 @@ describe('User CRUD tests', function () { | |
}); | ||
|
||
beforeEach(function (done) { | ||
// Create user credentials | ||
// Create user credentials with username | ||
credentials = { | ||
username: 'username', | ||
usernameOrEmail: 'username', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
// Create user credentials with email | ||
credentialsEmail = { | ||
usernameOrEmail: '[email protected]', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
|
@@ -44,7 +51,7 @@ describe('User CRUD tests', function () { | |
lastName: 'Name', | ||
displayName: 'Full Name', | ||
email: '[email protected]', | ||
username: credentials.username, | ||
username: credentials.usernameOrEmail, | ||
password: credentials.password, | ||
provider: 'local' | ||
}; | ||
|
@@ -83,7 +90,8 @@ describe('User CRUD tests', function () { | |
}); | ||
}); | ||
|
||
it('should be able to login successfully and logout successfully', function (done) { | ||
it('should be able to login with username and email successfully and logout successfully', function (done) { | ||
// Login with username | ||
agent.post('/api/auth/signin') | ||
.send(credentials) | ||
.expect(200) | ||
|
@@ -111,7 +119,18 @@ describe('User CRUD tests', function () { | |
signoutRes.text.should.equal('Moved Temporarily. Redirecting to /'); | ||
} | ||
|
||
return done(); | ||
// Login with username | ||
agent.post('/api/auth/signin') | ||
.send(credentials) | ||
.expect(200) | ||
.end(function (signinErr, signinRes) { | ||
// Handle signin error | ||
if (signinErr) { | ||
return done(signinErr); | ||
} | ||
|
||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
@@ -711,11 +730,11 @@ describe('User CRUD tests', function () { | |
_user2.email = '[email protected]'; | ||
|
||
var credentials2 = { | ||
username: 'username2', | ||
usernameOrEmail: 'username2', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
_user2.username = credentials2.username; | ||
_user2.username = credentials2.usernameOrEmail; | ||
_user2.password = credentials2.password; | ||
|
||
var user2 = new User(_user2); | ||
|
@@ -763,11 +782,11 @@ describe('User CRUD tests', function () { | |
_user2.email = '[email protected]'; | ||
|
||
var credentials2 = { | ||
username: 'username2', | ||
usernameOrEmail: 'username2', | ||
password: '[email protected]$Aw3$0m3' | ||
}; | ||
|
||
_user2.username = credentials2.username; | ||
_user2.username = credentials2.usernameOrEmail; | ||
_user2.password = credentials2.password; | ||
|
||
var user2 = new User(_user2); | ||
|
7 comments
on commit 6a6b630
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lirantal Hello, in modules/users/tests/server/user.server.routes.tests.js
should be able to login with username and email successfully and logout successfully
you make two agent.post('/api/auth/signin') with credentials, credentialsEmail is not used
a oversights if I'm not mistaken? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PierreBrisorgueil I took a look at this, and you're correct. The second login should be using credentialsEmail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mleanos that's not more clear to make two tests in this case ?
it('should be able to login with username successfully and logout successfully', function (done)
it('should be able to login with email successfully and logout successfully', function (done)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PierreBrisorgueil I agree with you, make two test is more clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We should have two separate tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itelo @PierreBrisorgueil could you please submit a PR with enhancements on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @itelo , it's signup, so we have two inputs for me, email, and username,
it('Should report missing username or email', function () {
should be
it('Should report missing username', function () {