From 6574210b915d7c1296bffb146de550ba06231b8f Mon Sep 17 00:00:00 2001 From: Michael Render Date: Tue, 26 Nov 2024 17:33:33 -0500 Subject: [PATCH 1/2] [dotnet] Fix `WebDriver.AuthenticatorId` --- dotnet/src/webdriver/WebDriver.cs | 21 +++++++++---------- .../VirtualAuthn/VirtualAuthenticatorTest.cs | 2 ++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/dotnet/src/webdriver/WebDriver.cs b/dotnet/src/webdriver/WebDriver.cs index 235b2e648058e..4b986eddc6ff8 100644 --- a/dotnet/src/webdriver/WebDriver.cs +++ b/dotnet/src/webdriver/WebDriver.cs @@ -45,7 +45,6 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds private NetworkManager network; private WebElementFactory elementFactory; private SessionId sessionId; - private String authenticatorId; private List registeredCommands = new List(); /// @@ -1046,8 +1045,8 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options) { Response commandResponse = this.Execute(DriverCommand.AddVirtualAuthenticator, options.ToDictionary()); string id = commandResponse.Value.ToString(); - this.authenticatorId = id; - return this.authenticatorId; + this.AuthenticatorId = id; + return this.AuthenticatorId; } /// @@ -1057,15 +1056,15 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options) public void RemoveVirtualAuthenticator(string authenticatorId) { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); this.Execute(DriverCommand.RemoveVirtualAuthenticator, parameters); - this.authenticatorId = null; + this.AuthenticatorId = null; } /// /// Gets the virtual authenticator ID for this WebDriver instance. /// - public string AuthenticatorId { get; } + public string AuthenticatorId { get; private set; } /// /// Add a credential to the Virtual Authenticator/ @@ -1074,7 +1073,7 @@ public void RemoveVirtualAuthenticator(string authenticatorId) public void AddCredential(Credential credential) { Dictionary parameters = new Dictionary(credential.ToDictionary()); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); this.Execute(driverCommandToExecute: DriverCommand.AddCredential, parameters); } @@ -1086,7 +1085,7 @@ public void AddCredential(Credential credential) public List GetCredentials() { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); object[] commandResponse = (object[])this.Execute(driverCommandToExecute: DriverCommand.GetCredentials, parameters).Value; @@ -1117,7 +1116,7 @@ public void RemoveCredential(byte[] credentialId) public void RemoveCredential(string credentialId) { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); parameters.Add("credentialId", credentialId); this.Execute(driverCommandToExecute: DriverCommand.RemoveCredential, parameters); @@ -1129,7 +1128,7 @@ public void RemoveCredential(string credentialId) public void RemoveAllCredentials() { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); this.Execute(driverCommandToExecute: DriverCommand.RemoveAllCredentials, parameters); } @@ -1141,7 +1140,7 @@ public void RemoveAllCredentials() public void SetUserVerified(bool verified) { Dictionary parameters = new Dictionary(); - parameters.Add("authenticatorId", this.authenticatorId); + parameters.Add("authenticatorId", this.AuthenticatorId); parameters.Add("isUserVerified", verified); this.Execute(driverCommandToExecute: DriverCommand.SetUserVerified, parameters); diff --git a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs index a5a8d53d73da4..76a5ac9cf9e24 100644 --- a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs +++ b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs @@ -186,6 +186,8 @@ public void ShouldRemoveAuthenticator() { VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions(); string authenticatorId = webDriver.AddVirtualAuthenticator(options); + Assert.That(webDriver.AuthenticatorId, Is.EqualTo(authenticatorId)); + webDriver.RemoveVirtualAuthenticator(authenticatorId); Assert.IsNull(webDriver.AuthenticatorId); From bc99d5f68fbe8220eea33da3a480dc922939b56f Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 27 Nov 2024 14:05:14 -0500 Subject: [PATCH 2/2] Don't remove the virtual authenticator if the web driver has been disposed --- dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs index 76a5ac9cf9e24..e6c16e11b673a 100644 --- a/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs +++ b/dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs @@ -71,7 +71,8 @@ public void Setup() [TearDown] public void Teardown() { - if (webDriver.AuthenticatorId != null) + if (webDriver.AuthenticatorId is not null && + webDriver.SessionId is not null) { webDriver.RemoveVirtualAuthenticator(webDriver.AuthenticatorId); }