Skip to content

Commit

Permalink
fix(ecs): Ensure null is returned when account does not exist (#5092)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
nabuskey and mergify[bot] committed Nov 10, 2020
1 parent 10202d9 commit de10c06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public void removeMapEntry(String ecsAccountName) {
}

public NetflixECSCredentials fromAwsAccountNameToEcs(String awsAccountName) {
return credentialsRepository.getOne(ecsCredentialsMap.get(awsAccountName));
String ecsAccountName = ecsCredentialsMap.get(awsAccountName);
if (ecsAccountName == null) {
return null;
}
return credentialsRepository.getOne(ecsAccountName);
}

public NetflixAmazonCredentials fromEcsAccountNameToAws(String ecsAccountName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,15 @@ class EcsAccountMapperSpec extends Specification {
!ecsAccountMapper.ecsCredentialsMap.containsKey(ecsAccountName)
!ecsAccountMapper.awsCredentialsMap.containsKey(awsAccount)
}

def 'should return null if provided name is invalid'() {
given:
def ecsAccountMapper = new EcsAccountMapper(credentialsRepository, compositeCredentialsRepository)

when:
def result = ecsAccountMapper.fromAwsAccountNameToEcs("invalid")

then:
result == null
}
}

0 comments on commit de10c06

Please sign in to comment.