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

Adding autofixAvailable flag to the noncompliance api endpoint, code … #1028

Merged
merged 1 commit into from
Mar 31, 2023
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
603 changes: 295 additions & 308 deletions api/pacman-api-asset/pom.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions api/pacman-api-compliance/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ spring:
password: ${CONFIG_PASSWORD}
username: user
label: latest

profiles:
active: ${ENVIRONMENT:prd}

autoconfigure:
exclude: org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration

security:
security:
oauth2:
resource:
jwk:
key-set-uri: https://cognito-idp.${AWS_USERPOOL_REGION}.amazonaws.com/${USERPOOL_ID}/.well-known/jwks.json
client:
clientId: ${CLIENT_ID}

query:
assetGroupQuery: SELECT groupName, targetType, attributeName, attributeValue, dataSource, aliasQuery FROM cf_AssetGroups
assetGroupQuery: SELECT groupName, targetType, attributeName, attributeValue, dataSource, aliasQuery FROM cf_AssetGroups

spring.jpa.hibernate.naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Original file line number Diff line number Diff line change
Expand Up @@ -215,35 +215,35 @@ public void revokeIssueExceptionFalseTest() throws Exception {

@Test
public void getNonCompliancePolicyByPolicyTest() throws Exception {
when(complianceService.getPolicycompliance(anyObject())).thenReturn(CommonTestUtil.getResponseWithOrder());
when(complianceService.getPolicyCompliance(anyObject())).thenReturn(CommonTestUtil.getResponseWithOrder());
assertThat(complianceController.getNonCompliancePolicyByPolicy(CommonTestUtil.getRequest()), is(notNullValue()));
assertThat(complianceController.getNonCompliancePolicyByPolicy(CommonTestUtil.getRequestEmpty()), is(notNullValue()));

when(complianceService.getPolicycompliance(anyObject())).thenThrow(new ServiceException());
when(complianceService.getPolicyCompliance(anyObject())).thenThrow(new ServiceException());
when(complianceService.formatException(anyObject())).thenReturn(ResponseUtils.buildFailureResponse(new ServiceException()));
ResponseEntity<Object> responseObj = complianceController.getNonCompliancePolicyByPolicy(CommonTestUtil.getRequest());
assertTrue(responseObj.getStatusCode() == HttpStatus.EXPECTATION_FAILED);
}

@Test
public void getPolicydetailsbyApplicationTest() throws Exception {
when(complianceService.getPolicyDetailsbyApplication(anyString(),anyString(),anyString())).thenReturn(CommonTestUtil.getListMapObject());
when(complianceService.getPolicyDetailsByApplication(anyString(),anyString(),anyString())).thenReturn(CommonTestUtil.getListMapObject());
assertThat(complianceController.getPolicydetailsbyApplication("ag","policyId","searchText"), is(notNullValue()));
assertThat(complianceController.getPolicydetailsbyApplication("","",""), is(notNullValue()));

when(complianceService.getPolicyDetailsbyApplication(anyString(),anyString(),anyString())).thenThrow(new ServiceException());
when(complianceService.getPolicyDetailsByApplication(anyString(),anyString(),anyString())).thenThrow(new ServiceException());
when(complianceService.formatException(anyObject())).thenReturn(ResponseUtils.buildFailureResponse(new ServiceException()));
ResponseEntity<Object> responseObj = complianceController.getPolicydetailsbyApplication("ag","policyId","searchText");
assertTrue(responseObj.getStatusCode() == HttpStatus.EXPECTATION_FAILED);
}

@Test
public void getpolicydetailsbyEnvironmentTest() throws Exception {
when(complianceService.getPolicyDetailsbyEnvironment(anyString(),anyString(),anyString(),anyString())).thenReturn(CommonTestUtil.getListMapObject());
when(complianceService.getPolicyDetailsByEnvironment(anyString(),anyString(),anyString(),anyString())).thenReturn(CommonTestUtil.getListMapObject());
assertThat(complianceController.getpolicydetailsbyEnvironment("ag","policyId","application","searchText"), is(notNullValue()));
assertThat(complianceController.getpolicydetailsbyEnvironment("","","",""), is(notNullValue()));

when(complianceService.getPolicyDetailsbyEnvironment(anyString(),anyString(),anyString(),anyString())).thenThrow(new ServiceException());
when(complianceService.getPolicyDetailsByEnvironment(anyString(),anyString(),anyString(),anyString())).thenThrow(new ServiceException());
when(complianceService.formatException(anyObject())).thenReturn(ResponseUtils.buildFailureResponse(new ServiceException()));
ResponseEntity<Object> responseObj = complianceController.getpolicydetailsbyEnvironment("ag","policyId","application","searchText");
assertTrue(responseObj.getStatusCode() == HttpStatus.EXPECTATION_FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ public void getPolicycomplianceTest() throws Exception {
anyInt(), anyString())).thenReturn(
CommonTestUtil.getMapLong());

assertThat(complianceService.getPolicycompliance(CommonTestUtil
assertThat(complianceService.getPolicyCompliance(CommonTestUtil
.getRequest()), is(notNullValue()));
}

@Test
public void getPolicycomplianceWithoutPolicyIdTest() throws Exception {
assertThat(complianceService.getPolicycompliance(CommonTestUtil
assertThat(complianceService.getPolicyCompliance(CommonTestUtil
.getRequest()), is(nullValue()));
}

Expand Down Expand Up @@ -383,23 +383,23 @@ public void getPolicyDetailsbyApplicationTest() throws Exception {
CommonTestUtil.getMapLong());

assertThat(
complianceService.getPolicyDetailsbyApplication(
complianceService.getPolicyDetailsByApplication(
"dummyString",
"PacMan_cloud-kernel-compliance_version-1_Ec2-Kernel-Compliance-Policy_ec2",
"dummyString"), is(notNullValue()));

assertThat(
complianceService.getPolicyDetailsbyApplication(
complianceService.getPolicyDetailsByApplication(
"dummyString",
"PacMan_onpremisekernelversion_version-1_onpremKernelVersionPolicy_onpremserver",
"dummyString"), is(notNullValue()));

assertThat(
complianceService.getPolicyDetailsbyApplication(
complianceService.getPolicyDetailsByApplication(
"dummyString",
"PacMan_Ec2InstanceScannedByQualys_version-1_Ec2-instance-scanned-by-qualys-API_ec2",
"dummyString"), is(notNullValue()));
assertThat(complianceService.getPolicyDetailsbyApplication("dummyString",
assertThat(complianceService.getPolicyDetailsByApplication("dummyString",
"", "dummyString"), is(notNullValue()));

}
Expand All @@ -425,25 +425,25 @@ public void getPolicyDetailsbyEnvironmentTest() throws Exception {
anyString(), anyString(),anyString(), anyString(),anyString())).thenReturn(5000l);

assertThat(
complianceService.getPolicyDetailsbyEnvironment(
complianceService.getPolicyDetailsByEnvironment(
"dummyString",
"PacMan_cloud-kernel-compliance_version-1_Ec2-Kernel-Compliance-Policy_ec2",
"", "dummyString"), is(notNullValue()));

assertThat(
complianceService.getPolicyDetailsbyEnvironment(
complianceService.getPolicyDetailsByEnvironment(
"dummyString",
"PacMan_onpremisekernelversion_version-1_onpremKernelVersionPolicy_onpremserver",
"", "dummyString"), is(notNullValue()));
assertThat(complianceService.getPolicyDetailsbyEnvironment("dummyString",
assertThat(complianceService.getPolicyDetailsByEnvironment("dummyString",
"", "", "dummyString"), is(notNullValue()));

assertThat(
complianceService.getPolicyDetailsbyEnvironment(
complianceService.getPolicyDetailsByEnvironment(
"dummyString",
"PacMan_Ec2InstanceScannedByQualys_version-1_Ec2-instance-scanned-by-qualys-API_ec2",
"dummyString",""), is(notNullValue()));
assertThat(complianceService.getPolicyDetailsbyEnvironment("dummyString",
assertThat(complianceService.getPolicyDetailsByEnvironment("dummyString",
"", "","dummyString"), is(notNullValue()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void getTrendProgressTest() throws Exception {
when(complianceService.getCertificates(anyString()))
.thenReturn(taggingInfoMap);

when(complianceService.getPolicycompliance(anyObject()))
when(complianceService.getPolicyCompliance(anyObject()))
.thenReturn(CommonTestUtil.getResponseWithOrder());

when(complianceService.getPatching(anyString(),anyString(),anyString()))
Expand Down Expand Up @@ -139,7 +139,7 @@ public void getTrendIssuesTest() throws Exception {
when(complainceRepository.getPolicyIdWithDisplayNameQuery(anyString()))
.thenReturn(CommonTestUtil.getListMapObject());

when(complianceService.getPoliciesevCatDetails(anyObject()))
when(complianceService.getPoliciesCatDetails(anyObject()))
.thenReturn(CommonTestUtil.getListMapObject());

when(repository.getTrendIssues(anyString(),anyObject(),anyObject(),anyObject(),anyObject()))
Expand All @@ -162,7 +162,7 @@ public void getComplianceTrendProgressTest() throws Exception {
when(complainceRepository.getPolicyIdWithDisplayNameQuery(anyString()))
.thenReturn(CommonTestUtil.getListMapObject());

when(complianceService.getPoliciesevCatDetails(anyObject()))
when(complianceService.getPoliciesCatDetails(anyObject()))
.thenReturn(CommonTestUtil.getListMapObject());

when(repository.getComplianceTrendProgress(anyString(),anyObject(),anyString(),anyObject()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
/*******************************************************************************
/**
* Copyright 2018 T Mobile, Inc. or its affiliates. All Rights Reserved.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
* <p>
* Copyright (C) 2017 T Mobile Inc - All Rights Reserve
* Purpose:
* Author :kkumar
* Modified Date: Oct 18, 2017
**/
/**
Copyright (C) 2017 T Mobile Inc - All Rights Reserve
Purpose:
Author :kkumar
Modified Date: Oct 18, 2017
**/
Copyright (C) 2017 T Mobile Inc - All Rights Reserve
Purpose:
Author :kkumar
Modified Date: Oct 18, 2017
**/
package com.tmobile.pacman.api.commons;

public interface Constants {

Integer ES_PAGE_SIZE = 10000;
String ES_PAGE_SCROLL_TTL = "2m";
String ES_DOC_ID_KEY = "_id";
Expand All @@ -46,7 +50,7 @@ public interface Constants {
String INCLUDE_EXEMPT = "include_exempt";
String SEVERITY = "severity";
String NAME = "name";
String COMPLIANCEPERCENT="compliance-percent";
String COMPLIANCEPERCENT = "compliance-percent";
String POLICYID = "policyId";
String OPEN_ISSUES = "openIssues";
String EC2_MANDATORY_TAG_RULE = "ec2mandatorytags_version-1_ec2mandatorytags_ec2";
Expand All @@ -59,6 +63,7 @@ public interface Constants {
String POLICY_NAME = "policyName";
String DISPLAY_NAME = "policyDisplayName";
String ASSETS_SCANNED = "assetsScanned";
String ASSETS = "assets";
String PASSED = "passed";
String FAILED = "failed";
String POLICY_DISPAY_NAME = "policyDisplayName";
Expand Down Expand Up @@ -87,14 +92,22 @@ public interface Constants {
String _ID = "_id";
String ID = "id";
String EXEMPTED = "exempted";
String IS_ASSETS_EXEMPTED = "isAssetsExempted";
String MODIFIED_DATE = "modifiedDate";
String PAC_DS = "pac_ds";
String POLICY_VIOLATION = "#violation";
String CONTRIBUTION = "contribution";
String CONTRIBUTION_PERCENT = "contribution_percent";
String COMPLIANCE_PERCENTAGE = "compliance";
String COMPLIANCE_PERCENT = "compliance_percent";
String LAST_SCAN = "lastScan";
String CATEGORY_TAGGING = "tagging";
String TAGGED = "tagged";
String POLICY_DETAILS_BY_ENVIRONMENT = "policydetailsbyenvironment";
String POLICY_DETAILS_BY_APPLICATION = "policydetailsbyapplication";
String NON_COMPLIANCE_POLICY = "noncompliancepolicy";
String OVERALL = "overall";
String TOTAL_ISSUES = "total_issues";
String TAGS_APPLICATION = "tags.Application";
String MISSING_TAGS = "missingTags";
String ACCOUNT_ID = "accountid";
Expand Down Expand Up @@ -159,7 +172,9 @@ public interface Constants {
String VALID_TO = "validto";
String UNDERSCORE_COUNT = "_count";
String ISSUE_DETAILS = "issueDetails";
String QUALYS_DETAILS = "qualysIssueDetails";
String QUALYS_ISSUE_DETAILS = "qualysIssueDetails";
String QUALYS_VIOLATION_DETAILS = "qualysViolationDetails";
String VIOLATION_REASON = "violationReason";
String SEARCH = "_search";
String INFRA_AND_PLATFORMS = "Infra & Platforms";
String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
Expand All @@ -177,9 +192,8 @@ public interface Constants {
String MUST = "must";
String DIRECTOR = "director";
String EXCUTIVE_SPONSOR = "executiveSponsor";
String UNPATCHED_INSTANCE = "unpatched_instances";
String NO_DATA_FOUND = "No Data Found";
String UNPATCHED_INSTANCES = "unpatched_instances";
String NO_DATA_FOUND = "No Data Found";
String TOTAL_INSTANCES = "total_instances";
String PATCHING_PERCENTAGE = "patching_percentage";
String EC2 = "ec2";
Expand All @@ -194,7 +208,7 @@ public interface Constants {
String RANGE = "range";
String AG_STATS = "assetgroup_stats";
String VULN_INFO = "vulninfo";
String APPS = "application";;
String APPS = "application";
String SCROLL = "?scroll=";
String SLASH_SCROLL = "/scroll";
String TAGS_APPS = "tags.Application.keyword";
Expand All @@ -213,11 +227,12 @@ public interface Constants {
int ELEVEN = 11;
String COMPLAINT = "compliant";
String NON_COMPLIANT = "noncompliant";
String NON_COMPLIANT_KEY = "non-compliant";
int NINE_THOUSAND_THREE_HUNDRED = 9300;
String NON_COMPLIANT_NUMBER = "nonCompliantNumber";
String APP_TAG = "appTag";
String KERNEL_RELEASE = "kernel_release";
String PATCHED_INSTANCE = "patched_instances";
String PATCHED_INSTANCES = "patched_instances";
String START_DATE = "start_date";
String END_DATE = "end_date";
String INSTANCE_ID = "instanceid";
Expand Down Expand Up @@ -332,6 +347,7 @@ public interface Constants {
String UNABLE_TO_DETERMINE = "unable to determine";
String STATUS_REASON = "status-reason";
String AUTOFIX_ENABLED = "autoFixEnabled";
String AUTOFIX_AVAILABLE = "autoFixAvailable";
String AUTOFIX = "autofix";
String AQUA = "aqua";
}