Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZMS-175 #738

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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