@Test public void testVerifyIfRoleBasedCredentialVerificationShouldFailWhenItIsCredentialCreationAndRoleIsAssumableWithoutExternalId() throws AwsPermissionMissingException { String roleArn = "someRoleArn"; when(credentialView.getRoleArn()).thenReturn(roleArn); CloudCredentialStatus result = underTest.verify(authenticatedContext, new CredentialVerificationContext(Boolean.TRUE)); assertNotNull(result); assertEquals(CredentialStatus.FAILED, result.getStatus()); assertEquals(AwsConfusedDeputyException.class, result.getException().getClass()); verify(awsCredentialVerifier, times(0)).validateAws(any()); verify(awsCredentialVerifier, times(0)).validateAws(credentialView); }
@Override public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext) { CloudCredential credential = authenticatedContext.getCloudCredential(); LOGGER.debug("Create credential: {}", credential); AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(credential); String roleArn = awsCredential.getRoleArn(); String accessKey = awsCredential.getAccessKey(); String secretKey = awsCredential.getSecretKey(); CloudCredentialStatus result; if (isNoneEmpty(roleArn, accessKey, secretKey)) { String message = "Please only provide the 'role arn' or the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else if (isNotEmpty(roleArn)) { result = verifyIamRoleIsAssumable(credential, credentialVerificationContext); } else if (isEmpty(accessKey) || isEmpty(secretKey)) { String message = "Please provide both the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else { result = verifyAccessKeySecretKeyIsAssumable(credential); } return result; }
AwsCredentialConnector implements CredentialConnector { @Override public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext) { CloudCredential credential = authenticatedContext.getCloudCredential(); LOGGER.debug("Create credential: {}", credential); AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(credential); String roleArn = awsCredential.getRoleArn(); String accessKey = awsCredential.getAccessKey(); String secretKey = awsCredential.getSecretKey(); CloudCredentialStatus result; if (isNoneEmpty(roleArn, accessKey, secretKey)) { String message = "Please only provide the 'role arn' or the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else if (isNotEmpty(roleArn)) { result = verifyIamRoleIsAssumable(credential, credentialVerificationContext); } else if (isEmpty(accessKey) || isEmpty(secretKey)) { String message = "Please provide both the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else { result = verifyAccessKeySecretKeyIsAssumable(credential); } return result; } }
AwsCredentialConnector implements CredentialConnector { @Override public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext) { CloudCredential credential = authenticatedContext.getCloudCredential(); LOGGER.debug("Create credential: {}", credential); AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(credential); String roleArn = awsCredential.getRoleArn(); String accessKey = awsCredential.getAccessKey(); String secretKey = awsCredential.getSecretKey(); CloudCredentialStatus result; if (isNoneEmpty(roleArn, accessKey, secretKey)) { String message = "Please only provide the 'role arn' or the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else if (isNotEmpty(roleArn)) { result = verifyIamRoleIsAssumable(credential, credentialVerificationContext); } else if (isEmpty(accessKey) || isEmpty(secretKey)) { String message = "Please provide both the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else { result = verifyAccessKeySecretKeyIsAssumable(credential); } return result; }  }
AwsCredentialConnector implements CredentialConnector { @Override public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext) { CloudCredential credential = authenticatedContext.getCloudCredential(); LOGGER.debug("Create credential: {}", credential); AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(credential); String roleArn = awsCredential.getRoleArn(); String accessKey = awsCredential.getAccessKey(); String secretKey = awsCredential.getSecretKey(); CloudCredentialStatus result; if (isNoneEmpty(roleArn, accessKey, secretKey)) { String message = "Please only provide the 'role arn' or the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else if (isNotEmpty(roleArn)) { result = verifyIamRoleIsAssumable(credential, credentialVerificationContext); } else if (isEmpty(accessKey) || isEmpty(secretKey)) { String message = "Please provide both the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else { result = verifyAccessKeySecretKeyIsAssumable(credential); } return result; }  @Override CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext); @Override CloudCredentialStatus create(AuthenticatedContext auth); @Override CloudCredentialStatus delete(AuthenticatedContext auth); @Override CredentialPrerequisitesResponse getPrerequisites(CloudContext cloudContext, String externalId, String deploymentAddress, CredentialType type); }
AwsCredentialConnector implements CredentialConnector { @Override public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext) { CloudCredential credential = authenticatedContext.getCloudCredential(); LOGGER.debug("Create credential: {}", credential); AwsCredentialView awsCredential = credentialViewProvider.createAwsCredentialView(credential); String roleArn = awsCredential.getRoleArn(); String accessKey = awsCredential.getAccessKey(); String secretKey = awsCredential.getSecretKey(); CloudCredentialStatus result; if (isNoneEmpty(roleArn, accessKey, secretKey)) { String message = "Please only provide the 'role arn' or the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else if (isNotEmpty(roleArn)) { result = verifyIamRoleIsAssumable(credential, credentialVerificationContext); } else if (isEmpty(accessKey) || isEmpty(secretKey)) { String message = "Please provide both the 'access' and 'secret key'"; result = new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message); } else { result = verifyAccessKeySecretKeyIsAssumable(credential); } return result; }  @Override CloudCredentialStatus verify(AuthenticatedContext authenticatedContext, CredentialVerificationContext credentialVerificationContext); @Override CloudCredentialStatus create(AuthenticatedContext auth); @Override CloudCredentialStatus delete(AuthenticatedContext auth); @Override CredentialPrerequisitesResponse getPrerequisites(CloudContext cloudContext, String externalId, String deploymentAddress, CredentialType type);  }