use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class JiraServerGlobalCrudActionsTestIT method init.
@BeforeEach
public void init() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.JIRA_SERVER;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method validateBadRequestTest.
@Test
public void validateBadRequestTest() {
Descriptor descriptorWithValidator = createDescriptor(Optional::empty, () -> Optional.of(jobFieldModel -> Set.of()));
JobConfigActions jobConfigActionsForTest = createJobConfigActions(new DescriptorMap(List.of(descriptorKey), List.of(descriptorWithValidator)), List.of());
Mockito.when(mockedJobAccessor.getJobByName(Mockito.anyString())).thenReturn(Optional.of(distributionJobModel));
ValidationActionResponse validationActionResponse = jobConfigActionsForTest.validate(jobFieldModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors(), "Expected validation response to have errors");
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method validateTest.
@Test
public void validateTest() {
Descriptor descriptorWithValidator = createDescriptor(Optional::empty, () -> Optional.of(jobFieldModel -> Set.of()));
JobConfigActions jobConfigActionsForTest = createJobConfigActions(new DescriptorMap(List.of(descriptorKey), List.of(descriptorWithValidator)), List.of());
ValidationActionResponse validationActionResponse = jobConfigActionsForTest.validate(jobFieldModel);
assertTrue(validationActionResponse.isSuccessful());
assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertFalse(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class ConfigurationFieldModelTest method convertDefinedFieldModelTest.
@Test
public void convertDefinedFieldModelTest() throws Exception {
List<DefinedFieldModel> configFields = createConfigFields();
EncryptionUtility encryptionUtility = Mockito.mock(EncryptionUtility.class);
Mockito.when(encryptionUtility.isInitialized()).thenReturn(true);
DescriptorAccessor descriptorAccessor = new MockDescriptorAccessor(configFields);
List<DescriptorKey> descriptorKeys = createDescriptorKeyList();
ConfigurationFieldModelConverter modelConverter = new ConfigurationFieldModelConverter(encryptionUtility, descriptorAccessor, descriptorKeys);
Optional<ConfigurationFieldModel> optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, false), VALUE_FIELD_1, true);
assertTrue(optionalModel.isPresent());
ConfigurationFieldModel actualModel = optionalModel.get();
assertEquals(VALUE_FIELD_1, actualModel.getFieldValue().orElseThrow(IllegalArgumentException::new));
assertFalse(actualModel.isSensitive());
assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
optionalModel = modelConverter.convertFromDefinedFieldModel(new DefinedFieldModel(KEY_FIELD_1, ConfigContextEnum.GLOBAL, true), VALUE_FIELD_1, true);
assertTrue(optionalModel.isPresent());
actualModel = optionalModel.get();
assertEquals(VALUE_FIELD_1, actualModel.getFieldValue().orElseThrow(IllegalArgumentException::new));
assertTrue(actualModel.isSensitive());
assertEquals(KEY_FIELD_1, actualModel.getFieldKey());
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class AuthorizationManager method getOperations.
public final Set<Integer> getOperations(ConfigContextEnum context, DescriptorKey descriptorKey) {
PermissionKey permissionKey = new PermissionKey(context.name(), descriptorKey.getUniversalKey());
Collection<String> roleNames = getCurrentUserRoleNames();
return roleNames.stream().filter(permissionCache::containsKey).map(permissionCache::get).map(object -> object.getOperations(permissionKey)).collect(Collectors.toSet());
}
Aggregations