lh0156 commented on code in PR #22298: URL: https://github.com/apache/kafka/pull/22298#discussion_r3288100451
########## clients/src/test/java/org/apache/kafka/common/security/oauthbearer/internals/OAuthBearerScopeClaimUtilsTest.java: ########## @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.common.security.oauthbearer.internals; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class OAuthBearerScopeClaimUtilsTest { + + @Test + public void testParseSpaceDelimitedScopeClaimSplitsScopeClaim() { + assertEquals(List.of("email", "profile", "phone"), + OAuthBearerScopeClaimUtils.parseSpaceDelimitedScopeClaim("email profile phone")); + } + + @Test + public void testParseSpaceDelimitedScopeClaimPreservesSingleScope() { + assertEquals(List.of("email"), + OAuthBearerScopeClaimUtils.parseSpaceDelimitedScopeClaim("email")); + } + + @Test + public void testParseSpaceDelimitedScopeClaimTrimsClaimBeforeSplitting() { + assertEquals(List.of("email", "profile", "phone"), + OAuthBearerScopeClaimUtils.parseSpaceDelimitedScopeClaim(" email profile phone ")); + } + + @Test + public void testParseSpaceDelimitedScopeClaimDoesNotEmitEmptyScopeItems() { + assertEquals(List.of("email", "profile", "phone"), + OAuthBearerScopeClaimUtils.parseSpaceDelimitedScopeClaim("email profile phone")); + } + + @Test + public void testParseSpaceDelimitedScopeClaimPreservesBlankClaimForCallerValidation() { + assertEquals(List.of(" "), OAuthBearerScopeClaimUtils.parseSpaceDelimitedScopeClaim(" ")); Review Comment: Thanks for catching this. I verified the RFC 6749 scope grammar and agree that a whitespace-only scope claim does not contain any scope-token, so the parser should not emit the original blank string as a scope item. I updated `parseSpaceDelimitedScopeClaim(" ")` to return an empty list and adjusted the unit test accordingly. I also kept the secured validator behavior explicit: blank string-valued scope claims are still rejected instead of being silently treated as a valid no-scope claim. I also corrected the related test names to reference RFC 6749. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
