-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f5a25a
commit 1f696b8
Showing
9 changed files
with
225 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AddType application/json .json |
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,17 @@ | ||
{ | ||
"accounts": [{ | ||
"id": "1234", | ||
"given_name": "John", | ||
"name": "John Doe", | ||
"email": "john_doe@idp.example", | ||
"picture": "https://idp.example/profile/123", | ||
"approved_clients": ["123", "456", "789"] | ||
}, { | ||
"id": "5678", | ||
"given_name": "Aisha", | ||
"name": "Aisha Ahmad", | ||
"email": "aisha@idp.example", | ||
"picture": "https://idp.example/profile/567", | ||
"approved_clients": [] | ||
}] | ||
} |
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,4 @@ | ||
{ | ||
"privacy_policy_url": "https://rp.example/privacy_policy.html", | ||
"terms_of_service_url": "https://rp.example/terms_of_service.html" | ||
} |
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,19 @@ | ||
<!DOCTYPE html> | ||
<script> | ||
|
||
let configURL = `https://{location.host}/fedcm/fedcm.json`; | ||
let promise = null; | ||
|
||
function triggerFedCm() { | ||
promise = navigator.credentials.get({ | ||
identity: { | ||
providers: [{ | ||
configURL: configURL, | ||
clientId: '1', | ||
}] | ||
} | ||
}); | ||
return promise; | ||
} | ||
|
||
</script> |
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,6 @@ | ||
{ | ||
"accounts_endpoint": "accounts.json", | ||
"client_metadata_endpoint": "client_metadata.json", | ||
"id_assertion_endpoint": "token.php", | ||
"signin_url": "https://idp.example/signin" | ||
} |
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,4 @@ | ||
<?php header("Content-Type: application/json") ?> | ||
{ | ||
"token": "<?php echo $_POST["account_id"]; ?>" | ||
} |
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,73 @@ | ||
// 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.remote; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.federatedcredentialmanagement.FederatedCredentialManagementAccount; | ||
import org.openqa.selenium.federatedcredentialmanagement.FederatedCredentialManagementDialog; | ||
import org.openqa.selenium.remote.DriverCommand; | ||
import org.openqa.selenium.remote.ExecuteMethod; | ||
|
||
class FedCmDialogImpl implements FederatedCredentialManagementDialog { | ||
private final ExecuteMethod executeMethod; | ||
|
||
FedCmDialogImpl(ExecuteMethod executeMethod) { | ||
this.executeMethod = executeMethod; | ||
} | ||
|
||
@Override | ||
public void cancelDialog() { | ||
executeMethod.execute(DriverCommand.CANCEL_DIALOG, null); | ||
} | ||
|
||
@Override | ||
public void selectAccount(int index) { | ||
executeMethod.execute(DriverCommand.SELECT_ACCOUNT, ImmutableMap.of("accountIndex", index)); | ||
} | ||
|
||
@Override | ||
public String getDialogType() { | ||
return (String) executeMethod.execute(DriverCommand.GET_FEDCM_DIALOG_TYPE, null); | ||
} | ||
|
||
@Override | ||
public String getTitle() { | ||
Map<String, Object> result = (Map<String, Object>) executeMethod.execute(DriverCommand.GET_FEDCM_TITLE, null); | ||
return (String) result.getOrDefault("title", null); | ||
} | ||
|
||
@Override | ||
public String getSubtitle() { | ||
Map<String, Object> result = (Map<String, Object>) executeMethod.execute(DriverCommand.GET_FEDCM_TITLE, null); | ||
return (String) result.getOrDefault("subtitle", null); | ||
} | ||
|
||
@Override | ||
public List<FederatedCredentialManagementAccount> getAccounts() { | ||
List<Map<String, String>> list = (List<Map<String, String>>) executeMethod.execute(DriverCommand.GET_ACCOUNTS, null); | ||
ArrayList<FederatedCredentialManagementAccount> accounts = new ArrayList<FederatedCredentialManagementAccount>(); | ||
for (Map<String, String> map : list) { | ||
accounts.add(new FederatedCredentialManagementAccount(map)); | ||
} | ||
return accounts; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
java/test/org/openqa/selenium/federatedcredentialmanagement/BUILD.bazel
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,22 @@ | ||
load("@rules_jvm_external//:defs.bzl", "artifact") | ||
load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite") | ||
|
||
java_selenium_test_suite( | ||
name = "LargeTests", | ||
size = "large", | ||
srcs = glob(["*.java"]), | ||
browsers = [ | ||
"chrome", | ||
], | ||
deps = [ | ||
"//java/src/org/openqa/selenium/chrome", | ||
"//java/src/org/openqa/selenium:core", | ||
"//java/src/org/openqa/selenium/remote", | ||
"//java/test/org/openqa/selenium/environment", | ||
"//java/test/org/openqa/selenium/testing:annotations", | ||
"//java/test/org/openqa/selenium/testing:test-base", | ||
"//java/test/org/openqa/selenium/testing/drivers", | ||
artifact("org.junit.jupiter:junit-jupiter-api"), | ||
artifact("org.assertj:assertj-core"), | ||
] + JUNIT5_DEPS, | ||
) |
79 changes: 79 additions & 0 deletions
79
.../org/openqa/selenium/federatedcredentialmanagement/FederatedCredentialManagementTest.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,79 @@ | ||
// 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.federatedcredentialmanagement; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assumptions.assumeThat; | ||
import static org.assertj.core.api.Fail.fail; | ||
import static org.assertj.core.api.InstanceOfAssertFactories.MAP; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.Arrays; | ||
import java.util.Base64; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.InvalidArgumentException; | ||
import org.openqa.selenium.JavascriptExecutor; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.federatedcredentialmanagement.FederatedCredentialManagementDialog; | ||
import org.openqa.selenium.federatedcredentialmanagement.HasFederatedCredentialManagement; | ||
import org.openqa.selenium.testing.JupiterTestBase; | ||
import org.openqa.selenium.testing.drivers.Browser; | ||
|
||
class FederatedCredentialManagementTest extends JupiterTestBase { | ||
|
||
private JavascriptExecutor jsAwareDriver; | ||
private HasFederatedCredentialManagement fedcmDriver; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
ChromeOptions options = (ChromeOptions) Browser.CHROME.getCapabilities(); | ||
options.addArguments("user-agent=foo;bar"); | ||
localDriver = seleniumExtension.createNewDriver(options); | ||
|
||
assumeThat(localDriver).isInstanceOf(HasFederatedCredentialManagement.class); | ||
jsAwareDriver = (JavascriptExecutor) localDriver; | ||
fedcmDriver = (HasFederatedCredentialManagement) localDriver; | ||
localDriver.get(appServer.whereIs("/fedcm/fedcm.html")); | ||
} | ||
|
||
private Object triggerFedCm() { | ||
return jsAwareDriver.executeScript("triggerFedCm()"); | ||
} | ||
|
||
@Test | ||
void testDismissDialog() { | ||
fedcmDriver.setDelayEnabled(false); | ||
|
||
//assertThat(response).asInstanceOf(MAP).containsEntry("status", "OK"); | ||
Object response = triggerFedCm(); | ||
|
||
|
||
FederatedCredentialManagementDialog dialog = fedcmDriver.getFederatedCredentialManagementDialog(); | ||
|
||
// Attempt to use the credential to get an assertion. | ||
assertThat(response) | ||
.extracting("credential.rawId") | ||
.asInstanceOf(MAP) | ||
.containsEntry("status", "OK"); | ||
} | ||
|
||
} |