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

[dotnet] Fix WebDriver.AuthenticatorId #14814

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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