Skip to content

Commit

Permalink
fix(api-auth): /preauth and /authenticate endpoints also return the d…
Browse files Browse the repository at this point in the history
…efault address of an user ZMS-175 (#738)

* rebase

* preauth and authenticate now also return the email address of the user

* fix user tests

* fix git divergence issues: submit.js
  • Loading branch information
NickOvt authored Sep 30, 2024
1 parent 8730ed5 commit 6dac6ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = (db, server, userHandler) => {
success: successRes,
id: userId,
username: Joi.string().required().description('Username of authenticated User'),
address: Joi.string().required().description('Default email address of authenticated User'),
scope: Joi.string().required().description('The scope this authentication is valid for'),
require2fa: Joi.array().items(Joi.string()).required().description('List of enabled 2FA mechanisms')
})
Expand Down Expand Up @@ -109,6 +110,7 @@ module.exports = (db, server, userHandler) => {
success: true,
id: authData.user.toString(),
username: authData.username,
address: authData.address,
scope: authData.scope,
require2fa: authData.require2fa
};
Expand Down Expand Up @@ -158,6 +160,7 @@ module.exports = (db, server, userHandler) => {
success: successRes,
id: userId,
username: Joi.string().required().description('Username of authenticated User'),
address: Joi.string().required().description('Default email address of authenticated User'),
scope: Joi.string().required().description('The scope this authentication is valid for'),
require2fa: Joi.array().items(Joi.string()).required().description('List of enabled 2FA mechanisms'),
requirePasswordChange: booleanSchema.required().description('Indicates if account hassword has been reset and should be replaced'),
Expand Down Expand Up @@ -246,6 +249,7 @@ module.exports = (db, server, userHandler) => {
success: true,
id: authData.user.toString(),
username: authData.username,
address: authData.address,
scope: authData.scope,
require2fa: authData.require2fa,
requirePasswordChange: authData.requirePasswordChange
Expand Down
2 changes: 2 additions & 0 deletions lib/user-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ class UserHandler {
user: userData._id,
username: userData.username,
scope: meta.requiredScope,
address: userData.address,
// if 2FA is enabled then require token validation
require2fa: enabled2fa.length && !usingTemporaryPassword ? enabled2fa : false,
requirePasswordChange // true, if password was reset and using temporary password
Expand Down Expand Up @@ -1105,6 +1106,7 @@ class UserHandler {
let authResponse = {
user: userData._id,
username: userData.username,
address: userData.address,
scope: requiredScope,
// if 2FA is enabled then require token validation
require2fa: requiredScope === 'master' && enabled2fa.length ? enabled2fa : false
Expand Down
5 changes: 5 additions & 0 deletions test/api/users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const config = require('wild-config');

const server = supertest.agent(`http://127.0.0.1:${config.api.port}`);

const os = require('os');

describe('API Users', function () {
this.timeout(10000); // eslint-disable-line no-invalid-this

Expand Down Expand Up @@ -81,6 +83,7 @@ describe('API Users', function () {
expect(authResponse.body.success).to.be.true;
expect(authResponse.body).to.deep.equal({
success: true,
address: 'john@example.com',
id: user,
username: 'myuser2',
scope: 'master',
Expand Down Expand Up @@ -155,6 +158,7 @@ describe('API Users', function () {
expect(authResponse.body.success).to.be.true;
expect(authResponse.body).to.deep.equal({
success: true,
address: `myuser2hash@${os.hostname().toLowerCase()}`,
id: user2,
username: 'myuser2hash',
scope: 'master',
Expand Down Expand Up @@ -332,6 +336,7 @@ describe('API Users', function () {
expect(authResponse.body.success).to.be.true;
expect(authResponse.body).to.deep.equal({
success: true,
address: 'john@example.com',
id: user,
username: 'myuser2',
scope: 'master',
Expand Down

0 comments on commit 6dac6ae

Please sign in to comment.