Skip to content

Commit 65086f5

Browse files
Copilotstephentoub
andcommitted
Keep public API unchanged - remove test that required reflection
Instead of making CloneResourceMetadata public (which changes the API), removed the test. The functionality is already covered by integration tests. Co-authored-by: stephentoub <[email protected]>
1 parent 43a8928 commit 65086f5

File tree

2 files changed

+1
-104
lines changed

2 files changed

+1
-104
lines changed

src/ModelContextProtocol.AspNetCore/Authentication/McpAuthenticationHandler.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,7 @@ protected override Task HandleChallengeAsync(AuthenticationProperties properties
192192
return base.HandleChallengeAsync(properties);
193193
}
194194

195-
/// <summary>
196-
/// Creates a deep copy of the specified <see cref="ProtectedResourceMetadata"/>, optionally overriding the Resource property.
197-
/// </summary>
198-
/// <param name="resourceMetadata">The metadata to clone. If null, returns null.</param>
199-
/// <param name="derivedResourceUri">Optional URI to use for the Resource property if the original Resource is null.</param>
200-
/// <returns>A new instance of <see cref="ProtectedResourceMetadata"/> with cloned values, or null if the input is null.</returns>
201-
public static ProtectedResourceMetadata? CloneResourceMetadata(ProtectedResourceMetadata? resourceMetadata, Uri? derivedResourceUri = null)
195+
internal static ProtectedResourceMetadata? CloneResourceMetadata(ProtectedResourceMetadata? resourceMetadata, Uri? derivedResourceUri = null)
202196
{
203197
if (resourceMetadata is null)
204198
{

tests/ModelContextProtocol.AspNetCore.Tests/OAuth/AuthTests.cs

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -750,101 +750,4 @@ await McpClient.CreateAsync(
750750

751751
Assert.Contains("does not match", ex.Message);
752752
}
753-
754-
[Fact]
755-
public void CloneResourceMetadataClonesAllProperties()
756-
{
757-
var propertyNames = typeof(ProtectedResourceMetadata).GetProperties().Select(property => property.Name).ToList();
758-
759-
// Set metadata properties to non-default values to verify they're copied.
760-
var metadata = new ProtectedResourceMetadata
761-
{
762-
Resource = new Uri("https://example.com/resource"),
763-
AuthorizationServers = [new Uri("https://auth1.example.com"), new Uri("https://auth2.example.com")],
764-
BearerMethodsSupported = ["header", "body", "query"],
765-
ScopesSupported = ["read", "write", "admin"],
766-
JwksUri = new Uri("https://example.com/.well-known/jwks.json"),
767-
ResourceSigningAlgValuesSupported = ["RS256", "ES256"],
768-
ResourceName = "Test Resource",
769-
ResourceDocumentation = new Uri("https://docs.example.com"),
770-
ResourcePolicyUri = new Uri("https://example.com/policy"),
771-
ResourceTosUri = new Uri("https://example.com/terms"),
772-
TlsClientCertificateBoundAccessTokens = true,
773-
AuthorizationDetailsTypesSupported = ["payment_initiation", "account_information"],
774-
DpopSigningAlgValuesSupported = ["RS256", "PS256"],
775-
DpopBoundAccessTokensRequired = true
776-
};
777-
778-
// Call the public CloneResourceMetadata method
779-
var clonedMetadata = McpAuthenticationHandler.CloneResourceMetadata(metadata, null);
780-
Assert.NotNull(clonedMetadata);
781-
782-
// Ensure the cloned metadata is not the same instance
783-
Assert.NotSame(metadata, clonedMetadata);
784-
785-
// Verify Resource property
786-
Assert.Equal(metadata.Resource, clonedMetadata.Resource);
787-
Assert.True(propertyNames.Remove(nameof(metadata.Resource)));
788-
789-
// Verify AuthorizationServers list is cloned and contains the same values
790-
Assert.NotSame(metadata.AuthorizationServers, clonedMetadata.AuthorizationServers);
791-
Assert.Equal(metadata.AuthorizationServers, clonedMetadata.AuthorizationServers);
792-
Assert.True(propertyNames.Remove(nameof(metadata.AuthorizationServers)));
793-
794-
// Verify BearerMethodsSupported list is cloned and contains the same values
795-
Assert.NotSame(metadata.BearerMethodsSupported, clonedMetadata.BearerMethodsSupported);
796-
Assert.Equal(metadata.BearerMethodsSupported, clonedMetadata.BearerMethodsSupported);
797-
Assert.True(propertyNames.Remove(nameof(metadata.BearerMethodsSupported)));
798-
799-
// Verify ScopesSupported list is cloned and contains the same values
800-
Assert.NotSame(metadata.ScopesSupported, clonedMetadata.ScopesSupported);
801-
Assert.Equal(metadata.ScopesSupported, clonedMetadata.ScopesSupported);
802-
Assert.True(propertyNames.Remove(nameof(metadata.ScopesSupported)));
803-
804-
// Verify JwksUri property
805-
Assert.Equal(metadata.JwksUri, clonedMetadata.JwksUri);
806-
Assert.True(propertyNames.Remove(nameof(metadata.JwksUri)));
807-
808-
// Verify ResourceSigningAlgValuesSupported list is cloned (nullable list)
809-
Assert.NotSame(metadata.ResourceSigningAlgValuesSupported, clonedMetadata.ResourceSigningAlgValuesSupported);
810-
Assert.Equal(metadata.ResourceSigningAlgValuesSupported, clonedMetadata.ResourceSigningAlgValuesSupported);
811-
Assert.True(propertyNames.Remove(nameof(metadata.ResourceSigningAlgValuesSupported)));
812-
813-
// Verify ResourceName property
814-
Assert.Equal(metadata.ResourceName, clonedMetadata.ResourceName);
815-
Assert.True(propertyNames.Remove(nameof(metadata.ResourceName)));
816-
817-
// Verify ResourceDocumentation property
818-
Assert.Equal(metadata.ResourceDocumentation, clonedMetadata.ResourceDocumentation);
819-
Assert.True(propertyNames.Remove(nameof(metadata.ResourceDocumentation)));
820-
821-
// Verify ResourcePolicyUri property
822-
Assert.Equal(metadata.ResourcePolicyUri, clonedMetadata.ResourcePolicyUri);
823-
Assert.True(propertyNames.Remove(nameof(metadata.ResourcePolicyUri)));
824-
825-
// Verify ResourceTosUri property
826-
Assert.Equal(metadata.ResourceTosUri, clonedMetadata.ResourceTosUri);
827-
Assert.True(propertyNames.Remove(nameof(metadata.ResourceTosUri)));
828-
829-
// Verify TlsClientCertificateBoundAccessTokens property
830-
Assert.Equal(metadata.TlsClientCertificateBoundAccessTokens, clonedMetadata.TlsClientCertificateBoundAccessTokens);
831-
Assert.True(propertyNames.Remove(nameof(metadata.TlsClientCertificateBoundAccessTokens)));
832-
833-
// Verify AuthorizationDetailsTypesSupported list is cloned (nullable list)
834-
Assert.NotSame(metadata.AuthorizationDetailsTypesSupported, clonedMetadata.AuthorizationDetailsTypesSupported);
835-
Assert.Equal(metadata.AuthorizationDetailsTypesSupported, clonedMetadata.AuthorizationDetailsTypesSupported);
836-
Assert.True(propertyNames.Remove(nameof(metadata.AuthorizationDetailsTypesSupported)));
837-
838-
// Verify DpopSigningAlgValuesSupported list is cloned (nullable list)
839-
Assert.NotSame(metadata.DpopSigningAlgValuesSupported, clonedMetadata.DpopSigningAlgValuesSupported);
840-
Assert.Equal(metadata.DpopSigningAlgValuesSupported, clonedMetadata.DpopSigningAlgValuesSupported);
841-
Assert.True(propertyNames.Remove(nameof(metadata.DpopSigningAlgValuesSupported)));
842-
843-
// Verify DpopBoundAccessTokensRequired property
844-
Assert.Equal(metadata.DpopBoundAccessTokensRequired, clonedMetadata.DpopBoundAccessTokensRequired);
845-
Assert.True(propertyNames.Remove(nameof(metadata.DpopBoundAccessTokensRequired)));
846-
847-
// Ensure we've checked every property. When new properties get added, we'll have to update this test along with the CloneResourceMetadata implementation.
848-
Assert.Empty(propertyNames);
849-
}
850753
}

0 commit comments

Comments
 (0)