Skip to content

Commit e96f4dc

Browse files
jeffhandleyCopilot
andcommitted
Rename RequireResource to ExpectResource in TestOAuthServer
The property now rejects requests that include a resource parameter when set to false, so ExpectResource better describes the bidirectional validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cd1cbc4 commit e96f4dc

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ await Assert.ThrowsAsync<McpException>(() => McpClient.CreateAsync(
586586
[Fact]
587587
public async Task CannotAuthenticate_WhenProtectedResourceMetadataMissingResource()
588588
{
589-
TestOAuthServer.RequireResource = false;
589+
TestOAuthServer.ExpectResource = false;
590590

591591
Builder.Services.Configure<McpAuthenticationOptions>(McpAuthenticationDefaults.AuthenticationScheme, options =>
592592
{
@@ -1051,7 +1051,7 @@ public async Task CanAuthenticate_WithLegacyServerWithoutProtectedResourceMetada
10511051
// 2025-03-26 backcompat: server does NOT serve PRM, but DOES serve auth server metadata.
10521052
// The client should fall back to using the MCP server's origin as the auth server
10531053
// and discover auth metadata from well-known URLs on that origin.
1054-
TestOAuthServer.RequireResource = false;
1054+
TestOAuthServer.ExpectResource = false;
10551055

10561056
// Use JwtBearer as the challenge scheme so the 401 response does NOT include resource_metadata.
10571057
Builder.Services.Configure<AuthenticationOptions>(options => options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme);
@@ -1166,7 +1166,7 @@ public async Task CanAuthenticate_WithLegacyServerUsingDefaultEndpointFallback()
11661166
// 2025-03-26 backcompat: server does NOT serve PRM AND does NOT serve auth server metadata.
11671167
// The client should fall back to default endpoint paths (/authorize, /token, /register)
11681168
// on the MCP server's origin.
1169-
TestOAuthServer.RequireResource = false;
1169+
TestOAuthServer.ExpectResource = false;
11701170

11711171
// Use JwtBearer as the challenge scheme so the 401 response does NOT include resource_metadata.
11721172
Builder.Services.Configure<AuthenticationOptions>(options => options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme);

tests/ModelContextProtocol.TestOAuthServer/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ public Program(ILoggerProvider? loggerProvider = null, IConnectionListenerFactor
6868
public bool ClientIdMetadataDocumentSupported { get; set; } = true;
6969

7070
/// <summary>
71-
/// Gets or sets a value indicating whether the authorization server requires a resource parameter.
71+
/// Gets or sets a value indicating whether the authorization server expects a resource parameter.
7272
/// When <c>true</c>, the resource parameter must be present and match a valid resource.
7373
/// When <c>false</c>, the resource parameter must be absent to simulate legacy servers that
7474
/// do not support RFC 8707 resource indicators.
7575
/// </summary>
7676
/// <remarks>
7777
/// The default value is <c>true</c>.
7878
/// </remarks>
79-
public bool RequireResource { get; set; } = true;
79+
public bool ExpectResource { get; set; } = true;
8080

8181
public HashSet<string> DisabledMetadataPaths { get; } = new(StringComparer.OrdinalIgnoreCase);
8282
public IReadOnlyCollection<string> MetadataRequests => _metadataRequests.ToArray();
@@ -301,8 +301,8 @@ IResult HandleMetadataRequest(HttpContext context, string? issuerPath = null)
301301
}
302302

303303
// Validate resource in accordance with RFC 8707.
304-
// When RequireResource is false, the resource parameter must be absent (legacy mode).
305-
if (RequireResource ? (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)) : !string.IsNullOrEmpty(resource))
304+
// When ExpectResource is false, the resource parameter must be absent (legacy mode).
305+
if (ExpectResource ? (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)) : !string.IsNullOrEmpty(resource))
306306
{
307307
return Results.Redirect($"{redirect_uri}?error=invalid_target&error_description=The+specified+resource+is+not+valid&state={state}");
308308
}
@@ -349,9 +349,9 @@ IResult HandleMetadataRequest(HttpContext context, string? issuerPath = null)
349349
}
350350

351351
// Validate resource in accordance with RFC 8707.
352-
// When RequireResource is false, the resource parameter must be absent (legacy mode).
352+
// When ExpectResource is false, the resource parameter must be absent (legacy mode).
353353
var resource = form["resource"].ToString();
354-
if (RequireResource ? (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)) : !string.IsNullOrEmpty(resource))
354+
if (ExpectResource ? (string.IsNullOrEmpty(resource) || !ValidResources.Contains(resource)) : !string.IsNullOrEmpty(resource))
355355
{
356356
return Results.BadRequest(new OAuthErrorResponse
357357
{

0 commit comments

Comments
 (0)