Skip to content

Commit 6c5cd07

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

File tree

3 files changed

+41
-134
lines changed

3 files changed

+41
-134
lines changed

Diff for: 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
}

Diff for: 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,40 @@
1+
package org.springframework.security.oauth2.client.jackson2;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
5+
import com.fasterxml.jackson.databind.node.ObjectNode;
6+
import com.fasterxml.jackson.databind.util.StdConverter;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
11+
12+
import java.util.stream.Stream;
13+
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
public class StdConvertersTest {
17+
18+
private final StdConverter<JsonNode, ClientAuthenticationMethod> clientAuthenticationMethodConverter =
19+
new StdConverters.ClientAuthenticationMethodConverter();
20+
21+
@ParameterizedTest
22+
@MethodSource("testClientAuthenticationMethodConverting")
23+
void testClientAuthenticationMethodConverting(String clientAuthenticationMethod) {
24+
ObjectNode jsonNode = JsonNodeFactory.instance.objectNode();
25+
jsonNode.put("value", clientAuthenticationMethod);
26+
ClientAuthenticationMethod actual = this.clientAuthenticationMethodConverter.convert(jsonNode);
27+
assertEquals(clientAuthenticationMethod, actual.getValue());
28+
29+
}
30+
31+
static Stream<Arguments> testClientAuthenticationMethodConverting() {
32+
return Stream.of(
33+
Arguments.of(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()),
34+
Arguments.of(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()),
35+
Arguments.of(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()),
36+
Arguments.of(ClientAuthenticationMethod.NONE.getValue()),
37+
Arguments.of("custom_method")
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)