Search in sources :

Example 21 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class AzureBoardsWorkItemFinderTest method verifyQueryWhereStatementTruncated.

@Test
public void verifyQueryWhereStatementTruncated() throws AlertException {
    AzureBoardsIssueTrackerQueryManager azureBoardsIssueTrackerQueryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
    ArgumentCaptor<WorkItemQuery> workItemQueryArgumentCaptor = ArgumentCaptor.forClass(WorkItemQuery.class);
    String teamProjectName = "team project name";
    AzureBoardsWorkItemFinder azureBoardsWorkItemFinder = new AzureBoardsWorkItemFinder(azureBoardsIssueTrackerQueryManager, teamProjectName);
    LinkableItem provider = new LinkableItem("providerLabel", "providerValue");
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    String componentKey = StringUtils.repeat("componentKey", 100);
    String subTopicKey = "subTopicKey";
    String additionalInfoKey = "additionalInfoKey";
    AzureSearchFieldMappingBuilder azureSearchFieldMappingBuilder = AzureSearchFieldMappingBuilder.create().addComponentKey(componentKey).addSubTopic(subTopicKey).addAdditionalInfoKey(additionalInfoKey);
    Mockito.doReturn(List.of()).when(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(Mockito.any());
    azureBoardsWorkItemFinder.findWorkItems(provider, project, azureSearchFieldMappingBuilder);
    Mockito.verify(azureBoardsIssueTrackerQueryManager).executeQueryAndRetrieveWorkItems(workItemQueryArgumentCaptor.capture());
    WorkItemQuery workItemQuery = workItemQueryArgumentCaptor.getValue();
    assertNotNull(workItemQuery);
    assertFalse(workItemQuery.exceedsCharLimit());
    Map<String, String> whereClauseValues = extractValuesFromWhereClause(workItemQuery.rawQuery());
    assertTrue(whereClauseValues.size() > 3);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
    assertQueryDataFound(whereClauseValues, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfoKey);
    String component = whereClauseValues.get(AzureCustomFieldManager.ALERT_COMPONENT_KEY_FIELD_REFERENCE_NAME);
    assertNotNull(component);
    // This is Azure boards custom field size limit
    String truncatedComponent = StringUtils.truncate(componentKey, 256);
    assertEquals(truncatedComponent, component);
}
Also used : WorkItemQuery(com.synopsys.integration.azure.boards.common.service.query.fluent.WorkItemQuery) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) AzureBoardsIssueTrackerQueryManager(com.synopsys.integration.alert.channel.azure.boards.distribution.AzureBoardsIssueTrackerQueryManager) Test(org.junit.jupiter.api.Test)

Example 22 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class MessageContentGroupCsvCreator method createCsvString.

public String createCsvString(MessageContentGroup messageContentGroup) {
    LinkableItem commonProvider = messageContentGroup.getCommonProvider();
    LinkableItem commonProject = messageContentGroup.getCommonTopic();
    List<ProviderMessageContent> contents = messageContentGroup.getSubContent();
    StringBuilder csvBuilder = new StringBuilder();
    List<String> columnNames = createColumnNames(commonProject, contents);
    appendLine(csvBuilder, columnNames);
    List<List<String>> rowValues = createRowValues(commonProvider, commonProject, contents);
    for (List<String> row : rowValues) {
        appendLine(csvBuilder, row);
    }
    return csvBuilder.toString();
}
Also used : ProviderMessageContent(com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class MessageContentGroupCsvCreator method createRowValues.

private List<List<String>> createRowValues(LinkableItem commonProvider, LinkableItem commonTopic, List<ProviderMessageContent> contents) {
    List<List<String>> rows = new ArrayList<>();
    for (ProviderMessageContent message : contents) {
        String subTopicValue = createOptionalValueString(message.getSubTopic(), LinkableItem::getValue);
        Set<ComponentItem> componentItems = extractComponentItemsOrDefault(message);
        for (ComponentItem componentItem : componentItems) {
            List<String> columnValues = createColumnValues(commonProvider.getLabel(), commonProvider.getValue(), commonTopic.getValue(), subTopicValue, componentItem);
            rows.add(columnValues);
        }
    }
    return rows;
}
Also used : ComponentItem(com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem) ProviderMessageContent(com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class AzureBoardsAlertIssuePropertiesManagerTest method verifyValidVulnIssuesAreCreated.

@Test
public void verifyValidVulnIssuesAreCreated() {
    AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
    LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
    ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    LinkableItem projectVersion = new LinkableItem("projectVersionLabel", "projectVersionValue");
    LinkableItem component = new LinkableItem("componentLabel", "componentValue");
    LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
    IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
    IssueVulnerabilityDetails issueVulnerabilityDetails = new IssueVulnerabilityDetails(false, List.of(IssueVulnerabilityModel.fromComponentConcern(ComponentConcern.vulnerability(ItemOperation.ADD, "vulnerabilityId", ComponentConcernSeverity.CRITICAL, "vulnerabilityUrl"))), List.of(), List.of());
    ProjectIssueModel vulnerability = ProjectIssueModel.vulnerability(providerDetails, project, projectVersion, issueBomComponentDetails, issueVulnerabilityDetails);
    List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(vulnerability);
    LinkableItem provider = providerDetails.getProvider();
    String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL);
    String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(vulnerability.getProjectVersion().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) Test(org.junit.jupiter.api.Test)

Example 25 with LinkableItem

use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.

the class AzureBoardsAlertIssuePropertiesManagerTest method verifyPolicyIssuesAreCreatedWithTruncatedPropertyValues.

@Test
public void verifyPolicyIssuesAreCreatedWithTruncatedPropertyValues() {
    AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
    LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
    ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
    LinkableItem project = new LinkableItem("projectLabel", "projectValue");
    LinkableItem projectVersion = new LinkableItem("projectVersionLabel", StringUtils.repeat("projectVersionValue", 100));
    LinkableItem component = new LinkableItem("componentLabel", "componentValue");
    LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
    IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
    IssuePolicyDetails issuePolicyDetails = new IssuePolicyDetails("policy", ItemOperation.ADD, ComponentConcernSeverity.CRITICAL);
    ProjectIssueModel policy = ProjectIssueModel.policy(providerDetails, project, projectVersion, issueBomComponentDetails, issuePolicyDetails);
    List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(policy);
    LinkableItem provider = providerDetails.getProvider();
    String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
    String additionalInfo = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + issuePolicyDetails.getName();
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfo);
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL);
    // This should trim the contents of the linkableitem
    String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(policy.getProjectVersion().orElse(null));
    assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
    WorkItemElementOperationModel workItem = workItemRequestCustomFieldOperations.stream().filter(workItemElementOperationModel -> StringUtils.endsWith(workItemElementOperationModel.getPath(), AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME)).findFirst().orElse(null);
    assertNotNull(workItem);
    Object workItemValue = workItem.getValue();
    assertEquals(subTopicKey, workItemValue);
    // Ensures that we don't push values that are larger than azure allows for custom fields
    assertEquals(256, workItemValue.toString().length());
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) WorkItemElementOperationModel(com.synopsys.integration.azure.boards.common.service.workitem.request.WorkItemElementOperationModel) Test(org.junit.jupiter.api.Test)

Aggregations

LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)94 Test (org.junit.jupiter.api.Test)39 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)26 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)22 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)18 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)15 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)11 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)11 ArrayList (java.util.ArrayList)11 LinkedList (java.util.LinkedList)11 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)9 List (java.util.List)9 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)8 Optional (java.util.Optional)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)6 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)6