Commit de1d4c66 authored by Nina Satragno's avatar Nina Satragno Committed by Commit Bot

[chromedriver] Add RemoveVirtualAuthenticator command

Add the `RemoveVirtualAuthenticator` command to ChromeDriver.

A draft of the proposed addition to the specification is available at
https://github.com/w3c/webauthn/pull/1256

This is one in a series of patches intended to create a Testing API for
WebAuthn, for use in Web Platform Tests and by external webauthn tests.

For an overview of overall design, please see
https://docs.google.com/document/d/1bp2cMgjm2HSpvL9-WsJoIQMsBi1oKGQY6CvWD-9WmIQ/edit?usp=sharing

Bug: 922572
Change-Id: I5b6094cc5eb9a52afc8ee89d548c3452a728b1fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713301
Auto-Submit: Nina Satragno <nsatragno@chromium.org>
Commit-Queue: John Chen <johnchen@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679727}
parent c0c24351
...@@ -629,3 +629,7 @@ class ChromeDriver(object): ...@@ -629,3 +629,7 @@ class ChromeDriver(object):
options['isUserVerified'] = isUserVerified options['isUserVerified'] = isUserVerified
return self.ExecuteCommand(Command.ADD_VIRTUAL_AUTHENTICATOR, options) return self.ExecuteCommand(Command.ADD_VIRTUAL_AUTHENTICATOR, options)
def RemoveVirtualAuthenticator(self, authenticatorId):
params = {'authenticatorId': authenticatorId}
return self.ExecuteCommand(Command.REMOVE_VIRTUAL_AUTHENTICATOR, params)
...@@ -170,6 +170,9 @@ class Command(object): ...@@ -170,6 +170,9 @@ class Command(object):
_Method.POST, '/session/:sessionId/reporting/generate_test_report') _Method.POST, '/session/:sessionId/reporting/generate_test_report')
ADD_VIRTUAL_AUTHENTICATOR = ( ADD_VIRTUAL_AUTHENTICATOR = (
_Method.POST, '/session/:sessionId/webauthn/authenticator') _Method.POST, '/session/:sessionId/webauthn/authenticator')
REMOVE_VIRTUAL_AUTHENTICATOR = (
_Method.DELETE,
'/session/:sessionId/webauthn/authenticator/:authenticatorId')
# Custom Chrome commands. # Custom Chrome commands.
IS_LOADING = (_Method.GET, '/session/:sessionId/is_loading') IS_LOADING = (_Method.GET, '/session/:sessionId/is_loading')
......
...@@ -741,13 +741,20 @@ HttpHandler::HttpHandler( ...@@ -741,13 +741,20 @@ HttpHandler::HttpHandler(
// Extension for WebAuthn API: // Extension for WebAuthn API:
// TODO(nsatragno): Update the link to the official spec once it lands. // TODO(nsatragno): Update the link to the official spec once it lands.
// https://github.com/nsatragno/webauthn/pull/1/files // https://github.com/w3c/webauthn/pull/1256
CommandMapping(kPost, "session/:sessionId/webauthn/authenticator", CommandMapping(kPost, "session/:sessionId/webauthn/authenticator",
WrapToCommand("AddVirtualAuthenticator", WrapToCommand("AddVirtualAuthenticator",
base::BindRepeating( base::BindRepeating(
&ExecuteWebAuthnCommand, &ExecuteWebAuthnCommand,
base::BindRepeating( base::BindRepeating(
&ExecuteAddVirtualAuthenticator)))), &ExecuteAddVirtualAuthenticator)))),
CommandMapping(
kDelete, "session/:sessionId/webauthn/authenticator/:authenticatorId",
WrapToCommand(
"RemoveVirtualAuthenticator",
base::BindRepeating(
&ExecuteWebAuthnCommand,
base::BindRepeating(&ExecuteRemoveVirtualAuthenticator)))),
// //
// Non-standard extension commands // Non-standard extension commands
......
...@@ -224,6 +224,7 @@ _ANDROID_NEGATIVE_FILTER['chrome'] = ( ...@@ -224,6 +224,7 @@ _ANDROID_NEGATIVE_FILTER['chrome'] = (
'ChromeDriverTest.testNewTabDoesNotFocus', 'ChromeDriverTest.testNewTabDoesNotFocus',
# Android does not support the virtual authenticator environment. # Android does not support the virtual authenticator environment.
'ChromeDriverSecureContextTest.testAddVirtualAuthenticator', 'ChromeDriverSecureContextTest.testAddVirtualAuthenticator',
'ChromeDriverSecureContextTest.testRemoveVirtualAuthenticator',
] ]
) )
_ANDROID_NEGATIVE_FILTER['chrome_stable'] = ( _ANDROID_NEGATIVE_FILTER['chrome_stable'] = (
...@@ -2052,6 +2053,32 @@ class ChromeDriverSecureContextTest(ChromeDriverBaseTest): ...@@ -2052,6 +2053,32 @@ class ChromeDriverSecureContextTest(ChromeDriverBaseTest):
self.assertEquals('OK', result['status']) self.assertEquals('OK', result['status'])
self.assertEquals(['usb'], result['credential']['transports']) self.assertEquals(['usb'], result['credential']['transports'])
def testRemoveVirtualAuthenticator(self):
self._driver.Load(self.GetHttpsUrlForFile(
'/chromedriver/webauthn_test.html', 'chromedriver.test'))
# Removing a non existent virtual authenticator should fail.
self.assertRaisesRegexp(
chromedriver.InvalidArgument,
'Could not find a Virtual Authenticator matching the ID',
self._driver.RemoveVirtualAuthenticator, 'id')
# Create an authenticator and try removing it.
response = self._driver.AddVirtualAuthenticator(
protocol = 'ctap2',
transport = 'usb',
hasResidentKey = False,
hasUserVerification = False,
)
self._driver.RemoveVirtualAuthenticator(response['authenticatorId'])
# Trying to remove the same authenticator should fail.
self.assertRaisesRegexp(
chromedriver.InvalidArgument,
'Could not find a Virtual Authenticator matching the ID',
self._driver.RemoveVirtualAuthenticator, response['authenticatorId'])
# Tests in the following class are expected to be moved to ChromeDriverTest # Tests in the following class are expected to be moved to ChromeDriverTest
# class when we no longer support the legacy mode. # class when we no longer support the legacy mode.
class ChromeDriverW3cTest(ChromeDriverBaseTestWithWebServer): class ChromeDriverW3cTest(ChromeDriverBaseTestWithWebServer):
......
...@@ -53,3 +53,15 @@ Status ExecuteAddVirtualAuthenticator(WebView* web_view, ...@@ -53,3 +53,15 @@ Status ExecuteAddVirtualAuthenticator(WebView* web_view,
return web_view->SendCommandAndGetResult("WebAuthn.addVirtualAuthenticator", return web_view->SendCommandAndGetResult("WebAuthn.addVirtualAuthenticator",
options, value); options, value);
} }
Status ExecuteRemoveVirtualAuthenticator(WebView* web_view,
const base::Value& params,
std::unique_ptr<base::Value>* value) {
base::DictionaryValue options;
const base::Value* authenticatorId = params.FindKey("authenticatorId");
if (authenticatorId)
options.SetKey("authenticatorId", authenticatorId->Clone());
return web_view->SendCommandAndGetResult(
"WebAuthn.removeVirtualAuthenticator", options, value);
}
...@@ -34,4 +34,9 @@ Status ExecuteAddVirtualAuthenticator(WebView* web_view, ...@@ -34,4 +34,9 @@ Status ExecuteAddVirtualAuthenticator(WebView* web_view,
const base::Value& params, const base::Value& params,
std::unique_ptr<base::Value>* value); std::unique_ptr<base::Value>* value);
// Remove a virtual authenticator.
Status ExecuteRemoveVirtualAuthenticator(WebView* web_view,
const base::Value& params,
std::unique_ptr<base::Value>* value);
#endif // CHROME_TEST_CHROMEDRIVER_WEBAUTHN_COMMANDS_H_ #endif // CHROME_TEST_CHROMEDRIVER_WEBAUTHN_COMMANDS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment