Skip to content

Commit 389835b

Browse files
committed
Test updateCtx with response having illegal parameter contents
1 parent e24804d commit 389835b

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/test/java/org/oidc/service/oauth2/ProviderInfoDiscoveryTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ public void init() {
5050

5151
@Test(expected = MissingRequiredAttributeException.class)
5252
public void testHttpParamsMissingIssuer() throws Exception {
53-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
5453
service.getRequestParameters(new HashMap<String, Object>());
5554
}
5655

5756
@Test
5857
public void testHttpParamsSuccessfulIssuer() throws Exception {
5958
serviceContext.setIssuer(issuer);
60-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
6159
HttpArguments httpArguments = service.getRequestParameters(new HashMap<String, Object>());
6260
Assert.assertEquals("https://www.example.com/.well-known/openid-configuration",
6361
httpArguments.getUrl());
@@ -67,7 +65,6 @@ public void testHttpParamsSuccessfulIssuer() throws Exception {
6765
@Test
6866
public void testHttpParamsSuccessFulIssuerTrailingSlash() throws Exception {
6967
serviceContext.setIssuer(issuer + "/");
70-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
7168
HttpArguments httpArguments = service.getRequestParameters(new HashMap<String, Object>());
7269
Assert.assertEquals("https://www.example.com/.well-known/openid-configuration",
7370
httpArguments.getUrl());
@@ -76,13 +73,18 @@ public void testHttpParamsSuccessFulIssuerTrailingSlash() throws Exception {
7673

7774
@Test(expected = MissingRequiredAttributeException.class)
7875
public void testUpdateCtxMissingIssuer() throws Exception {
79-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
8076
service.updateServiceContext(buildMinimalResponse(issuer));
8177
}
8278

79+
@Test(expected = InvalidClaimException.class)
80+
public void testUpdateCtxInvalidResponseContents() throws Exception {
81+
ASConfigurationResponse response = buildMinimalResponseWithEndpoints(issuer);
82+
response.addClaim("revocation_endpoint", Arrays.asList("should", "not", "be", "list"));
83+
service.updateServiceContext(response);
84+
}
85+
8386
@Test
8487
public void testUpdateCtxSuccess() throws Exception {
85-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
8688
serviceContext.setIssuer(issuer);
8789
Assert.assertNull(service.getServiceContext().getProviderConfigurationResponse());
8890
service.updateServiceContext(buildMinimalResponse(issuer));
@@ -96,7 +98,6 @@ public void testUpdateCtxSuccess() throws Exception {
9698

9799
@Test
98100
public void testUpdateCtxSuccessMismatchAllowed() throws Exception {
99-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
100101
serviceContext.setIssuer("https://www.example.org");
101102
Map<String, Boolean> allow = new HashMap<String, Boolean>();
102103
allow.put(Constants.ALLOW_PARAM_ISSUER_MISMATCH, Boolean.TRUE);
@@ -113,15 +114,13 @@ public void testUpdateCtxSuccessMismatchAllowed() throws Exception {
113114

114115
@Test(expected = InvalidClaimException.class)
115116
public void testUpdateCtxFailedMismatch() throws Exception {
116-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
117117
serviceContext.setIssuer("https://www.example.org");
118118
Assert.assertNull(service.getServiceContext().getProviderConfigurationResponse());
119119
service.updateServiceContext(buildMinimalResponse(issuer + "/"));
120120
}
121121

122122
@Test
123123
public void testUpdateCtxSuccessWithEndpoints() throws Exception {
124-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
125124
serviceContext.setIssuer(issuer);
126125
Assert.assertNull(service.getServiceContext().getProviderConfigurationResponse());
127126
service.updateServiceContext(buildMinimalResponseWithEndpoints(issuer));

src/test/java/org/oidc/service/oidc/ProviderInfoDiscoveryTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public void testPreferenceNotSatisfied() throws Exception {
112112

113113
@Test
114114
public void testUpdateCtxSuccessWithEndpoints() throws Exception {
115-
ProviderInfoDiscovery service = new ProviderInfoDiscovery(serviceContext, null, null);
116115
serviceContext.setIssuer(issuer);
117116
Assert.assertNull(service.getServiceContext().getProviderConfigurationResponse());
118117
service.updateServiceContext(service.parseResponse(exampleValidResponse()));
@@ -135,6 +134,14 @@ public void testUpdateCtxSuccessWithEndpoints() throws Exception {
135134
Assert.assertEquals("https://example.com/end_session",
136135
serviceContext.getEndpoints().get(EndpointName.END_SESSION));
137136
}
137+
138+
@Test(expected = InvalidClaimException.class)
139+
public void testUpdateCtxInvalidResponseContents() throws Exception {
140+
ProviderConfigurationResponse pcr = new ProviderConfigurationResponse();
141+
pcr.fromJson(exampleValidResponse());
142+
pcr.addClaim("request_parameter_supported", "should be boolean");
143+
service.updateServiceContext(pcr);
144+
}
138145

139146
@Test
140147
public void testCustomPreferences() throws Exception {

src/test/java/org/oidc/service/oidc/WebfingerTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,26 @@ public void init() {
5959
@Rule
6060
public ExpectedException thrown = ExpectedException.none();
6161

62-
@Test
62+
@Test(expected = UnsupportedOperationException.class)
6363
public void testUpdateServiceContextWrongMethod() throws Exception {
64-
thrown.expect(UnsupportedOperationException.class);
65-
thrown.expectMessage(
66-
"stateKey is not supported to update service context for the WebFinger service");
67-
service.updateServiceContext(new JsonResponseDescriptor(), "mockKey");
64+
service.updateServiceContext(buildMinimalJrd(), "mockKey");
6865
}
6966

67+
@Test(expected = InvalidClaimException.class)
68+
public void testUpdateServiceContextInvalidMsgContents() throws Exception {
69+
JsonResponseDescriptor jrd = buildMinimalJrd();
70+
jrd.addClaim("properties", "this is not a map as it should");
71+
service.updateServiceContext(jrd);
72+
}
73+
74+
protected JsonResponseDescriptor buildMinimalJrd() {
75+
JsonResponseDescriptor jrd = new JsonResponseDescriptor();
76+
Link link = new Link();
77+
link.addClaim("rel", "mockRel");
78+
jrd.addClaim("links", Arrays.asList(link));
79+
return jrd;
80+
}
81+
7082
protected Map<String, Object> buildArgsWithResource(String resource) {
7183
Map<String, Object> map = new HashMap<>();
7284
map.put(Constants.WEBFINGER_RESOURCE, resource);

0 commit comments

Comments
 (0)