Added tests on auth service
MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -170,6 +170,7 @@ export default class AuthService {
});
}
// Check Mandatory field
+ Object.assign(filteredRequest, { password: filteredRequest.passwords.password });
UtilsService.checkIfUserValid(filteredRequest as User, null, req);
// Check email
const user = await UserStorage.getUserByEmail(tenantID, filteredRequest.email);

MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -1324,7 +1324,7 @@ export default class UtilsService {
actionOnUser: filteredRequest.id
});
}
- if (filteredRequest.password && !Utils.isPasswordValid(filteredRequest.password)) {
+ if ((req.method === 'POST' && (!filteredRequest.password || !Utils.isPasswordValid(filteredRequest.password))) || filteredRequest.password && !Utils.isPasswordValid(filteredRequest.password)) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,

MODIFY
test/api/AuthenticationTest.ts
test/api/AuthenticationTest.ts
@@ -231,6 +231,36 @@ describe('Authentication Service (tenant utall)', function() {
});
describe('Error cases', () => {
+ it('Should not allow registration without password', async () => {
+ // Call
+ const newUser = UserFactory.buildRegisterUser();
+ delete newUser.passwords;
+ const response = await CentralServerService.defaultInstance.authenticationApi.registerUser(newUser, testData.adminTenant);
+ // Check
+ expect(response.status).to.be.eql(StatusCodes.INTERNAL_SERVER_ERROR);
+ expect(response.data).to.not.have.property('token');
+ });
+
+ it('Should not allow registration with empty strings passwords', async () => {
+ // Call
+ const newUser = UserFactory.buildRegisterUser();
+ newUser.passwords = { password: '', repeatPassword: '' };
+ const response = await CentralServerService.defaultInstance.authenticationApi.registerUser(newUser, testData.adminTenant);
+ // Check
+ expect(response.status).to.be.eql(StatusCodes.INTERNAL_SERVER_ERROR);
+ expect(response.data).to.not.have.property('token');
+ });
+
+ it('Should not allow registration with weak password', async () => {
+ // Call
+ const newUser = UserFactory.buildRegisterUser();
+ newUser.passwords = { password: '1234', repeatPassword: '1234' };
+ const response = await CentralServerService.defaultInstance.authenticationApi.registerUser(newUser, testData.adminTenant);
+ // Check
+ expect(response.status).to.be.eql(StatusCodes.INTERNAL_SERVER_ERROR);
+ expect(response.data).to.not.have.property('token');
+ });
+
it('Should not allow authentication of known user with wrong password', async () => {
// Call
const response = await CentralServerService.defaultInstance.authenticationApi.login(testData.adminEmail, 'A_M4tch1ng_P4ssw0rd', true);

Added tests on auth service