Skip to content

Commit cfaa8c4

Browse files
[dotnet] Fix WebDriver.AuthenticatorId to return proper state set by user (#14814)
1 parent 4fe2a56 commit cfaa8c4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Diff for: dotnet/src/webdriver/WebDriver.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
4545
private NetworkManager network;
4646
private WebElementFactory elementFactory;
4747
private SessionId sessionId;
48-
private String authenticatorId;
4948
private List<string> registeredCommands = new List<string>();
5049

5150
/// <summary>
@@ -1046,8 +1045,8 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options)
10461045
{
10471046
Response commandResponse = this.Execute(DriverCommand.AddVirtualAuthenticator, options.ToDictionary());
10481047
string id = commandResponse.Value.ToString();
1049-
this.authenticatorId = id;
1050-
return this.authenticatorId;
1048+
this.AuthenticatorId = id;
1049+
return this.AuthenticatorId;
10511050
}
10521051

10531052
/// <summary>
@@ -1057,15 +1056,15 @@ public string AddVirtualAuthenticator(VirtualAuthenticatorOptions options)
10571056
public void RemoveVirtualAuthenticator(string authenticatorId)
10581057
{
10591058
Dictionary<string, object> parameters = new Dictionary<string, object>();
1060-
parameters.Add("authenticatorId", this.authenticatorId);
1059+
parameters.Add("authenticatorId", this.AuthenticatorId);
10611060
this.Execute(DriverCommand.RemoveVirtualAuthenticator, parameters);
1062-
this.authenticatorId = null;
1061+
this.AuthenticatorId = null;
10631062
}
10641063

10651064
/// <summary>
10661065
/// Gets the virtual authenticator ID for this WebDriver instance.
10671066
/// </summary>
1068-
public string AuthenticatorId { get; }
1067+
public string AuthenticatorId { get; private set; }
10691068

10701069
/// <summary>
10711070
/// Add a credential to the Virtual Authenticator/
@@ -1074,7 +1073,7 @@ public void RemoveVirtualAuthenticator(string authenticatorId)
10741073
public void AddCredential(Credential credential)
10751074
{
10761075
Dictionary<string, object> parameters = new Dictionary<string, object>(credential.ToDictionary());
1077-
parameters.Add("authenticatorId", this.authenticatorId);
1076+
parameters.Add("authenticatorId", this.AuthenticatorId);
10781077

10791078
this.Execute(driverCommandToExecute: DriverCommand.AddCredential, parameters);
10801079
}
@@ -1086,7 +1085,7 @@ public void AddCredential(Credential credential)
10861085
public List<Credential> GetCredentials()
10871086
{
10881087
Dictionary<string, object> parameters = new Dictionary<string, object>();
1089-
parameters.Add("authenticatorId", this.authenticatorId);
1088+
parameters.Add("authenticatorId", this.AuthenticatorId);
10901089

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

@@ -1117,7 +1116,7 @@ public void RemoveCredential(byte[] credentialId)
11171116
public void RemoveCredential(string credentialId)
11181117
{
11191118
Dictionary<string, object> parameters = new Dictionary<string, object>();
1120-
parameters.Add("authenticatorId", this.authenticatorId);
1119+
parameters.Add("authenticatorId", this.AuthenticatorId);
11211120
parameters.Add("credentialId", credentialId);
11221121

11231122
this.Execute(driverCommandToExecute: DriverCommand.RemoveCredential, parameters);
@@ -1129,7 +1128,7 @@ public void RemoveCredential(string credentialId)
11291128
public void RemoveAllCredentials()
11301129
{
11311130
Dictionary<string, object> parameters = new Dictionary<string, object>();
1132-
parameters.Add("authenticatorId", this.authenticatorId);
1131+
parameters.Add("authenticatorId", this.AuthenticatorId);
11331132

11341133
this.Execute(driverCommandToExecute: DriverCommand.RemoveAllCredentials, parameters);
11351134
}
@@ -1141,7 +1140,7 @@ public void RemoveAllCredentials()
11411140
public void SetUserVerified(bool verified)
11421141
{
11431142
Dictionary<string, object> parameters = new Dictionary<string, object>();
1144-
parameters.Add("authenticatorId", this.authenticatorId);
1143+
parameters.Add("authenticatorId", this.AuthenticatorId);
11451144
parameters.Add("isUserVerified", verified);
11461145

11471146
this.Execute(driverCommandToExecute: DriverCommand.SetUserVerified, parameters);

Diff for: dotnet/test/common/VirtualAuthn/VirtualAuthenticatorTest.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public void Setup()
7171
[TearDown]
7272
public void Teardown()
7373
{
74-
if (webDriver.AuthenticatorId != null)
74+
if (webDriver.AuthenticatorId is not null &&
75+
webDriver.SessionId is not null)
7576
{
7677
webDriver.RemoveVirtualAuthenticator(webDriver.AuthenticatorId);
7778
}
@@ -186,6 +187,8 @@ public void ShouldRemoveAuthenticator()
186187
{
187188
VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions();
188189
string authenticatorId = webDriver.AddVirtualAuthenticator(options);
190+
Assert.That(webDriver.AuthenticatorId, Is.EqualTo(authenticatorId));
191+
189192
webDriver.RemoveVirtualAuthenticator(authenticatorId);
190193

191194
Assert.IsNull(webDriver.AuthenticatorId);

0 commit comments

Comments
 (0)