Skip to content

Commit

Permalink
[dotnet] Fix webauth credential to allow nullable rpID (#15201)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko authored Jan 31, 2025
1 parent 9e28ba8 commit 74feb5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions dotnet/src/webdriver/VirtualAuth/Credential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public sealed class Credential
private readonly byte[] id;
private readonly byte[]? userHandle;

private Credential(byte[] id, bool isResidentCredential, string rpId, string privateKey, byte[]? userHandle, int signCount)
private Credential(byte[] id, bool isResidentCredential, string? rpId, string privateKey, byte[]? userHandle, int signCount)
{
this.id = id ?? throw new ArgumentNullException(nameof(id));
this.IsResidentCredential = isResidentCredential;
this.RpId = rpId ?? throw new ArgumentNullException(nameof(rpId));
this.RpId = rpId;
this.PrivateKey = privateKey ?? throw new ArgumentNullException(nameof(privateKey));
this.userHandle = userHandle;
this.SignCount = signCount;
Expand All @@ -52,7 +52,7 @@ private Credential(byte[] id, bool isResidentCredential, string rpId, string pri
/// <param name="privateKey">The private Key for the credentials.</param>
/// <param name="signCount">The signature counter for the credentials.</param>
/// <returns>The created instance of the Credential class.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="id"/>, <paramref name="rpId"/>, or <paramref name="privateKey"/> are <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="id"/> or <paramref name="privateKey"/> are <see langword="null"/>.</exception>
public static Credential CreateNonResidentCredential(byte[] id, string rpId, string privateKey, int signCount)
{
return new Credential(id, false, rpId, privateKey, null, signCount);
Expand All @@ -67,7 +67,7 @@ public static Credential CreateNonResidentCredential(byte[] id, string rpId, str
/// <param name="userHandle">The user handle associated to the credential.</param>
/// <param name="signCount">The signature counter for the credentials.</param>
/// <returns>The created instance of the Credential class.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="id"/>, <paramref name="rpId"/>, or <paramref name="privateKey"/> are <see langword="null"/>.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="id"/> or <paramref name="privateKey"/> are <see langword="null"/>.</exception>
public static Credential CreateResidentCredential(byte[] id, string rpId, string privateKey, byte[] userHandle, int signCount)
{
return new Credential(id, true, rpId, privateKey, userHandle, signCount);
Expand All @@ -86,7 +86,7 @@ public static Credential CreateResidentCredential(byte[] id, string rpId, string
/// <summary>
/// Gets the ID of the relying party of this credential.
/// </summary>
public string RpId { get; }
public string? RpId { get; }

/// <summary>
/// Gets the private key of the credential.
Expand Down Expand Up @@ -130,7 +130,10 @@ public Dictionary<string, object> ToDictionary()

toReturn["credentialId"] = Base64UrlEncoder.Encode(this.id);
toReturn["isResidentCredential"] = this.IsResidentCredential;
toReturn["rpId"] = this.RpId;
if (this.RpId is not null)
{
toReturn["rpId"] = this.RpId;
}
toReturn["privateKey"] = this.PrivateKey;
toReturn["signCount"] = this.SignCount;
if (this.userHandle is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public void ShouldRemoveAllCredentials()
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Virtual Authenticator")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Virtual Authenticator")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Virtual Authenticator")]
public void testSetUserVerified()
public void TestSetUserVerified()
{
CreateRKEnabledCTAP2Authenticator();

Expand Down

0 comments on commit 74feb5d

Please sign in to comment.