use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class CertificateActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(CertificateModel resource) {
ValidationResponseModel responseModel;
if (StringUtils.isNotBlank(resource.getId()) && !NumberUtils.isCreatable(resource.getId())) {
responseModel = ValidationResponseModel.generalError("Invalid resource id");
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
List<AlertFieldStatus> fieldErrors = validateCertificateFields(resource);
if (fieldErrors.isEmpty()) {
responseModel = ValidationResponseModel.success("The certificate configuration is valid");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the certificate configuration", fieldErrors);
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class UserActionsTest method testTestWithoutChecks.
@Test
public void testTestWithoutChecks() {
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
roleNames.add(DefaultUserRole.ALERT_ADMIN.name());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", emailAddress, roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ValidationActionResponse validationActionResponse = userActions.testWithoutChecks(userConfig);
assertFalse(validationActionResponse.isError());
assertTrue(validationActionResponse.hasContent());
assertFalse(validationActionResponse.getContent().get().hasErrors());
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class RoleActionsTest method validateTest.
@Test
public void validateTest() {
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel));
Mockito.when(roleAccessor.doesRoleNameExist(Mockito.eq(roleName))).thenReturn(false);
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ValidationActionResponse validationActionResponse = roleActions.validate(rolePermissionModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class RoleActionsTest method validateBadRequestTest.
@Test
public void validateBadRequestTest() {
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel));
Mockito.when(roleAccessor.doesRoleNameExist(Mockito.eq(roleName))).thenReturn(true);
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ValidationActionResponse validationActionResponse = roleActions.validate(rolePermissionModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.
the class UserActionsTest method testExternalUserNoEmailValidation.
@Test
public void testExternalUserNoEmailValidation() throws Exception {
AuthenticationType authenticationTypeLDAP = AuthenticationType.LDAP;
UserModel userModel = UserModel.existingUser(id, name, password, null, authenticationTypeLDAP, roles, true);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
roleNames.add(DefaultUserRole.ALERT_ADMIN.name());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", null, roleNames, false, false, false, true, false, authenticationTypeLDAP.name(), true);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ValidationActionResponse validationActionResponse = userActions.validate(userConfig);
assertFalse(validationActionResponse.isError());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertFalse(validationResponseModel.hasErrors());
assertEquals("The user is valid", validationActionResponse.getMessage().get());
}
Aggregations