diff --git a/application/src/main/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettings.java b/application/src/main/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettings.java index 73a9981f5e..010d8bed41 100644 --- a/application/src/main/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettings.java +++ b/application/src/main/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettings.java @@ -17,6 +17,6 @@ public class TwoFactorAuthSettings { * @return true if 2FA is enabled and configured, false otherwise. */ public boolean isAvailable() { - return enabled && (emailVerified || totpConfigured); + return enabled && totpConfigured; } } diff --git a/application/src/test/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettingsTest.java b/application/src/test/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettingsTest.java new file mode 100644 index 0000000000..a46381e633 --- /dev/null +++ b/application/src/test/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettingsTest.java @@ -0,0 +1,41 @@ +package run.halo.app.security.authentication.twofactor; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class TwoFactorAuthSettingsTest { + + @ParameterizedTest + @MethodSource("isAvailableCases") + void isAvailableTest(TwoFactorAuthSettings settings, boolean expectAvailable) { + assertEquals(expectAvailable, settings.isAvailable()); + } + + static Stream isAvailableCases() { + return Stream.of( + arguments(settings(false, true, true), false), + arguments(settings(false, false, false), false), + arguments(settings(false, false, true), false), + arguments(settings(false, true, false), false), + arguments(settings(true, true, true), true), + arguments(settings(true, false, false), false), + arguments(settings(true, false, true), true), + arguments(settings(true, true, false), false) + ); + } + + static TwoFactorAuthSettings settings(boolean enabled, boolean emailVerified, + boolean totpConfigured) { + var settings = new TwoFactorAuthSettings(); + settings.setEnabled(enabled); + settings.setEmailVerified(emailVerified); + settings.setTotpConfigured(totpConfigured); + return settings; + } + +} \ No newline at end of file