Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Add FedCM support to the ruby selenium client #13796

Merged
merged 89 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
b1547d5
Start the work to add FedCM support to the ruby selenium client
aguspe Apr 10, 2024
86a63e1
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Apr 13, 2024
fc07c2b
Add fedcm tests
aguspe Apr 19, 2024
b1b6da7
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Apr 22, 2024
327f5bf
Update account initializer
aguspe Apr 22, 2024
7ed2560
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Apr 22, 2024
60550d5
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe May 2, 2024
0a84eac
Update tests and add module
aguspe May 9, 2024
2c1fd4b
Update tests
aguspe May 11, 2024
b867ce7
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe May 30, 2024
532e85a
Update fedcm tests
aguspe May 31, 2024
383a833
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe May 31, 2024
5a4cf26
Autoload FedCM
aguspe Jun 2, 2024
4d62eb8
Starting to run tests
aguspe Jun 3, 2024
8dae523
Expand dialog for FedCM
aguspe Jun 4, 2024
6ccf967
Add commands for dialog
aguspe Jun 5, 2024
f7997c8
Use has fedcm
aguspe Jun 7, 2024
47b54b1
Update dialog and commands
aguspe Jun 8, 2024
a62fa25
First test
aguspe Jun 8, 2024
5c22768
Improve test
aguspe Jun 8, 2024
db3cc8e
Improve test
aguspe Jun 8, 2024
799cbc2
Expand errors test
aguspe Jun 8, 2024
216953b
Added full flow test
aguspe Jun 8, 2024
9aaf61f
Improve test flow
aguspe Jun 9, 2024
ca55d27
Remove all the sleeps and added wait for dialog
aguspe Jun 9, 2024
ede8a6f
Update integration tests
aguspe Jun 9, 2024
c3cfced
Add unit tests for dialog
aguspe Jun 9, 2024
94d655f
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 9, 2024
23844c5
Fix rubocop alignment issues
aguspe Jun 9, 2024
d1e18fd
Remove duplication and correct alignment
aguspe Jun 9, 2024
6965382
Add types
aguspe Jun 9, 2024
05af6c9
Remove steepfile test
aguspe Jun 9, 2024
a4a2ad5
Remove unnecessary comment
aguspe Jun 9, 2024
a2d60bf
Fix select account
aguspe Jun 10, 2024
8be7ea9
Add extra type signatures
aguspe Jun 10, 2024
2e2171d
Add extra tests and click dialog
aguspe Jun 10, 2024
77337e3
Improve click dialog
aguspe Jun 10, 2024
5f961f8
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 10, 2024
85cae7c
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 10, 2024
d8e34ec
Address review comments
aguspe Jun 10, 2024
57e9acd
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 10, 2024
8a7656c
Remove not needed modules
aguspe Jun 10, 2024
ac7a99a
update integration tests
aguspe Jun 11, 2024
46955af
Clean integration tests
aguspe Jun 11, 2024
8011dc7
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 11, 2024
2b7e0f3
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 11, 2024
996cced
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 13, 2024
c61ec6a
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 14, 2024
dd9475c
Add tests
aguspe Jun 14, 2024
40d3ea2
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 14, 2024
9406c11
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 14, 2024
9a8b23a
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 14, 2024
b5bfeff
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 14, 2024
ae18632
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 14, 2024
952ff61
Fix Fedcm server
aguspe Jun 14, 2024
5a54bc9
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 14, 2024
559068f
Add extra tests
aguspe Jun 14, 2024
bae6296
Fix hash issues
aguspe Jun 15, 2024
408257c
Update types
aguspe Jun 15, 2024
ff62d85
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 15, 2024
80db8c7
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 16, 2024
38d7711
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 17, 2024
ca87836
Skip dialog test until further investigation on IDP
aguspe Jun 17, 2024
eaf0c27
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 17, 2024
2431257
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 17, 2024
c123eaf
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 17, 2024
88a810d
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 18, 2024
f88142a
Address review comments
aguspe Jun 19, 2024
2b4b409
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 19, 2024
aecf770
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 19, 2024
b77789b
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 20, 2024
3e883e8
Fix rubocop and edge issues
aguspe Jun 20, 2024
a67465e
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 20, 2024
45523ad
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 20, 2024
a950a9b
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 20, 2024
d10d854
Add edge to tests
aguspe Jun 21, 2024
1401b07
Merge branch 'add_fedcm_support_for_the_ruby_library' of github.com:a…
aguspe Jun 21, 2024
23e6969
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 21, 2024
780edbd
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 21, 2024
c71f1b1
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 21, 2024
5c8b689
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 21, 2024
b001426
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 21, 2024
318f9ca
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 22, 2024
086ec0c
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 22, 2024
5babcdc
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 22, 2024
78aa10a
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 22, 2024
066bf21
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 23, 2024
6c9288a
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
aguspe Jun 24, 2024
7e7486e
Merge branch 'trunk' into add_fedcm_support_for_the_ruby_library
p0deje Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 = `https://${location.host}/fedcm/fedcm.json`;
let configURL = `http://${location.host}/fedcm/fedcm.json`;
let promise = null;

function triggerFedCm() {
Expand Down
3 changes: 2 additions & 1 deletion common/src/web/fedcm/fedcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"accounts_endpoint": "accounts.json",
"client_metadata_endpoint": "client_metadata.json",
"id_assertion_endpoint": "id_assertion",
"signin_url": "/signin"
"signin_url": "/signin",
"login_url": "/login"
}
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/chromium/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Driver < WebDriver::Driver
EXTENSIONS = [DriverExtensions::HasCDP,
DriverExtensions::HasBiDi,
DriverExtensions::HasCasting,
DriverExtensions::HasFedCmDialog,
DriverExtensions::HasNetworkConditions,
DriverExtensions::HasNetworkInterception,
DriverExtensions::HasWebStorage,
Expand Down
3 changes: 3 additions & 0 deletions rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
require 'selenium/webdriver/common/driver_extensions/has_cdp'
require 'selenium/webdriver/common/driver_extensions/has_casting'
require 'selenium/webdriver/common/driver_extensions/has_launching'
require 'selenium/webdriver/common/driver_extensions/has_fedcm_dialog'
require 'selenium/webdriver/common/keys'
require 'selenium/webdriver/common/profile_helper'
require 'selenium/webdriver/common/options'
Expand All @@ -99,3 +100,5 @@
require 'selenium/webdriver/common/websocket_connection'
require 'selenium/webdriver/common/child_process'
require 'selenium/webdriver/common/script'
require 'selenium/webdriver/common/fedcm/account'
require 'selenium/webdriver/common/fedcm/dialog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

# 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.

module Selenium
aguspe marked this conversation as resolved.
Show resolved Hide resolved
module WebDriver
module DriverExtensions
module HasFedCmDialog
# Disables the promise rejection delay for FedCm.
#
# FedCm by default delays promise resolution in failure cases for privacy reasons.
# This method allows turning it off to let tests run faster where this is not relevant.
def enable_fedcm_delay=(enable)
@bridge.fedcm_delay(enable)
end

# Resets the FedCm dialog cooldown.
#
# If a user agent triggers a cooldown when the account chooser is dismissed,
# this method resets that cooldown so that the dialog can be triggered again immediately.
def reset_fedcm_cooldown
@bridge.reset_fedcm_cooldown
end

def fedcm_dialog
@fedcm_dialog ||= FedCM::Dialog.new(@bridge)
end

def wait_for_fedcm_dialog(timeout: 5, interval: 0.2, message: nil, ignore: nil)
wait = Wait.new(timeout: timeout, interval: interval, message: message, ignore: ignore)
wait.until do
fedcm_dialog if fedcm_dialog.type
rescue Error::NoSuchAlertError
nil
end
end
end # HasFedCmDialog
end # DriverExtensions
end # WebDriver
end # Selenium
27 changes: 27 additions & 0 deletions rb/lib/selenium/webdriver/common/fedcm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

# 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.

module Selenium
module WebDriver
module FedCM
autoload :Account, 'fedcm/account'
autoload :Dialog, 'fedcm/dialog'
end # FedCM
end # WebDriver
end # Selenium
50 changes: 50 additions & 0 deletions rb/lib/selenium/webdriver/common/fedcm/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

# 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.

module Selenium
module WebDriver
module FedCM
# Represents an account displayed in a FedCm account list.
# See: https://fedidcg.github.io/FedCM/#dictdef-identityprovideraccount
# https://fedidcg.github.io/FedCM/#webdriver-accountlist
class Account
LOGIN_STATE_SIGNIN = 'SignIn'
LOGIN_STATE_SIGNUP = 'SignUp'

attr_reader :account_id, :email, :name, :given_name, :picture_url,
:idp_config_url, :login_state, :terms_of_service_url, :privacy_policy_url

# Initializes a new account with the provided attributes.
#
# @param [Hash]
def initialize(**args)
@account_id = args['accountId']
@email = args['email']
@name = args['name']
@given_name = args['givenName']
@picture_url = args['pictureUrl']
@idp_config_url = args['idpConfigUrl']
@login_state = args['loginState']
@terms_of_service_url = args['termsOfServiceUrl']
@privacy_policy_url = args['privacyPolicyUrl']
end
end # Account
end # FedCM
end # WebDriver
end # Selenium
74 changes: 74 additions & 0 deletions rb/lib/selenium/webdriver/common/fedcm/dialog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frozen_string_literal: true

# 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.

module Selenium
module WebDriver
module FedCM
class Dialog
def initialize(bridge)
@bridge = bridge
end

DIALOG_TYPE_ACCOUNT_LIST = 'AccountChooser'
DIALOG_TYPE_AUTO_REAUTH = 'AutoReauthn'

# Closes the dialog as if the user had clicked X.
def click
@bridge.click_fedcm_dialog_button
end

# Closes the dialog as if the user had clicked X.
def cancel
@bridge.cancel_fedcm_dialog
end

# Selects an account as if the user had clicked on it.
#
# @param [Integer] index The index of the account to select from the list returned by get_accounts.
aguspe marked this conversation as resolved.
Show resolved Hide resolved
def select_account(index)
@bridge.select_fedcm_account index
end

# Returns the type of the open dialog.
#
# One of DIALOG_TYPE_ACCOUNT_LIST and DIALOG_TYPE_AUTO_REAUTH.
def type
@bridge.fedcm_dialog_type
end

# Returns the title of the dialog.
def title
@bridge.fedcm_title
end

# Returns the subtitle of the dialog or nil if none.
def subtitle
@bridge.fedcm_subtitle
end

# Returns the accounts shown in the account chooser.
#
# If this is an auto reauth dialog, returns the single account that is being signed in.
def accounts
@bridge.fedcm_account_list.map { |account| Account.new(**account) }
end
end # Dialog
end # FedCM
end # WebDriver
end # Selenium
40 changes: 40 additions & 0 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,46 @@ def user_verified(verified, authenticator_id)
execute :set_user_verified, {authenticatorId: authenticator_id}, {isUserVerified: verified}
end

#
# federated-credential management
#

def cancel_fedcm_dialog
execute :cancel_fedcm_dialog
end

def select_fedcm_account(index)
execute :select_fedcm_account, {}, {accountIndex: index}
end

def fedcm_dialog_type
execute :get_fedcm_dialog_type
end

def fedcm_title
execute(:get_fedcm_title).fetch('title')
end

def fedcm_subtitle
execute(:get_fedcm_title).fetch('subtitle', nil)
end

def fedcm_account_list
execute :get_fedcm_account_list
end

def fedcm_delay(enabled)
execute :set_fedcm_delay, {}, {enabled: enabled}
end

def reset_fedcm_cooldown
execute :reset_fedcm_cooldown
end

def click_fedcm_dialog_button
execute :click_fedcm_dialog_button, {}, {dialogButton: 'ConfirmIdpLoginContinue'}
end

def bidi
msg = 'BiDi must be enabled by setting #web_socket_url to true in options class'
raise(WebDriver::Error::WebDriverError, msg)
Expand Down
14 changes: 13 additions & 1 deletion rb/lib/selenium/webdriver/remote/bridge/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,20 @@ class Bridge
remove_credential: [:delete,
'session/:session_id/webauthn/authenticator/:authenticatorId/credentials/:credentialId'],
remove_all_credentials: [:delete, 'session/:session_id/webauthn/authenticator/:authenticatorId/credentials'],
set_user_verified: [:post, 'session/:session_id/webauthn/authenticator/:authenticatorId/uv']
set_user_verified: [:post, 'session/:session_id/webauthn/authenticator/:authenticatorId/uv'],

#
# federated-credential management
#

get_fedcm_title: [:get, 'session/:session_id/fedcm/gettitle'],
get_fedcm_dialog_type: [:get, 'session/:session_id/fedcm/getdialogtype'],
get_fedcm_account_list: [:get, 'session/:session_id/fedcm/accountlist'],
click_fedcm_dialog_button: [:post, 'session/:session_id/fedcm/clickdialogbutton'],
cancel_fedcm_dialog: [:post, 'session/:session_id/fedcm/canceldialog'],
select_fedcm_account: [:post, 'session/:session_id/fedcm/selectaccount'],
set_fedcm_delay: [:post, 'session/:session_id/fedcm/setdelayenabled'],
reset_fedcm_cooldown: [:post, 'session/:session_id/fedcm/resetcooldown']
}.freeze
end # Bridge
end # Remote
Expand Down
52 changes: 52 additions & 0 deletions rb/sig/lib/selenium/webdriver/fedcm/account.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Selenium
module WebDriver
module FedCM
# Represents an account displayed in a FedCm account list.
# See: https://fedidcg.github.io/FedCM/#dictdef-identityprovideraccount
# https://fedidcg.github.io/FedCM/#webdriver-accountlist
class Account
@account_id: String

@email: String

@name: String

@given_name: String

@picture_url: String

@idp_config_url: String

@login_state: String

@terms_of_service_url: String

@privacy_policy_url: String

LOGIN_STATE_SIGNIN: String

LOGIN_STATE_SIGNUP: String

attr_reader account_id: String

attr_reader email: String

attr_reader name: String

attr_reader given_name: String

attr_reader picture_url: String

attr_reader idp_config_url: String

attr_reader login_state: String

attr_reader terms_of_service_url: String

attr_reader privacy_policy_url: String

def initialize: (**untyped args) -> void
end
end
end
end
26 changes: 26 additions & 0 deletions rb/sig/lib/selenium/webdriver/fedcm/dialog.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Selenium
module WebDriver
module FedCM
class Dialog
DIALOG_TYPE_ACCOUNT_LIST: String
DIALOG_TYPE_AUTO_REAUTH: String

@bridge: Remote::Bridge

def accounts: -> Array[Account]

def cancel: -> Remote::Response?

def click: -> untyped

def select_account: (Integer index) -> Remote::Response?

def subtitle: -> (String | Remote::Response)?

def title: -> (String | Remote::Response)

def type: -> (String | Remote::Response)
end
end
end
end
Loading
Loading