Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Update authorType check (#48)
Browse files Browse the repository at this point in the history
* Update authorType check

* Make ldapdnCheckIgnoredAuthorTypes a list

* Initlizate ignoredAuthorType list
  • Loading branch information
chzhanpeng authored Jul 6, 2020
1 parent c78d4b1 commit a68a8a8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>api-audit</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>3.3.5-SNAPSHOT</version>
<version>3.3.6-SNAPSHOT</version>
<description>Hygieia Audit Rest API Layer</description>
<url>https://github.com/Hygieia/${repository.name}</url>

Expand Down Expand Up @@ -59,7 +59,7 @@
<properties>
<repository.name>api-audit</repository.name>
<java.version>1.8</java.version>
<com.capitalone.dashboard.core.version>3.7.9</com.capitalone.dashboard.core.version>
<com.capitalone.dashboard.core.version>3.7.11</com.capitalone.dashboard.core.version>
<bc.version>3.0.2</bc.version>
<application.version.number>${version}</application.version.number>
<apache.rat.plugin.version>0.13</apache.rat.plugin.version>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/capitalone/dashboard/ApiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
Expand Down Expand Up @@ -46,6 +47,7 @@ public class ApiSettings {
@Value("${criticalLicenseVulnerabilitiesAge:0}")
private int criticalLicenseVulnerabilitiesAge;
private List<String> buildStageRegEx;
private List<String> ldapdnCheckIgnoredAuthorTypes = new ArrayList<>();

public String getKey() {
return key;
Expand Down Expand Up @@ -223,5 +225,12 @@ public void setBuildStageRegEx(List<String> buildStageRegEx) {
this.buildStageRegEx = buildStageRegEx;
}

public List<String> getLdapdnCheckIgnoredAuthorTypes() {
return ldapdnCheckIgnoredAuthorTypes;
}

public void setLdapdnCheckIgnoredAuthorTypes(List<String> ldapdnCheckIgnoredAuthorTypes) {
this.ldapdnCheckIgnoredAuthorTypes = ldapdnCheckIgnoredAuthorTypes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.capitalone.dashboard.ApiSettings;
import com.capitalone.dashboard.common.CommonCodeReview;
import com.capitalone.dashboard.model.AuthorType;
import com.capitalone.dashboard.model.Collector;
import com.capitalone.dashboard.model.CollectorItem;
import com.capitalone.dashboard.model.CollectorType;
Expand Down Expand Up @@ -222,10 +221,11 @@ private CodeReviewAuditResponseV2 getPeerReviewResponses(CollectorItem repoItem,
* Adds SCM_AUTHOR_LOGIN_INVALID status at Code Review level
*/
private void checkCommitByLDAPUnauthUser(CodeReviewAuditResponseV2 reviewAuditResponseV2, Commit commit) {
if (StringUtils.isNotEmpty(commit.getScmAuthorType()) && settings.getLdapdnCheckIgnoredAuthorTypes().contains(commit.getScmAuthorType())) {
return;
}
if (StringUtils.isEmpty(commit.getScmAuthorLDAPDN()) &&
!CommonCodeReview.matchIncrementVersionTag(commit.getScmCommitLog(), settings) &&
commit.getScmAuthorType() != null &&
!commit.getScmAuthorType().equals(AuthorType.Bot)) {
!CommonCodeReview.matchIncrementVersionTag(commit.getScmCommitLog(), settings)) {
reviewAuditResponseV2.addAuditStatus(CodeReviewAuditStatus.SCM_AUTHOR_LOGIN_INVALID);
// add commit made by unauth user to commitsByLDAPUnauthUsers list
reviewAuditResponseV2.addCommitByLDAPUnauthUser(commit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.capitalone.dashboard.ApiSettings;
import com.capitalone.dashboard.common.TestConstants;
import com.capitalone.dashboard.model.AuthorType;
import com.capitalone.dashboard.model.CollectionError;
import com.capitalone.dashboard.model.CollectorItem;
import com.capitalone.dashboard.model.Commit;
Expand Down Expand Up @@ -368,7 +367,7 @@ public void checkCommitByBotTest() {
when(gitRequestRepository.findByCollectorItemIdAndMergedAtIsBetween(any(ObjectId.class),any(Long.class), any(Long.class))).thenReturn(pullRequestList);
when(commitRepository.findByCollectorItemIdAndScmCommitTimestampIsBetween(any(ObjectId.class),any(Long.class), any(Long.class))).thenReturn(commitsList);
when(apiSettings.getServiceAccountOU()).thenReturn(TestConstants.USER_ACCOUNTS);
when(apiSettings.getServiceAccountOU()).thenReturn(TestConstants.USER_ACCOUNTS);
when(apiSettings.getLdapdnCheckIgnoredAuthorTypes()).thenReturn(Arrays.asList("Bot"));
when(apiSettings.getCommitLogIgnoreAuditRegEx()).thenReturn("(.)*(Increment_Version_Tag)(.)*");
when(serviceAccountRepository.findAll()).thenReturn(Stream.of(makeServiceAccount()).collect(Collectors.toList()));

Expand Down Expand Up @@ -580,7 +579,7 @@ private Commit makeUnauthCommit(String message, String scmRevisionNumber, String
c.setScmRevisionNumber(scmRevisionNumber);
c.setType(CommitType.New);
c.setScmAuthor(author);
c.setScmAuthorType(AuthorType.fromString(authorType));
c.setScmAuthorType(authorType);
c.setScmAuthorLogin("unknown");
c.setScmCommitterLogin(committer);
c.setScmCommitTimestamp(timeStamp);
Expand Down

0 comments on commit a68a8a8

Please sign in to comment.