Skip to content

Commit

Permalink
AUT-2202: Updating DynamoServiceIntegrationTest to accomodate the new…
Browse files Browse the repository at this point in the history
… MFA Database schema
  • Loading branch information
VladGavrilet committed Apr 26, 2024
1 parent 095f64c commit 9be8e3c
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import uk.gov.di.authentication.shared.entity.ClientConsent;
import uk.gov.di.authentication.shared.entity.MFAMethod;
import uk.gov.di.authentication.shared.entity.MFAMethodType;
import uk.gov.di.authentication.shared.entity.MFAMethodV2;
import uk.gov.di.authentication.shared.entity.PriorityIdentifier;
import uk.gov.di.authentication.shared.entity.UserCredentials;
import uk.gov.di.authentication.shared.entity.UserProfile;
import uk.gov.di.authentication.shared.entity.ValidScopes;
Expand Down Expand Up @@ -171,6 +173,110 @@ void shouldAddAuthAppMFAMethod() {
assertThat(mfaMethod.getCredentialValue(), equalTo(TEST_MFA_APP_CREDENTIAL));
}

@Test
void shouldAddAuthAppMFAMethodV2() {
setUpDynamo();
dynamoService.addMFAMethodV2(
TEST_EMAIL,
MFAMethodType.AUTH_APP,
true,
true,
PriorityIdentifier.PRIMARY,
1,
"test");
UserCredentials updatedUserCredentials =
dynamoService.getUserCredentialsFromEmail(TEST_EMAIL);

assertThat(updatedUserCredentials.getMfaMethodsV2().size(), equalTo(1));
MFAMethodV2 mfaMethod = updatedUserCredentials.getMfaMethodsV2().get(0);
assertThat(mfaMethod.getMfaMethodType(), equalTo(MFAMethodType.AUTH_APP.getValue()));
assertThat(mfaMethod.isMethodVerified(), equalTo(true));
assertThat(mfaMethod.isEnabled(), equalTo(true));
assertThat(mfaMethod.getPriorityIdentifier(), equalTo(PriorityIdentifier.PRIMARY));
assertThat(mfaMethod.getMfaIdentifier(), equalTo(1));
assertThat(mfaMethod.getEndPoint(), equalTo("test"));
}

@Test
void shouldUpdateAuthAppMFAMethodV2() {
setUpDynamo();
dynamoService.addMFAMethodV2(
TEST_EMAIL,
MFAMethodType.AUTH_APP,
true,
true,
PriorityIdentifier.PRIMARY,
1,
"test");

dynamoService.updateMFAmethodV2(
TEST_EMAIL,
MFAMethodType.AUTH_APP,
true,
false,
PriorityIdentifier.SECONDARY,
1,
"test");

UserCredentials updatedUserCredentials =
dynamoService.getUserCredentialsFromEmail(TEST_EMAIL);

assertThat(updatedUserCredentials.getMfaMethodsV2().size(), equalTo(1));
MFAMethodV2 mfaMethod = updatedUserCredentials.getMfaMethodsV2().get(0);
assertThat(mfaMethod.getMfaMethodType(), equalTo(MFAMethodType.AUTH_APP.getValue()));
assertThat(mfaMethod.isMethodVerified(), equalTo(true));
assertThat(mfaMethod.isEnabled(), equalTo(false));
assertThat(mfaMethod.getPriorityIdentifier(), equalTo(PriorityIdentifier.SECONDARY));
assertThat(mfaMethod.getMfaIdentifier(), equalTo(1));
assertThat(mfaMethod.getEndPoint(), equalTo("test"));
}

@Test
void shouldDeleteAuthAppMFAMethodV2() {

setUpDynamo();
dynamoService.addMFAMethodV2(
TEST_EMAIL,
MFAMethodType.AUTH_APP,
true,
true,
PriorityIdentifier.PRIMARY,
1,
"test");

List<MFAMethodV2> users = dynamoService.readMFAMethodsV2(TEST_EMAIL);

assertThat(users.size(), equalTo(1));

dynamoService.deleteMFAmethodV2(TEST_EMAIL, 1);

users = dynamoService.readMFAMethodsV2(TEST_EMAIL);
assertThat(users.size(), equalTo(0));
}

@Test
void shouldReadAuthAppMFAMethodv2() {
setUpDynamo();
dynamoService.addMFAMethodV2(
TEST_EMAIL,
MFAMethodType.AUTH_APP,
true,
true,
PriorityIdentifier.PRIMARY,
1,
"test");
dynamoService.addMFAMethodV2(
TEST_EMAIL,
MFAMethodType.AUTH_APP,
true,
false,
PriorityIdentifier.SECONDARY,
3,
"google");
List<MFAMethodV2> users = dynamoService.readMFAMethodsV2(TEST_EMAIL);
assertThat(users.size(), equalTo(2));
}

@Test
void
shouldSetAuthAppMFAMethodNotEnabledAndSetPhoneNumberAndAccountVerifiedWhenMfaMethodExists() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ AttributeValue toAttributeValue() {
AttributeValue.fromS(getPriorityIdentifier().getValue())),
Map.entry(ATTRIBUTE_END_POINT, AttributeValue.fromS(getEndPoint()))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public enum PriorityIdentifier {
public String getValue() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ public int getTestUser() {
public void setTestUser(int isTestUser) {
this.testUser = isTestUser;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public DynamoService(ConfigurationService configurationService) {
@Override
public boolean userExists(String email) {
return dynamoUserProfileTable.getItem(
Key.builder().partitionValue(email.toLowerCase(Locale.ROOT)).build())
Key.builder().partitionValue(email.toLowerCase(Locale.ROOT)).build())
!= null;
}

Expand Down Expand Up @@ -376,10 +376,10 @@ public void updatePhoneNumberAndAccountVerifiedStatus(
.filter(
method ->
method.getMfaMethodType()
.equals(
MFAMethodType
.AUTH_APP
.getValue())
.equals(
MFAMethodType
.AUTH_APP
.getValue())
&& method.isEnabled())
.findFirst())
.ifPresent(
Expand Down Expand Up @@ -422,10 +422,10 @@ public void setVerifiedPhoneNumberAndRemoveAuthAppIfPresent(String email, String
.filter(
method ->
method.getMfaMethodType()
.equals(
MFAMethodType
.AUTH_APP
.getValue())
.equals(
MFAMethodType
.AUTH_APP
.getValue())
&& method.isEnabled()
&& method.isMethodVerified())
.findFirst())
Expand Down Expand Up @@ -863,4 +863,4 @@ private static String hashPassword(String password) {
private void warmUp() {
dynamoUserProfileTable.describeTable();
}
}
}

0 comments on commit 9be8e3c

Please sign in to comment.