Skip to content

Commit

Permalink
[dotnet] Fix WebDriver.AuthenticatorId to return proper state set b…
Browse files Browse the repository at this point in the history
…y user (#14814)
  • Loading branch information
RenderMichael authored Nov 27, 2024
1 parent 4fe2a56 commit cfaa8c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 10 additions & 11 deletions dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> registeredCommands = new List<string>();

/// <summary>
Expand Down Expand Up @@ -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;
}

/// <summary>
Expand All @@ -1057,15 +1056,15 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options)
public void RemoveVirtualAuthenticator(string authenticatorId)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("authenticatorId", this.authenticatorId);
parameters.Add("authenticatorId", this.AuthenticatorId);
this.Execute(DriverCommand.RemoveVirtualAuthenticator, parameters);
this.authenticatorId = null;
this.AuthenticatorId = null;
}

/// <summary>
/// Gets the virtual authenticator ID for this WebDriver instance.
/// </summary>
public string AuthenticatorId { get; }
public string AuthenticatorId { get; private set; }

/// <summary>
/// Add a credential to the Virtual Authenticator/
Expand All @@ -1074,7 +1073,7 @@ public void RemoveVirtualAuthenticator(string authenticatorId)
public void AddCredential(Credential credential)
{
Dictionary<string, object> parameters = new Dictionary<string, object>(credential.ToDictionary());
parameters.Add("authenticatorId", this.authenticatorId);
parameters.Add("authenticatorId", this.AuthenticatorId);

this.Execute(driverCommandToExecute: DriverCommand.AddCredential, parameters);
}
Expand All @@ -1086,7 +1085,7 @@ public void AddCredential(Credential credential)
public List<Credential> GetCredentials()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("authenticatorId", this.authenticatorId);
parameters.Add("authenticatorId", this.AuthenticatorId);

object[] commandResponse = (object[])this.Execute(driverCommandToExecute: DriverCommand.GetCredentials, parameters).Value;

Expand Down Expand Up @@ -1117,7 +1116,7 @@ public void RemoveCredential(byte[] credentialId)
public void RemoveCredential(string credentialId)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("authenticatorId", this.authenticatorId);
parameters.Add("authenticatorId", this.AuthenticatorId);
parameters.Add("credentialId", credentialId);

this.Execute(driverCommandToExecute: DriverCommand.RemoveCredential, parameters);
Expand All @@ -1129,7 +1128,7 @@ public void RemoveCredential(string credentialId)
public void RemoveAllCredentials()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("authenticatorId", this.authenticatorId);
parameters.Add("authenticatorId", this.AuthenticatorId);

this.Execute(driverCommandToExecute: DriverCommand.RemoveAllCredentials, parameters);
}
Expand All @@ -1141,7 +1140,7 @@ public void RemoveAllCredentials()
public void SetUserVerified(bool verified)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("authenticatorId", this.authenticatorId);
parameters.Add("authenticatorId", this.AuthenticatorId);
parameters.Add("isUserVerified", verified);

this.Execute(driverCommandToExecute: DriverCommand.SetUserVerified, parameters);
Expand Down
5 changes: 4 additions & 1 deletion dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -186,6 +187,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);
Expand Down

0 comments on commit cfaa8c4

Please sign in to comment.