Change supported criteria for Google Authenticator

List Google Authenticator as supported when
- hash algorithm is SHA256 or SHA512
- number of digits is 8
- OTP type is hotp

Signed-off-by: Tero Saarni <tero.saarni@est.tech>
This commit is contained in:
Tero Saarni 2024-02-28 14:59:33 +02:00 committed by Marek Posolda
parent 244ecd45a7
commit e06fcbe6ae
4 changed files with 30 additions and 26 deletions

View file

@ -22,15 +22,10 @@ public class GoogleAuthenticatorProvider implements OTPApplicationProviderFactor
@Override @Override
public boolean supports(OTPPolicy policy) { public boolean supports(OTPPolicy policy) {
if (policy.getDigits() != 6) { if (policy.getType().equals("totp")) {
return false; return policy.getPeriod() == 30;
} }
return true;
if (!policy.getAlgorithm().equals("HmacSHA1")) {
return false;
}
return policy.getType().equals("totp") && policy.getPeriod() == 30;
} }
@Override @Override

View file

@ -318,7 +318,7 @@ public class AppInitiatedActionTotpSetupTest extends AbstractAppInitiatedActionT
String pageSource = driver.getPageSource(); String pageSource = driver.getPageSource();
assertTrue(pageSource.contains("FreeOTP")); assertTrue(pageSource.contains("FreeOTP"));
assertFalse(pageSource.contains("Google Authenticator")); assertTrue(pageSource.contains("Google Authenticator"));
totpPage.clickManual(); totpPage.clickManual();

View file

@ -338,7 +338,7 @@ public class RequiredActionTotpSetupTest extends AbstractTestRealmKeycloakTest {
String pageSource = driver.getPageSource(); String pageSource = driver.getPageSource();
assertTrue(pageSource.contains("FreeOTP")); assertTrue(pageSource.contains("FreeOTP"));
assertFalse(pageSource.contains("Google Authenticator")); assertTrue(pageSource.contains("Google Authenticator"));
assertFalse(pageSource.contains("Microsoft Authenticator")); assertFalse(pageSource.contains("Microsoft Authenticator"));
totpPage.clickManual(); totpPage.clickManual();

View file

@ -1027,8 +1027,17 @@ public class RealmTest extends AbstractAdminTest {
rep = realm.toRepresentation(); rep = realm.toRepresentation();
supportedApplications = rep.getOtpSupportedApplications(); supportedApplications = rep.getOtpSupportedApplications();
assertThat(supportedApplications, hasSize(1)); assertThat(supportedApplications, hasSize(2));
assertThat(supportedApplications, containsInAnyOrder("totpAppFreeOTPName")); assertThat(supportedApplications, containsInAnyOrder("totpAppFreeOTPName", "totpAppGoogleName"));
rep.setOtpPolicyType("hotp");
realm.update(rep);
rep = realm.toRepresentation();
supportedApplications = rep.getOtpSupportedApplications();
assertThat(supportedApplications, hasSize(2));
assertThat(supportedApplications, containsInAnyOrder("totpAppFreeOTPName", "totpAppGoogleName"));
} }
private void setupTestAppAndUser() { private void setupTestAppAndUser() {