Commit 9cb0f711 authored by Matt Wise's avatar Matt Wise
Browse files

Merge branch 'feat/update-aws' into 'master'

Fix integration tests

See merge request !8
parents 24178f31 a5857dd8
Pipeline #11823 failed with stages
in 50 minutes and 33 seconds
......@@ -11,8 +11,4 @@ analyze:
- name: os-entitlements-aws
type: mvn
target: pom.xml
path: .
- name: Entitlements Functions
type: mvn
target: EntitlementsFunctions/pom.xml
path: .
path: .
\ No newline at end of file
......@@ -25,4 +25,4 @@ include:
# is no javascript to scan, so the job isn't helpful and just gets in the way
eslint-sast:
rules:
- when: never
- when: never
\ No newline at end of file
This diff is collapsed.
......@@ -38,7 +38,7 @@ export DEPLOY_ENV=empty
export AWS_COGNITO_AUTH_FLOW=USER_PASSWORD_AUTH
export AWS_COGNITO_AUTH_PARAMS_USER=$ADMIN_USER
export AWS_COGNITO_AUTH_PARAMS_PASSWORD=$ADMIN_PASSWORD
export MY_TENANT=opendes-int
export ENTITLEMENTS_TEST_TENANT=opendes-int
export DOMAIN=testing.com
......
......@@ -42,14 +42,11 @@ public class EntitlementsApiTests {
envhelper.createCognitoUser(AwsConfig.getAWSCognitoUserPoolID(),AwsConfig.getAWSCognitoTestUsername(),"Password@123",AwsConfig.getAWSCognitoTestUserPassword());
envhelper.add_test_tenant();
envhelper.add_groups();
}
@Test
public void getGroupsTest_ok() throws Exception {
String path = "groups";
ClientResponse response = HTTPUtil.send(path, "GET",
HTTPUtil.getHeaders(), "", "");
......
......@@ -64,7 +64,7 @@ public class AwsConfig {
}
public static String getTenant() {
return getEnvironmentVariableOrDefaultValue("MY_TENANT", "opendes-int");
return getEnvironmentVariableOrDefaultValue("ENTITLEMENTS_TEST_TENANT", "opendes-int");
}
......
......@@ -52,8 +52,11 @@ public class EnvHelper {
AWSCognitoIdentityProvider provider = client.getProvider();
String awsCognitoClientId = AwsConfig.getAWSCognitoClientId();
AuthenticationResultType authenticationResult = null;
AdminCreateUserRequest cognitoRequest = new AdminCreateUserRequest()
try {
AdminCreateUserRequest cognitoRequest = new AdminCreateUserRequest()
.withUserPoolId(userpoolid)
.withUsername(test_username)
.withUserAttributes(
......@@ -67,30 +70,38 @@ public class EnvHelper {
.withMessageAction("SUPPRESS")
.withDesiredDeliveryMediums(DeliveryMediumType.EMAIL)
.withForceAliasCreation(Boolean.FALSE);
AdminCreateUserResult createUserResult = provider.adminCreateUser(cognitoRequest);
UserType cognitoUser = createUserResult.getUser();
AdminCreateUserResult createUserResult = provider.adminCreateUser(cognitoRequest);
String session_token = client.getToken(test_username, temppassword, "session");
UserType cognitoUser = createUserResult.getUser();
String session_token = client.getToken(test_username, temppassword, "session");
//CONFIRM the user
final Map<String, String> challengeResponses = new HashMap<>();
challengeResponses.put("USERNAME", test_username);
challengeResponses.put("NEW_PASSWORD", newpassword);
//populate the challenge response
final AdminRespondToAuthChallengeRequest request =
new AdminRespondToAuthChallengeRequest();
request.withChallengeName(ChallengeNameType.NEW_PASSWORD_REQUIRED)
.withChallengeResponses(challengeResponses)
.withClientId(awsCognitoClientId)
.withUserPoolId(userpoolid)
.withSession(session_token);
//CONFIRM the user
final Map<String, String> challengeResponses = new HashMap<>();
challengeResponses.put("USERNAME", test_username);
challengeResponses.put("NEW_PASSWORD", newpassword);
//populate the challenge response
final AdminRespondToAuthChallengeRequest request =
new AdminRespondToAuthChallengeRequest();
request.withChallengeName(ChallengeNameType.NEW_PASSWORD_REQUIRED)
.withChallengeResponses(challengeResponses)
.withClientId(awsCognitoClientId)
.withUserPoolId(userpoolid)
.withSession(session_token);
AdminRespondToAuthChallengeResult resultChallenge =
provider.adminRespondToAuthChallenge(request);
authenticationResult = resultChallenge.getAuthenticationResult();
AdminRespondToAuthChallengeResult resultChallenge =
provider.adminRespondToAuthChallenge(request);
authenticationResult = resultChallenge.getAuthenticationResult();
}
catch (Exception e) {
System.out.println(e);
throw e;
}
}
......@@ -124,44 +135,52 @@ public class EnvHelper {
public void add_groups() {
System.out.println("Adding the test groups to user: "+AwsConfig.getAWSCognitoTestUsername()+" now..");
String tableName = tablePrefix + "-" + "Groups";
Table table = dynamoDB.getTable(tableName);
List<String> groups = new ArrayList<String>();
groups.add("data.default.viewers");
groups.add("data.file.WellboreTrajectory");
groups.add("service.storage.viewer");
groups.add("service.search.user");
groups.add("service.entitlements.admin");
String dataPartitionId = AwsConfig.getTenant();
String domain = AwsConfig.getDomain();
String memberEmail = AwsConfig.getAWSCognitoTestUsername();
for (String group : groups) {
String groupName = group;
String groupDescription = group;
String groupEmail = String.format("%s@%s.%s", groupName, dataPartitionId, domain);
String groupUniqueIdentifier = String.format("%s:%s:%s", dataPartitionId, groupEmail, memberEmail);
String memberEmailAndDataPartition = String.format("%s:%s", memberEmail, dataPartitionId);
// Build the item
Item item = new Item()
.withString("groupUniqueIdentifier", groupUniqueIdentifier)
.withString("dataPartitionId", dataPartitionId)
.withString("groupDescription", groupDescription)
.withString("groupEmail", groupEmail)
.withString("groupName", groupName)
.withString("memberEmail", memberEmail)
.withString("memberEmailAndDataPartition", memberEmailAndDataPartition)
.withString("role", "OWNER");
// Write the item to the table
PutItemOutcome outcome = table.putItem(item);
try {
System.out.println("Adding the test groups to user: "+AwsConfig.getAWSCognitoTestUsername()+" now..");
String tableName = tablePrefix + "-" + "Groups";
Table table = dynamoDB.getTable(tableName);
List<String> groups = new ArrayList<String>();
groups.add("data.default.viewers");
groups.add("data.file.WellboreTrajectory");
groups.add("service.storage.viewer");
groups.add("service.search.user");
groups.add("service.entitlements.admin");
String dataPartitionId = AwsConfig.getTenant();
String domain = AwsConfig.getDomain();
String memberEmail = AwsConfig.getAWSCognitoTestUsername();
for (String group : groups) {
String groupName = group;
String groupDescription = group;
String groupEmail = String.format("%s@%s.%s", groupName, dataPartitionId, domain);
String groupUniqueIdentifier = String.format("%s:%s:%s", dataPartitionId, groupEmail, memberEmail);
String memberEmailAndDataPartition = String.format("%s:%s", memberEmail, dataPartitionId);
// Build the item
Item item = new Item()
.withString("groupUniqueIdentifier", groupUniqueIdentifier)
.withString("dataPartitionId", dataPartitionId)
.withString("groupDescription", groupDescription)
.withString("groupEmail", groupEmail)
.withString("groupName", groupName)
.withString("memberEmail", memberEmail)
.withString("memberEmailAndDataPartition", memberEmailAndDataPartition)
.withString("role", "OWNER");
// Write the item to the table
PutItemOutcome outcome = table.putItem(item);
}
}
catch (Exception e) {
System.out.println(e);
throw e;
}
}
public void delete_test_tenant() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment