Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmiccoli committed Oct 23, 2023
1 parent 13f27b4 commit bd9764d
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public void testEnableAuthenticatorApp() throws Exception {

IamTotpMfa totpMfa = cloneTotpMfa(TOTP_MFA);
totpMfa.setActive(true);
totpMfa.setAccount(TEST_ACCOUNT);
totpMfa.setAccount(account);
totpMfa.setSecret("secret");
String totp = "123456";

when(totpMfaService.verifyTotp(account, totp)).thenReturn(true);
when(totpMfaService.enableTotpMfa(account)).thenReturn(totpMfa);

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().isOk());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().isOk());

verify(accountRepository, times(2)).findByUsername(TEST_USERNAME);
verify(totpMfaService, times(1)).verifyTotp(account, totp);
Expand All @@ -140,7 +140,7 @@ public void testEnableAuthenticatorAppIncorrectCode() throws Exception {

when(totpMfaService.verifyTotp(account, totp)).thenReturn(false);

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, times(1)).verifyTotp(account, totp);
verify(totpMfaService, never()).enableTotpMfa(account);
Expand All @@ -152,7 +152,7 @@ public void testEnableAuthenticatorAppInvalidCharactersInCode() throws Exception
IamAccount account = cloneAccount(TEST_ACCOUNT);
String totp = "abcdef";

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).enableTotpMfa(account);
}
Expand All @@ -163,7 +163,7 @@ public void testEnableAuthenticatorAppCodeTooShort() throws Exception {
IamAccount account = cloneAccount(TEST_ACCOUNT);
String totp = "12345";

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).enableTotpMfa(account);
}
Expand All @@ -174,7 +174,7 @@ public void testEnableAuthenticatorAppCodeTooLong() throws Exception {
IamAccount account = cloneAccount(TEST_ACCOUNT);
String totp = "1234567";

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).enableTotpMfa(account);
}
Expand All @@ -185,7 +185,7 @@ public void testEnableAuthenticatorAppNullCode() throws Exception {
IamAccount account = cloneAccount(TEST_ACCOUNT);
String totp = null;

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).enableTotpMfa(account);
}
Expand All @@ -196,7 +196,7 @@ public void testEnableAuthenticatorAppEmptyCode() throws Exception {
IamAccount account = cloneAccount(TEST_ACCOUNT);
String totp = "";

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).enableTotpMfa(account);
}
Expand All @@ -206,15 +206,15 @@ public void testEnableAuthenticatorAppEmptyCode() throws Exception {
public void testEnableAuthenticatorAppNoAuthenticationIsUnauthorized() throws Exception {
String totp = "123456";

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().isUnauthorized());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().isUnauthorized());
}

@Test
@WithMockPreAuthenticatedUser
public void testEnableAuthenticatorAppPreAuthenticationIsUnauthorized() throws Exception {
String totp = "123456";

mvc.perform(post(ENABLE_URL).param("totp", totp)).andExpect(status().isUnauthorized());
mvc.perform(post(ENABLE_URL).param("code", totp)).andExpect(status().isUnauthorized());
}

@Test
Expand All @@ -227,7 +227,7 @@ public void testDisableAuthenticatorApp() throws Exception {
when(totpMfaService.verifyTotp(account, totp)).thenReturn(true);
when(totpMfaService.disableTotpMfa(account)).thenReturn(totpMfa);

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().isOk());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().isOk());

verify(accountRepository, times(2)).findByUsername(TOTP_USERNAME);
verify(totpMfaService, times(1)).verifyTotp(account, totp);
Expand All @@ -242,7 +242,7 @@ public void testDisableAuthenticatorAppIncorrectCode() throws Exception {

when(totpMfaService.verifyTotp(account, totp)).thenReturn(false);

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, times(1)).verifyTotp(account, totp);
verify(totpMfaService, never()).disableTotpMfa(account);
Expand All @@ -254,7 +254,7 @@ public void testDisableAuthenticatorAppInvalidCharactersInCode() throws Exceptio
IamAccount account = cloneAccount(TOTP_MFA_ACCOUNT);
String totp = "123456";

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).disableTotpMfa(account);
}
Expand All @@ -265,7 +265,7 @@ public void testDisableAuthenticatorAppCodeTooShort() throws Exception {
IamAccount account = cloneAccount(TOTP_MFA_ACCOUNT);
String totp = "12345";

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).disableTotpMfa(account);
}
Expand All @@ -276,7 +276,7 @@ public void testDisableAuthenticatorAppCodeTooLong() throws Exception {
IamAccount account = cloneAccount(TOTP_MFA_ACCOUNT);
String totp = "1234567";

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).disableTotpMfa(account);
}
Expand All @@ -287,7 +287,7 @@ public void testDisableAuthenticatorAppNullCode() throws Exception {
IamAccount account = cloneAccount(TOTP_MFA_ACCOUNT);
String totp = null;

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).disableTotpMfa(account);
}
Expand All @@ -298,7 +298,7 @@ public void testDisableAuthenticatorAppEmptyCode() throws Exception {
IamAccount account = cloneAccount(TOTP_MFA_ACCOUNT);
String totp = "";

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().is4xxClientError());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().is4xxClientError());

verify(totpMfaService, never()).disableTotpMfa(account);
}
Expand All @@ -308,14 +308,14 @@ public void testDisableAuthenticatorAppEmptyCode() throws Exception {
public void testDisableAuthenticatorAppNoAuthenticationIsUnauthorized() throws Exception {
String totp = "123456";

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().isUnauthorized());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().isUnauthorized());
}

@Test
@WithMockPreAuthenticatedUser
public void testDisableAuthenticatorAppPreAuthenticationIsUnauthorized() throws Exception {
String totp = "123456";

mvc.perform(post(DISABLE_URL).param("totp", totp)).andExpect(status().isUnauthorized());
mvc.perform(post(DISABLE_URL).param("code", totp)).andExpect(status().isUnauthorized());
}
}

0 comments on commit bd9764d

Please sign in to comment.