Skip to content

Commit

Permalink
[java] Fix FedCM command definition and tests (#14070)
Browse files Browse the repository at this point in the history
Co-authored-by: Puja Jagani <puja.jagani93@gmail.com>
  • Loading branch information
cbiesinger and pujagani authored Dec 26, 2024
1 parent 359ac9a commit c2d859c
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 76 deletions.
1 change: 0 additions & 1 deletion .skipped-tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
-//java/test/org/openqa/selenium/edge:EdgeDriverFunctionalTest
-//java/test/org/openqa/selenium/edge:EdgeDriverFunctionalTest-edge
-//java/test/org/openqa/selenium/edge:EdgeDriverFunctionalTest-remote
-//java/test/org/openqa/selenium/federatedcredentialmanagement:FederatedCredentialManagementTest
-//java/test/org/openqa/selenium/firefox:FirefoxDriverBuilderTest
-//java/test/org/openqa/selenium/grid/gridui:OverallGridTest
-//java/test/org/openqa/selenium/grid/router:RemoteWebDriverDownloadTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"accounts_endpoint": "accounts.json",
"client_metadata_endpoint": "client_metadata.json",
"id_assertion_endpoint": "id_assertion",
"signin_url": "/signin",
"login_url": "/login"
"id_assertion_endpoint": "id_assertion.json",
"signin_url": "signin",
"login_url": "login"
}
4 changes: 2 additions & 2 deletions common/src/web/fedcm/fedcm.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<script>

let configURL = `http://${location.host}/fedcm/fedcm.json`;
let configURL = `http://${location.host}/fedcm/config.json`;
let promise = null;

function triggerFedCm() {
Expand All @@ -17,4 +17,4 @@
return promise;
}

</script>
</script>
37 changes: 37 additions & 0 deletions common/src/web/fedcm/fedcm_async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>FedCM Example</title>
</head>
<body>
<button id="triggerButton" onclick="triggerFedCm()">Trigger FedCM</button>
<div id="result"></div>

<script>
// Use a relative path for the configURL
let configURL = `https://${location.host}/fedcm/config.json`;
console.log(configURL)
let result = null;

async function triggerFedCm() {
console.log("Config URL:", configURL);
try {
let promise = await navigator.credentials.get({
identity: {
providers: [{
configURL: configURL,
clientId: '1',
}]
}
});
result = promise;
document.getElementById('result').innerText = JSON.stringify(result);
} catch (error) {
console.error("FedCM Error:", error);
result = { error: error.message };
document.getElementById('result').innerText = JSON.stringify(result);
}
}
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions common/src/web/fedcm/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login Page</h1>
<p>Login successful! This is a placeholder for the login process.</p>
<a href="/">Return to Home</a>
</body>
</html>
19 changes: 19 additions & 0 deletions common/src/web/fedcm/signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Sign In</title>
</head>
<body>
<h1>Sign In Page</h1>
<p>This is a placeholder for the sign-in page.</p>
<form action="/signin" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br><br>
<button type="submit">Sign In</button>
</form>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface FederatedCredentialManagementDialog {
/** Returns the subtitle of the dialog or null if none. */
String getSubtitle();

void clickDialog();

/**
* Returns the accounts shown in the account chooser.
*
Expand Down
6 changes: 6 additions & 0 deletions java/src/org/openqa/selenium/remote/FedCmDialogImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public String getDialogType() {
return (String) executeMethod.execute(DriverCommand.GET_FEDCM_DIALOG_TYPE, null);
}

@Override
public void clickDialog() {
executeMethod.execute(
DriverCommand.CLICK_DIALOG, Map.of("dialogButton", "ConfirmIdpLoginContinue"));
}

@Override
public String getTitle() {
Map<String, Object> result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,15 @@ public AbstractHttpCommandCodec() {
defineCommand(SET_USER_VERIFIED, post(webauthnId + "/uv"));

// Federated Credential Management API
defineCommand(CANCEL_DIALOG, post("/fedcm/canceldialog"));
defineCommand(SELECT_ACCOUNT, post("/fedcm/selectaccount"));
defineCommand(CLICK_DIALOG, post("/fedcm/clickdialogbutton"));
defineCommand(GET_ACCOUNTS, get("/fedcm/accountlist"));
defineCommand(GET_FEDCM_TITLE, get("/fedcm/gettitle"));
defineCommand(GET_FEDCM_DIALOG_TYPE, get("/fedcm/getdialogtype"));
defineCommand(SET_DELAY_ENABLED, post("/fedcm/setdelayenabled"));
defineCommand(RESET_COOLDOWN, post("/fedcm/resetcooldown"));
String fedcm = sessionId + "/fedcm";
defineCommand(CANCEL_DIALOG, post(fedcm + "/canceldialog"));
defineCommand(SELECT_ACCOUNT, post(fedcm + "/selectaccount"));
defineCommand(CLICK_DIALOG, post(fedcm + "/clickdialogbutton"));
defineCommand(GET_ACCOUNTS, get(fedcm + "/accountlist"));
defineCommand(GET_FEDCM_TITLE, get(fedcm + "/gettitle"));
defineCommand(GET_FEDCM_DIALOG_TYPE, get(fedcm + "/getdialogtype"));
defineCommand(SET_DELAY_ENABLED, post(fedcm + "/setdelayenabled"));
defineCommand(RESET_COOLDOWN, post(fedcm + "/resetcooldown"));

defineCommand(GET_DOWNLOADABLE_FILES, get(sessionId + "/se/files"));
defineCommand(DOWNLOAD_FILE, post(sessionId + "/se/files"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.environment.webserver;

import java.io.UncheckedIOException;
import java.util.Map;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;

class FedCmConfigHandler implements HttpHandler {

@Override
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
HttpResponse response = new HttpResponse();
response.setHeader("Content-Type", "application/json");
response.setHeader("Cache-Control", "no-store");

response.setContent(
Contents.asJson(
Map.of(
"accounts_endpoint", "accounts.json",
"client_metadata_endpoint", "client_metadata.json",
"id_assertion_endpoint", "id_assertion.json",
"signin_url", "signin",
"login_url", "login")));

return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public HandlersForTests(String hostname, int port, Path tempPageDir) {
.setContent(Contents.string("<h1>authorized</h1>", UTF_8)))
.with(new BasicAuthenticationFilter("test", "test")),
Route.get("/.well-known/web-identity").to(WellKnownWebIdentityHandler::new),
Route.get("/fedcm/config.json").to(FedCmConfigHandler::new),
Route.get("/echo").to(EchoHandler::new),
Route.get("/cookie").to(CookieHandler::new),
Route.post("/fedcm/id_assertion").to(FedCmIdAssertion::new),
Route.post("/fedcm/id_assertion.json").to(FedCmIdAssertion::new),
Route.get("/encoding").to(EncodingHandler::new),
Route.matching(req -> req.getUri().startsWith("/generated/"))
.to(() -> new GeneratedJsTestHandler("/generated")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
HttpResponse response = new HttpResponse();
response.setHeader("Content-Type", "application/json");
response.setHeader("Cache-Control", "no-store");
String targetLocation = UrlPath.relativeToContext(req, "/fedcm/fedcm.json");
String targetLocation = UrlPath.relativeToContext(req, "https://idp.com");

response.setContent(Contents.string(String.format(RESPONSE_STRING, targetLocation), UTF_8));

Expand Down
Loading

0 comments on commit c2d859c

Please sign in to comment.