Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
Handle null secret in HashedSharedSecretValidator #3404
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Jul 9, 2019
1 parent fd15f76 commit 7be6a8d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Expand Up @@ -82,6 +82,11 @@ public Task<SecretValidationResult> ValidateAsync(IEnumerable<Secret> secrets, P
_logger.LogInformation("Secret: {description} uses invalid hashing algorithm.", secretDescription);
return fail;
}
catch (ArgumentNullException)
{
_logger.LogInformation("Secret: {description} is null.", secretDescription);
return fail;
}

if (secretBytes.Length == 32)
{
Expand Down
Expand Up @@ -140,5 +140,23 @@ public async Task Client_with_no_Secret_Should_Fail()
var result = await _validator.ValidateAsync(client.ClientSecrets, secret);
result.Success.Should().BeFalse();
}

[Fact]
[Trait("Category", Category)]
public async Task Client_with_null_Secret_Should_Fail()
{
var clientId = "null_secret_client";
var client = await _clients.FindEnabledClientByIdAsync(clientId);

var secret = new ParsedSecret
{
Id = clientId,
Type = IdentityServerConstants.ParsedSecretTypes.SharedSecret,
Credential = "secret"
};

var result = await _validator.ValidateAsync(client.ClientSecrets, secret);
result.Success.Should().BeFalse();
}
}
}
Expand Up @@ -140,5 +140,23 @@ public async Task Client_with_no_Secret_Should_Fail()
var result = await _validator.ValidateAsync(client.ClientSecrets, secret);
result.Success.Should().BeFalse();
}

[Fact]
[Trait("Category", Category)]
public async Task Client_with_null_Secret_Should_Fail()
{
var clientId = "null_secret_client";
var client = await _clients.FindEnabledClientByIdAsync(clientId);

var secret = new ParsedSecret
{
Id = clientId,
Type = IdentityServerConstants.ParsedSecretTypes.SharedSecret,
Credential = "secret"
};

var result = await _validator.ValidateAsync(client.ClientSecrets, secret);
result.Success.Should().BeFalse();
}
}
}
Expand Up @@ -36,6 +36,14 @@ public static List<Client> Get()
Enabled = true
},

new Client
{
ClientName = "Client with null secret set",
ClientId = "null_secret_client",
Enabled = true,
ClientSecrets = { new Secret(null) }
},

new Client
{
ClientName = "Client with single secret, no protection, no expiration",
Expand Down

0 comments on commit 7be6a8d

Please sign in to comment.