1 parent
83028e2dd9
commit
3e545de8b6
6 files changed
+90
-6
No files matched your search
@@ -263,6 +263,50 @@ func TestLoginMethodsRolesAndSingleConsumption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailLoginAfterAsyncDelivery(t *testing.T) {
|
||||
codes := make(chan string, 1)
|
||||
user, _ := setupLoginMethods(t, func(_ verification.Challenge, code string) error {
|
||||
codes <- code
|
||||
return nil
|
||||
})
|
||||
pending, err := beginLoginVerification(user, "127.0.0.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id := pending["challenge_id"].(string)
|
||||
input := resendLoginVerificationRequest{ID: id, Account: user.Account}
|
||||
if code, _ := callLoginHandler(t, ResendLoginVerification, input); code != 0 {
|
||||
t.Fatal("failed to start delivery")
|
||||
}
|
||||
var emailCode string
|
||||
select {
|
||||
case emailCode = <-codes:
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("delivery did not run")
|
||||
}
|
||||
deadline := time.Now().Add(3 * time.Second)
|
||||
for {
|
||||
code, data := callLoginHandler(t, LoginVerificationStatus, input)
|
||||
if code != 0 {
|
||||
t.Fatal("status failed")
|
||||
}
|
||||
if data["delivery_status"] == "sent" {
|
||||
break
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("delivery status never became sent")
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
verify := loginVerificationRequest{ID: id, Account: user.Account, Method: "email", Code: emailCode}
|
||||
if code, _ := callLoginHandler(t, CompleteLoginVerification, verify); code != 0 {
|
||||
t.Fatal("delivered email code did not complete login")
|
||||
}
|
||||
if code, _ := callLoginHandler(t, CompleteLoginVerification, verify); code == 0 {
|
||||
t.Fatal("consumed code accepted again")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginMethodsRejectInvalidState(t *testing.T) {
|
||||
user, _ := setupLoginMethods(t, func(verification.Challenge, string) error { return nil })
|
||||
pending, _ := beginLoginVerification(user, "127.0.0.1")
|
||||
|
||||
@@ -18,6 +18,7 @@ func registerV1Routes(mux *http.ServeMux) {
|
||||
registerV1MethodRoute(mux, "/api/v1/security/verification/verify", "/api/security/verification/verify", http.MethodPost, 16<<10, controllers.VerifyVerification)
|
||||
registerV1MethodRoute(mux, "/api/v1/security/login/verify", "/api/security/login/verify", http.MethodPost, 16<<10, controllers.CompleteLoginVerification)
|
||||
registerV1MethodRoute(mux, "/api/v1/security/login/resend", "/api/security/login/resend", http.MethodPost, 16<<10, controllers.ResendLoginVerification)
|
||||
registerV1MethodRoute(mux, "/api/v1/security/login/status", "/api/security/login/status", http.MethodPost, 4<<10, controllers.LoginVerificationStatus)
|
||||
registerV1MethodRoute(mux, "/api/v1/security/webauthn/registration/begin", "/api/security/webauthn/registration/begin", http.MethodPost, 16<<10, controllers.BeginWebAuthnRegistration)
|
||||
registerV1MethodRoute(mux, "/api/v1/security/webauthn/registration/finish", "/api/security/webauthn/registration/finish", http.MethodPost, 64<<10, controllers.FinishWebAuthnRegistration)
|
||||
registerV1MethodRoute(mux, "/api/v1/security/webauthn/credentials", "/api/security/webauthn/credentials", http.MethodGet, 0, controllers.ListWebAuthnCredentials)
|
||||
|
||||
@@ -58,6 +58,7 @@ func TestV1PostOnlyRoutesRejectGet(t *testing.T) {
|
||||
"/api/v1/user/info",
|
||||
"/api/v1/user/list",
|
||||
"/api/v1/rule/get",
|
||||
"/api/v1/security/login/status",
|
||||
} {
|
||||
recorder := httptest.NewRecorder()
|
||||
mux.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, endpoint, nil))
|
||||
@@ -198,6 +199,7 @@ func TestFrontendV1RoutesAreRegistered(t *testing.T) {
|
||||
"/api/v1/security/external-email/list",
|
||||
"/api/v1/security/external-email/verify",
|
||||
"/api/v1/security/login/resend",
|
||||
"/api/v1/security/login/status",
|
||||
"/api/v1/security/login/verify",
|
||||
"/api/v1/security/recovery/begin",
|
||||
"/api/v1/security/recovery/complete",
|
||||
|
||||
Reference in new issue
Block a user