-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the problem of being unable to login when 2FA was enabled but TOT…
…P was not configured (#5400) #### What type of PR is this? /kind bug /area core /milestone 2.13.x #### What this PR does / why we need it: This PR ignored `email verified` status while 2FA was enabled. #### Which issue(s) this PR fixes: Fixes #5398 #### Does this PR introduce a user-facing change? ```release-note 修复开启两步验证但未配置 TOTP 可能无法登录的问题 ```
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...c/test/java/run/halo/app/security/authentication/twofactor/TwoFactorAuthSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Arguments> 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; | ||
} | ||
|
||
} |