Skip to content

Commit 52d931c

Browse files
committed
Replace ClientRegistrationMixinTests with StdConvertersTest
Signed-off-by: Risto Virtanen <[email protected]>
1 parent 16db74c commit 52d931c

File tree

3 files changed

+57
-134
lines changed

3 files changed

+57
-134
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/jackson2/StdConverters.java

+1-22
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,7 @@ static final class ClientAuthenticationMethodConverter extends StdConverter<Json
5050
@Override
5151
public ClientAuthenticationMethod convert(JsonNode jsonNode) {
5252
String value = JsonNodeUtils.findStringValue(jsonNode, "value");
53-
if (ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue().equalsIgnoreCase(value)) {
54-
return ClientAuthenticationMethod.CLIENT_SECRET_BASIC;
55-
}
56-
if (ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue().equalsIgnoreCase(value)) {
57-
return ClientAuthenticationMethod.CLIENT_SECRET_POST;
58-
}
59-
if (ClientAuthenticationMethod.CLIENT_SECRET_JWT.getValue().equalsIgnoreCase(value)) {
60-
return ClientAuthenticationMethod.CLIENT_SECRET_JWT;
61-
}
62-
if (ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue().equalsIgnoreCase(value)) {
63-
return ClientAuthenticationMethod.PRIVATE_KEY_JWT;
64-
}
65-
if (ClientAuthenticationMethod.NONE.getValue().equalsIgnoreCase(value)) {
66-
return ClientAuthenticationMethod.NONE;
67-
}
68-
if (ClientAuthenticationMethod.TLS_CLIENT_AUTH.getValue().equalsIgnoreCase(value)) {
69-
return ClientAuthenticationMethod.TLS_CLIENT_AUTH;
70-
}
71-
if (ClientAuthenticationMethod.SELF_SIGNED_TLS_CLIENT_AUTH.getValue().equalsIgnoreCase(value)) {
72-
return ClientAuthenticationMethod.SELF_SIGNED_TLS_CLIENT_AUTH;
73-
}
74-
return null;
53+
return ClientAuthenticationMethod.valueOf(value);
7554
}
7655

7756
}

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/jackson2/ClientRegistrationMixinTests.java

-112
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.oauth2.client.jackson2;
18+
19+
import com.fasterxml.jackson.databind.JsonNode;
20+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21+
import com.fasterxml.jackson.databind.node.ObjectNode;
22+
import com.fasterxml.jackson.databind.util.StdConverter;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.Arguments;
25+
import org.junit.jupiter.params.provider.MethodSource;
26+
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
27+
28+
import java.util.stream.Stream;
29+
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
31+
32+
public class StdConvertersTest {
33+
34+
private final StdConverter<JsonNode, ClientAuthenticationMethod> clientAuthenticationMethodConverter =
35+
new StdConverters.ClientAuthenticationMethodConverter();
36+
37+
@ParameterizedTest
38+
@MethodSource("testClientAuthenticationMethodConverting")
39+
void testClientAuthenticationMethodConverting(String clientAuthenticationMethod) {
40+
ObjectNode jsonNode = JsonNodeFactory.instance.objectNode();
41+
jsonNode.put("value", clientAuthenticationMethod);
42+
ClientAuthenticationMethod actual = this.clientAuthenticationMethodConverter.convert(jsonNode);
43+
assertEquals(clientAuthenticationMethod, actual.getValue());
44+
45+
}
46+
47+
static Stream<Arguments> testClientAuthenticationMethodConverting() {
48+
return Stream.of(
49+
Arguments.of(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
50+
Arguments.of(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
51+
Arguments.of(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()),
52+
Arguments.of(ClientAuthenticationMethod.NONE.getValue()),
53+
Arguments.of("custom_method")
54+
);
55+
}
56+
}

0 commit comments

Comments
 (0)