Skip to content

Commit 853a99c

Browse files
authored
Disable webauthn buttons after click
Closes #41037 Signed-off-by: rmartinc <[email protected]>
1 parent 57972d8 commit 853a99c

File tree

8 files changed

+23
-8
lines changed

8 files changed

+23
-8
lines changed

testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/WaitUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.jboss.arquillian.graphene.wait.ElementBuilder;
2020
import org.keycloak.executors.ExecutorsProvider;
2121
import org.keycloak.testsuite.client.KeycloakTestingClient;
22+
import org.keycloak.testsuite.pages.AbstractPage;
2223
import org.openqa.selenium.By;
2324
import org.openqa.selenium.TimeoutException;
2425
import org.openqa.selenium.WebDriver;
@@ -91,6 +92,12 @@ public static void waitUntilElementClassContains(WebElement element, String valu
9192
);
9293
}
9394

95+
public static void waitUntilPageIsCurrent(AbstractPage page) {
96+
WebDriver driver = getCurrentDriver();
97+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(PAGELOAD_TIMEOUT_MILLIS));
98+
wait.until((WebDriver driver1) -> page.isCurrent());
99+
}
100+
94101
public static void pause(long millis) {
95102
if (millis > 0) {
96103
log.info("Wait: " + millis + "ms");

testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/registration/AuthAttachmentRegisterTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.Test;
2222
import org.junit.Ignore;
2323
import org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver;
24+
import org.keycloak.testsuite.util.WaitUtils;
2425
import org.keycloak.testsuite.webauthn.AbstractWebAuthnVirtualTest;
2526
import org.keycloak.testsuite.webauthn.utils.WebAuthnRealmData;
2627
import org.openqa.selenium.firefox.FirefoxDriver;
@@ -59,6 +60,7 @@ public void authenticatorAttachmentPlatform() throws IOException {
5960
try (Closeable u = getWebAuthnRealmUpdater()
6061
.setWebAuthnPolicyAuthenticatorAttachment(AuthenticatorAttachment.PLATFORM.getValue())
6162
.setWebAuthnPolicyUserVerificationRequirement(UserVerificationRequirement.DISCOURAGED.getValue())
63+
.setWebAuthnPolicyCreateTimeout(3)
6264
.update()) {
6365

6466
// It shouldn't be possible to register the authenticator
@@ -70,12 +72,18 @@ public void authenticatorAttachmentPlatform() throws IOException {
7072

7173
registerDefaultUser(false);
7274

75+
// Instead of returning an error it seems that selenium webauthn just hangs
76+
// So we cannot test this correctly
7377
webAuthnRegisterPage.assertCurrent();
7478

79+
// click authentication again does nothing
7580
webAuthnRegisterPage.clickRegister();
81+
webAuthnRegisterPage.clickRegister();
82+
webAuthnRegisterPage.assertCurrent();
7683

77-
webAuthnErrorPage.assertCurrent();
78-
assertThat(webAuthnErrorPage.getError(), containsString("A request is already pending."));
84+
// it timeouts after create timeout
85+
WaitUtils.waitUntilPageIsCurrent(webAuthnErrorPage);
86+
assertThat(webAuthnErrorPage.getError(), containsString("The operation either timed out or was not allowed."));
7987
}
8088
}
8189

themes/src/main/resources/theme/base/login/login-passkeys-conditional-authenticate.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
};
115115
authButton.addEventListener("click", () => {
116116
authenticateByWebAuthn(input);
117-
});
117+
}, { once: true });
118118
119119
const args = {
120120
isUserIdentified : ${isUserIdentified},

themes/src/main/resources/theme/base/login/passkeys.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
authButton.addEventListener("click", (event) => {
3434
event.preventDefault();
3535
authenticateByWebAuthn({errmsg : "${msg("webauthn-unsupported-browser-text")?no_esc}", ...args});
36-
});
36+
}, { once: true });
3737
}
3838
</script>
3939
<a id="authenticateWebAuthnButton" href="#" class="${properties.kcButtonSecondaryClass!} ${properties.kcButtonBlockClass!} ${properties.kcMarginTopClass!}">

themes/src/main/resources/theme/base/login/webauthn-authenticate.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
errmsg : "${msg("webauthn-unsupported-browser-text")?no_esc}"
9090
};
9191
authenticateByWebAuthn(input);
92-
});
92+
}, { once: true });
9393
</script>
9494
9595
<#elseif section = "info">

themes/src/main/resources/theme/base/login/webauthn-register.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
errmsg : "${msg("webauthn-unsupported-browser-text")?no_esc}"
4444
};
4545
registerByWebAuthn(input);
46-
});
46+
}, { once: true });
4747
</script>
4848
4949
<input type="submit"

themes/src/main/resources/theme/keycloak.v2/login/webauthn-authenticate.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
errmsg : "${msg("webauthn-unsupported-browser-text")?no_esc}"
117117
};
118118
authenticateByWebAuthn(input);
119-
});
119+
}, { once: true });
120120
</script>
121121
122122
<#elseif section = "info">

themes/src/main/resources/theme/keycloak.v2/login/webauthn-register.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
errmsg : "${msg("webauthn-unsupported-browser-text")?no_esc}"
4545
};
4646
registerByWebAuthn(input);
47-
});
47+
}, { once: true });
4848
</script>
4949
5050
<@buttons.actionGroup horizontal=true>

0 commit comments

Comments
 (0)