diff --git a/actions/user-registration/__tests__/index.tests.js b/actions/user-registration/__tests__/index.tests.js index 80c2ecf..1ea400f 100644 --- a/actions/user-registration/__tests__/index.tests.js +++ b/actions/user-registration/__tests__/index.tests.js @@ -48,7 +48,7 @@ describe('user-registration', () => { .catch(err => expect(err).toBe('[400] "username" is required')) }) - test('invalid username returns [400] "username" must be a valid email', () => { + test('email returns [400] "email" is required', () => { expect.assertions(1) const request = { @@ -60,7 +60,23 @@ describe('user-registration', () => { } return userRegistration(request, actions) - .catch(err => expect(err).toBe('[400] "username" must be a valid email')) + .catch(err => expect(err).toBe('[400] "email" is required')) + }) + + test('invalid email returns [400] "email" must be a valid email', () => { + expect.assertions(1) + + const request = { + pathParameters: { realm: 'realm' }, + body: querystring.stringify({ + client_id: 'client_id', + username: 'username', + email: 'invalid', + }) + } + + return userRegistration(request, actions) + .catch(err => expect(err).toBe('[400] "email" must be a valid email')) }) test('no password returns [400] "password" is required', () => { @@ -71,6 +87,7 @@ describe('user-registration', () => { body: querystring.stringify({ client_id: 'client_id', username: 'test@test.com', + email: 'test@test.com', }) } @@ -86,6 +103,7 @@ describe('user-registration', () => { body: querystring.stringify({ client_id: 'client_id', username: 'test@test.com', + email: 'test@test.com', password: 'password' }) } @@ -106,6 +124,7 @@ describe('user-registration', () => { body: querystring.stringify({ client_id: 'client_id', username: 'test@test.com', + email: 'test@test.com', password: 'password' }) } @@ -125,7 +144,8 @@ describe('user-registration', () => { pathParameters: { realm: 'realm' }, body: querystring.stringify({ client_id: 'client_id', - username: 'test2@test.com', + username: 'username', + email: 'test2@test.com', password: 'password' }) } diff --git a/actions/user-registration/__tests__/request.tests.js b/actions/user-registration/__tests__/request.tests.js index 3cb6837..03b34ab 100644 --- a/actions/user-registration/__tests__/request.tests.js +++ b/actions/user-registration/__tests__/request.tests.js @@ -24,24 +24,39 @@ describe('userRegistrationRequest', () => { const data = { pathParameters: { realm: 'realm' }, body: querystring.encode({ - client_id: 'client_id' + client_id: 'client_id', }) } return validate(I)(data) .catch(error => expect(error).toBe('[400] "username" is required')) }) - test('invalid username returns [400] "username" must be a valid email', () => { + test('no email returns [400] "email" is required', () => { expect.assertions(1) const data = { pathParameters: { realm: 'realm' }, body: querystring.encode({ client_id: 'client_id', - username: 'invalid' + username: 'username', }) } return validate(I)(data) - .catch(error => expect(error).toBe('[400] "username" must be a valid email')) + .catch(error => expect(error).toBe('[400] "email" is required')) + }) + + test('invalid email returns [400] "email" must be a valid email', () => { + expect.assertions(1) + const data = { + pathParameters: { realm: 'realm' }, + body: querystring.encode({ + client_id: 'client_id', + username: 'username', + email: 'invalid', + password: 'password', + }) + } + return validate(I)(data) + .catch(error => expect(error).toBe('[400] "email" must be a valid email')) }) test('no password returns [400] "password" is required', () => { @@ -50,7 +65,8 @@ describe('userRegistrationRequest', () => { pathParameters: { realm: 'realm' }, body: querystring.encode({ client_id: 'client_id', - username: 'email@address.com' + username: 'email@address.com', + email: 'test@test.com', }) } return validate(I)(data) @@ -63,12 +79,13 @@ describe('userRegistrationRequest', () => { pathParameters: { realm: 'realm' }, body: querystring.encode({ client_id: 'client_id', - username: 'email@address.com', - password: 'password' + username: 'username', + email: 'test@test.com', + password: 'password', }) } return validate(request => { - expect(request).toEqual({ realm: 'realm', client_id: 'client_id', username: 'email@address.com', password: 'password' }) + expect(request).toEqual({ realm: 'realm', client_id: 'client_id', username: 'username', email: 'test@test.com', password: 'password' }) })(data) }) }) diff --git a/actions/user-registration/index.js b/actions/user-registration/index.js index 1858097..494facb 100644 --- a/actions/user-registration/index.js +++ b/actions/user-registration/index.js @@ -8,7 +8,8 @@ const exceptionMapper = require('../../lib/exceptionMapper') const toUserModel = (state) => ({ userId: `${state.props.realm}:${state.props.username}`, - emailAddress: state.props.username, + username: state.props.username, + emailAddress: state.props.email, password: state.props.password, realm: state.props.realm, roles: [], diff --git a/actions/user-registration/request.js b/actions/user-registration/request.js index 41ee001..b40372b 100644 --- a/actions/user-registration/request.js +++ b/actions/user-registration/request.js @@ -12,7 +12,8 @@ const getRequest = event => const schema = Joi.object().keys({ realm: Joi.string().required(), client_id: Joi.string().required(), - username: Joi.string().email().required(), + username: Joi.string().required(), + email: Joi.string().email().required(), password: Joi.string().required(), redirect_uri: Joi.string() }) diff --git a/services/storage/dynamodb/create-user.js b/services/storage/dynamodb/create-user.js index bd3ef94..c52ac43 100644 --- a/services/storage/dynamodb/create-user.js +++ b/services/storage/dynamodb/create-user.js @@ -6,6 +6,7 @@ const docClient = require('./doc-client') const schema = Joi.object().keys({ userId: Joi.string().regex(/^[^:]+:[^:]+:[^:]+$/).required(), + username: Joi.string().required(), emailAddress: Joi.string().email().required(), password: Joi.string().required(), realm: Joi.string().regex(/^[^:]+:[^:]+$/).required(),