Skip to content

Commit 7373f2d

Browse files
authored
test(mcp): assert public clients get no client secret (open-metadata#28568) (open-metadata#28758)
1 parent 94d4e7f commit 7373f2d

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

openmetadata-mcp/src/test/java/org/openmetadata/mcp/server/auth/handlers/RegistrationHandlerTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void testValidRegistration_defaultsAuthMethod() {
9191
OAuthClientInformation result = handler.handle(metadata).join();
9292

9393
assertThat(result.getTokenEndpointAuthMethod()).isEqualTo("client_secret_post");
94+
assertThat(result.getClientSecret()).isNotNull().isNotEmpty();
9495
}
9596

9697
@Test
@@ -256,6 +257,46 @@ void testNoneAuthMethod_accepted() {
256257
verify(clientRepository).register(any());
257258
}
258259

260+
/**
261+
* Regression for PR #28552: a public client (token_endpoint_auth_method=none) MUST NOT be issued a
262+
* client secret. Before the fix the secret was generated unconditionally, so the token endpoint
263+
* then demanded a secret the public PKCE client (Cursor, ChatGPT) never had, failing with
264+
* "Client secret required" (401). Public clients are secured by PKCE, not a secret.
265+
*/
266+
@Test
267+
void testPublicClient_none_issuesNoSecret() {
268+
OAuthClientMetadata metadata = validMetadata();
269+
metadata.setTokenEndpointAuthMethod("none");
270+
271+
OAuthClientInformation result = handler.handle(metadata).join();
272+
273+
assertThat(result.getClientSecret()).isNull();
274+
assertThat(result.getClientSecretExpiresAt()).isNull();
275+
verify(clientRepository).register(any());
276+
}
277+
278+
@Test
279+
void testConfidentialClient_clientSecretPost_issuesSecret() {
280+
OAuthClientMetadata metadata = validMetadata();
281+
metadata.setTokenEndpointAuthMethod("client_secret_post");
282+
283+
OAuthClientInformation result = handler.handle(metadata).join();
284+
285+
assertThat(result.getClientSecret()).isNotNull().isNotEmpty();
286+
assertThat(result.getClientSecretExpiresAt()).isEqualTo(0L);
287+
}
288+
289+
@Test
290+
void testConfidentialClient_clientSecretBasic_issuesSecret() {
291+
OAuthClientMetadata metadata = validMetadata();
292+
metadata.setTokenEndpointAuthMethod("client_secret_basic");
293+
294+
OAuthClientInformation result = handler.handle(metadata).join();
295+
296+
assertThat(result.getClientSecret()).isNotNull().isNotEmpty();
297+
assertThat(result.getClientSecretExpiresAt()).isEqualTo(0L);
298+
}
299+
259300
@Test
260301
void testUnsupportedAuthMethod_throwsRegistrationException() {
261302
OAuthClientMetadata metadata = validMetadata();

0 commit comments

Comments
 (0)