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

Adds Id to Credential Description #94

Merged
merged 3 commits into from
Sep 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ namespace Microsoft.Identity.Abstractions
/// </summary>
public class CredentialDescription
{
private string? _cachedId;

/// <summary>
/// Gets a unique identifier for a CredentialDescription based on <see cref="SourceType"/> and <see cref="ReferenceOrValue"/>.
/// </summary>
public string Id
sruke marked this conversation as resolved.
Show resolved Hide resolved
{
get
{
if (_cachedId == null)
_cachedId = $"{SourceType}_{Container}_{ReferenceOrValue}";

return _cachedId;
}
}

/// <summary>
/// Type of the source of the credential. This property is used to determine which other properties need
/// to be provided to describe the credential.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Security.AccessControl;
using Xunit;

namespace Microsoft.Identity.Abstractions.ApplicationOptions.Tests
Expand Down Expand Up @@ -411,6 +410,27 @@ public void TestValueOrReference(CredentialSource credentialSource)
Assert.Equal("referenceOrValue", credentialDescription.ReferenceOrValue);
}

[Theory]
[InlineData(CredentialSource.KeyVault, "KeyVaultUrl", "CertificateName")]
[InlineData(CredentialSource.KeyVault, null, "CertificateName")]
[InlineData(CredentialSource.KeyVault, "KeyVaultUrl", null)]
[InlineData(CredentialSource.KeyVault, null, null)]
public void TestId(CredentialSource sourceType, string credentialLocation, string credentialName)
{
var credentialDescription = new CredentialDescription
{
SourceType = sourceType,
Container = credentialLocation,
ReferenceOrValue = credentialName
};

var id = credentialDescription.Id;

var expectedId = $"{credentialDescription.SourceType}_{credentialDescription.Container}_{credentialDescription.ReferenceOrValue}";
sruke marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(expectedId, id);

var cachedId = credentialDescription.Id;
Assert.Equal(expectedId, cachedId);
}
}
}