Skip to content

Commit c2d859c

Browse files
cbiesingerpujagani
andauthored
[java] Fix FedCM command definition and tests (#14070)
Co-authored-by: Puja Jagani <[email protected]>
1 parent 359ac9a commit c2d859c

File tree

13 files changed

+232
-76
lines changed

13 files changed

+232
-76
lines changed

.skipped-tests

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
-//java/test/org/openqa/selenium/edge:EdgeDriverFunctionalTest
66
-//java/test/org/openqa/selenium/edge:EdgeDriverFunctionalTest-edge
77
-//java/test/org/openqa/selenium/edge:EdgeDriverFunctionalTest-remote
8-
-//java/test/org/openqa/selenium/federatedcredentialmanagement:FederatedCredentialManagementTest
98
-//java/test/org/openqa/selenium/firefox:FirefoxDriverBuilderTest
109
-//java/test/org/openqa/selenium/grid/gridui:OverallGridTest
1110
-//java/test/org/openqa/selenium/grid/router:RemoteWebDriverDownloadTest
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"accounts_endpoint": "accounts.json",
33
"client_metadata_endpoint": "client_metadata.json",
4-
"id_assertion_endpoint": "id_assertion",
5-
"signin_url": "/signin",
6-
"login_url": "/login"
4+
"id_assertion_endpoint": "id_assertion.json",
5+
"signin_url": "signin",
6+
"login_url": "login"
77
}

common/src/web/fedcm/fedcm.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<script>
33

4-
let configURL = `http://${location.host}/fedcm/fedcm.json`;
4+
let configURL = `http://${location.host}/fedcm/config.json`;
55
let promise = null;
66

77
function triggerFedCm() {
@@ -17,4 +17,4 @@
1717
return promise;
1818
}
1919

20-
</script>
20+
</script>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>FedCM Example</title>
5+
</head>
6+
<body>
7+
<button id="triggerButton" onclick="triggerFedCm()">Trigger FedCM</button>
8+
<div id="result"></div>
9+
10+
<script>
11+
// Use a relative path for the configURL
12+
let configURL = `https://${location.host}/fedcm/config.json`;
13+
console.log(configURL)
14+
let result = null;
15+
16+
async function triggerFedCm() {
17+
console.log("Config URL:", configURL);
18+
try {
19+
let promise = await navigator.credentials.get({
20+
identity: {
21+
providers: [{
22+
configURL: configURL,
23+
clientId: '1',
24+
}]
25+
}
26+
});
27+
result = promise;
28+
document.getElementById('result').innerText = JSON.stringify(result);
29+
} catch (error) {
30+
console.error("FedCM Error:", error);
31+
result = { error: error.message };
32+
document.getElementById('result').innerText = JSON.stringify(result);
33+
}
34+
}
35+
</script>
36+
</body>
37+
</html>

common/src/web/fedcm/login.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Login</title>
5+
</head>
6+
<body>
7+
<h1>Login Page</h1>
8+
<p>Login successful! This is a placeholder for the login process.</p>
9+
<a href="/">Return to Home</a>
10+
</body>
11+
</html>

common/src/web/fedcm/signin.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Sign In</title>
5+
</head>
6+
<body>
7+
<h1>Sign In Page</h1>
8+
<p>This is a placeholder for the sign-in page.</p>
9+
<form action="/signin" method="post">
10+
<label for="username">Username:</label>
11+
<input type="text" id="username" name="username" required>
12+
<br><br>
13+
<label for="password">Password:</label>
14+
<input type="password" id="password" name="password" required>
15+
<br><br>
16+
<button type="submit">Sign In</button>
17+
</form>
18+
</body>
19+
</html>

java/src/org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementDialog.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public interface FederatedCredentialManagementDialog {
5252
/** Returns the subtitle of the dialog or null if none. */
5353
String getSubtitle();
5454

55+
void clickDialog();
56+
5557
/**
5658
* Returns the accounts shown in the account chooser.
5759
*

java/src/org/openqa/selenium/remote/FedCmDialogImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public String getDialogType() {
4545
return (String) executeMethod.execute(DriverCommand.GET_FEDCM_DIALOG_TYPE, null);
4646
}
4747

48+
@Override
49+
public void clickDialog() {
50+
executeMethod.execute(
51+
DriverCommand.CLICK_DIALOG, Map.of("dialogButton", "ConfirmIdpLoginContinue"));
52+
}
53+
4854
@Override
4955
public String getTitle() {
5056
Map<String, Object> result =

java/src/org/openqa/selenium/remote/codec/AbstractHttpCommandCodec.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ public AbstractHttpCommandCodec() {
197197
defineCommand(SET_USER_VERIFIED, post(webauthnId + "/uv"));
198198

199199
// Federated Credential Management API
200-
defineCommand(CANCEL_DIALOG, post("/fedcm/canceldialog"));
201-
defineCommand(SELECT_ACCOUNT, post("/fedcm/selectaccount"));
202-
defineCommand(CLICK_DIALOG, post("/fedcm/clickdialogbutton"));
203-
defineCommand(GET_ACCOUNTS, get("/fedcm/accountlist"));
204-
defineCommand(GET_FEDCM_TITLE, get("/fedcm/gettitle"));
205-
defineCommand(GET_FEDCM_DIALOG_TYPE, get("/fedcm/getdialogtype"));
206-
defineCommand(SET_DELAY_ENABLED, post("/fedcm/setdelayenabled"));
207-
defineCommand(RESET_COOLDOWN, post("/fedcm/resetcooldown"));
200+
String fedcm = sessionId + "/fedcm";
201+
defineCommand(CANCEL_DIALOG, post(fedcm + "/canceldialog"));
202+
defineCommand(SELECT_ACCOUNT, post(fedcm + "/selectaccount"));
203+
defineCommand(CLICK_DIALOG, post(fedcm + "/clickdialogbutton"));
204+
defineCommand(GET_ACCOUNTS, get(fedcm + "/accountlist"));
205+
defineCommand(GET_FEDCM_TITLE, get(fedcm + "/gettitle"));
206+
defineCommand(GET_FEDCM_DIALOG_TYPE, get(fedcm + "/getdialogtype"));
207+
defineCommand(SET_DELAY_ENABLED, post(fedcm + "/setdelayenabled"));
208+
defineCommand(RESET_COOLDOWN, post(fedcm + "/resetcooldown"));
208209

209210
defineCommand(GET_DOWNLOADABLE_FILES, get(sessionId + "/se/files"));
210211
defineCommand(DOWNLOAD_FILE, post(sessionId + "/se/files"));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.environment.webserver;
19+
20+
import java.io.UncheckedIOException;
21+
import java.util.Map;
22+
import org.openqa.selenium.remote.http.Contents;
23+
import org.openqa.selenium.remote.http.HttpHandler;
24+
import org.openqa.selenium.remote.http.HttpRequest;
25+
import org.openqa.selenium.remote.http.HttpResponse;
26+
27+
class FedCmConfigHandler implements HttpHandler {
28+
29+
@Override
30+
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
31+
HttpResponse response = new HttpResponse();
32+
response.setHeader("Content-Type", "application/json");
33+
response.setHeader("Cache-Control", "no-store");
34+
35+
response.setContent(
36+
Contents.asJson(
37+
Map.of(
38+
"accounts_endpoint", "accounts.json",
39+
"client_metadata_endpoint", "client_metadata.json",
40+
"id_assertion_endpoint", "id_assertion.json",
41+
"signin_url", "signin",
42+
"login_url", "login")));
43+
44+
return response;
45+
}
46+
}

0 commit comments

Comments
 (0)