Skip to content

Commit e23a243

Browse files
committed
Initial version
1 parent 6bba2ed commit e23a243

6 files changed

Lines changed: 406 additions & 0 deletions
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (C) 2018 Google Inc.
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+
* http://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.oidc.msg.oidc;
18+
19+
import java.util.Arrays;
20+
21+
import org.junit.Assert;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
import org.oidc.msg.BaseMessageTest;
25+
26+
/**
27+
* Unit tests for {@link ProviderConfigurationResponse}.
28+
*/
29+
public class ProviderConfigurationResponseTest
30+
extends BaseMessageTest<ProviderConfigurationResponse> {
31+
32+
@Before
33+
public void setup() {
34+
message = new ProviderConfigurationResponse();
35+
addRequiredClaims();
36+
}
37+
38+
protected void addRequiredClaims() {
39+
message.addClaim("issuer", "https://example.org");
40+
message.addClaim("authorization_endpoint", "https://example.org/authorize");
41+
message.addClaim("jwks_uri", "https://example.org/keyset.jwk");
42+
message.addClaim("response_types_supported", Arrays.asList("id_token"));
43+
message.addClaim("subject_types_supported", Arrays.asList("public"));
44+
message.addClaim("id_token_signing_alg_values_supported", Arrays.asList("RS256"));
45+
}
46+
47+
@Test
48+
public void testInvalidScopesSupported() {
49+
message.addClaim("scopes_supported", "info");
50+
Assert.assertFalse(message.verify());
51+
Assert.assertEquals(1, message.getError().getDetails().size());
52+
Assert.assertEquals("scopes_supported",
53+
message.getError().getDetails().get(0).getParameterName());
54+
}
55+
56+
@Test
57+
public void testInvalidIssuerNonUri() {
58+
message.addClaim("issuer", "not_and_uri");
59+
Assert.assertFalse(message.verify());
60+
Assert.assertEquals(1, message.getError().getDetails().size());
61+
Assert.assertEquals("issuer", message.getError().getDetails().get(0).getParameterName());
62+
}
63+
64+
@Test
65+
public void testInvalidIssuerInvalidUriScheme() {
66+
message.addClaim("issuer", "http://example.org");
67+
Assert.assertFalse(message.verify());
68+
Assert.assertEquals(1, message.getError().getDetails().size());
69+
Assert.assertEquals("issuer", message.getError().getDetails().get(0).getParameterName());
70+
}
71+
72+
@Test
73+
public void testInvalidIssuerInvalidUriWithParameter() {
74+
message.addClaim("issuer", "https://example.org?query=test");
75+
Assert.assertFalse(message.verify());
76+
Assert.assertEquals(1, message.getError().getDetails().size());
77+
Assert.assertEquals("issuer", message.getError().getDetails().get(0).getParameterName());
78+
}
79+
80+
@Test
81+
public void testInvalidIssuerInvalidUriWithFragment() {
82+
message.addClaim("issuer", "https://example.org#mockFragment");
83+
Assert.assertFalse(message.verify());
84+
Assert.assertEquals(1, message.getError().getDetails().size());
85+
Assert.assertEquals("issuer", message.getError().getDetails().get(0).getParameterName());
86+
}
87+
88+
@Test
89+
public void testMissingTokenEndpoint() {
90+
message.addClaim("response_types_supported", "code");
91+
Assert.assertFalse(message.verify());
92+
Assert.assertEquals(1, message.getError().getDetails().size());
93+
Assert.assertEquals("token_endpoint",
94+
message.getError().getDetails().get(0).getParameterName());
95+
}
96+
97+
@Test
98+
public void testValidTokenEndpoint() {
99+
message.addClaim("response_types_supported", "code");
100+
message.addClaim("token_endpoint", "https://example.org/token");
101+
Assert.assertTrue(message.verify());
102+
}
103+
104+
@Test
105+
public void testValidMinimal() {
106+
Assert.assertTrue(message.verify());
107+
}
108+
109+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2018 Google Inc.
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+
* http://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.oidc.msg.oidc;
18+
19+
import org.junit.Before;
20+
21+
/**
22+
* Unit tests for {@link RefreshAccessTokenRequest}.
23+
*/
24+
public class RefreshAccessTokenRequestTest
25+
extends org.oidc.msg.oauth2.RefreshAccessTokenRequestTest {
26+
27+
@Before
28+
public void setup() {
29+
message = new RefreshAccessTokenRequest();
30+
}
31+
32+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (C) 2018 Google Inc.
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+
* http://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.oidc.msg.oidc;
18+
19+
import java.util.Arrays;
20+
import java.util.List;
21+
22+
import org.junit.Assert;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.oidc.msg.BaseMessageTest;
26+
import org.oidc.msg.InvalidClaimException;
27+
28+
/**
29+
* Unit tests for {@link RegistrationRequest}.
30+
*/
31+
public class RegistrationRequestTest extends BaseMessageTest<RegistrationRequest> {
32+
33+
private List<String> redirectUris;
34+
35+
@Before
36+
public void setup() {
37+
message = new RegistrationRequest();
38+
redirectUris = Arrays.asList("https://example.org/cb");
39+
message.addClaim("redirect_uris", redirectUris);
40+
}
41+
42+
@Test
43+
public void testSuccessMandatoryParameters() throws InvalidClaimException {
44+
Assert.assertTrue(message.verify());
45+
Assert.assertEquals(redirectUris, message.getClaims().get("redirect_uris"));
46+
}
47+
48+
@Test
49+
public void testInvalidInitiateLoginUri() throws InvalidClaimException {
50+
message.addClaim("initiate_login_uri", "http://example.org/initiate");
51+
Assert.assertFalse(message.verify());
52+
Assert.assertEquals(1, message.getError().getDetails().size());
53+
Assert.assertEquals("initiate_login_uri",
54+
message.getError().getDetails().get(0).getParameterName());
55+
56+
}
57+
58+
@Test
59+
public void testInvalidTokenEndpointAuthSigningAlg() throws InvalidClaimException {
60+
message.addClaim("token_endpoint_auth_signing_alg", "none");
61+
Assert.assertFalse(message.verify());
62+
Assert.assertEquals(1, message.getError().getDetails().size());
63+
Assert.assertEquals("token_endpoint_auth_signing_alg",
64+
message.getError().getDetails().get(0).getParameterName());
65+
}
66+
67+
@Test
68+
public void testMissingRequestObjectEncryptionAlg() {
69+
testMissingEncryptionAlg("request_object_encryption");
70+
}
71+
72+
@Test
73+
public void testMissingIdTokenEncryptionAlg() {
74+
testMissingEncryptionAlg("id_token_encrypted_response");
75+
}
76+
77+
@Test
78+
public void testMissingUserinfoEncryptionAlg() {
79+
testMissingEncryptionAlg("userinfo_encrypted_response");
80+
}
81+
82+
@Test
83+
public void testDefaultRequestObjectEncryptionEnc() {
84+
testDefaultEncryptionEnc("request_object_encryption");
85+
}
86+
87+
@Test
88+
public void testDefaultIdTokenEncryptionEnc() {
89+
testDefaultEncryptionEnc("id_token_encrypted_response");
90+
}
91+
92+
@Test
93+
public void testDefaultUserinfoEncryptionEnc() {
94+
testDefaultEncryptionEnc("userinfo_encrypted_response");
95+
}
96+
97+
protected void testMissingEncryptionAlg(String prefix) {
98+
message.addClaim(prefix + "_enc", "mockEnc");
99+
Assert.assertFalse(message.verify());
100+
Assert.assertEquals(1, message.getError().getDetails().size());
101+
Assert.assertEquals(prefix + "_alg", message.getError().getDetails().get(0).getParameterName());
102+
}
103+
104+
protected void testDefaultEncryptionEnc(String prefix) {
105+
message.addClaim(prefix + "_alg", "mockAlg");
106+
Assert.assertTrue(message.verify());
107+
Assert.assertEquals(RegistrationRequest.DEFAULT_ENC_VALUE,
108+
message.getClaims().get(prefix + "_enc"));
109+
}
110+
111+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2018 Google Inc.
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+
* http://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.oidc.msg.oidc;
18+
19+
import java.util.Arrays;
20+
import java.util.List;
21+
22+
import org.junit.Assert;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.oidc.msg.BaseMessageTest;
26+
import org.oidc.msg.InvalidClaimException;
27+
28+
/**
29+
* Unit tests for {@link RegistrationResponse}.
30+
*/
31+
public class RegistrationResponseTest extends BaseMessageTest<RegistrationResponse> {
32+
33+
private List<String> redirectUris;
34+
35+
private String clientId;
36+
37+
@Before
38+
public void setup() {
39+
message = new RegistrationResponse();
40+
redirectUris = Arrays.asList("https://example.org/cb");
41+
clientId = "mockClientId";
42+
message.addClaim("redirect_uris", redirectUris);
43+
message.addClaim("client_id", clientId);
44+
}
45+
46+
@Test
47+
public void testSuccessMandatoryParameters() throws InvalidClaimException {
48+
Assert.assertTrue(message.verify());
49+
Assert.assertEquals(redirectUris, message.getClaims().get("redirect_uris"));
50+
Assert.assertEquals(clientId, message.getClaims().get("client_id"));
51+
}
52+
53+
@Test
54+
public void testMissingRegistrationClientUri() throws InvalidClaimException {
55+
message.addClaim("registration_access_token", "mockToken");
56+
Assert.assertFalse(message.verify());
57+
Assert.assertEquals(1, message.getError().getDetails().size());
58+
Assert.assertEquals("registration_client_uri",
59+
message.getError().getDetails().get(0).getParameterName());
60+
61+
}
62+
63+
@Test
64+
public void testMissingRegistrationAccessToken() throws InvalidClaimException {
65+
message.addClaim("registration_client_uri", "mockUri");
66+
Assert.assertFalse(message.verify());
67+
Assert.assertEquals(1, message.getError().getDetails().size());
68+
Assert.assertEquals("registration_access_token",
69+
message.getError().getDetails().get(0).getParameterName());
70+
}
71+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2018 Google Inc.
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+
* http://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.oidc.msg.oidc;
18+
19+
import org.junit.Assert;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
import org.oidc.msg.BaseMessageTest;
23+
24+
/**
25+
* Unit tests for {@link RequestObject}.
26+
*/
27+
public class RequestObjectTest extends BaseMessageTest<RequestObject> {
28+
29+
@Before
30+
public void setup() {
31+
message = new RequestObject();
32+
message.addClaim("response_type", "code");
33+
message.addClaim("client_id", "value");
34+
message.addClaim("redirect_uri", "value");
35+
message.addClaim("scope", "openid");
36+
}
37+
38+
@Test
39+
public void testRequestIncluded() {
40+
message.addClaim("request", "mockRequest");
41+
Assert.assertFalse(message.verify());
42+
Assert.assertEquals(1, message.getError().getDetails().size());
43+
Assert.assertEquals("request", message.getError().getDetails().get(0).getParameterName());
44+
}
45+
46+
@Test
47+
public void testRequestUriIncluded() {
48+
message.addClaim("request_uri", "mockRequestUri");
49+
Assert.assertFalse(message.verify());
50+
Assert.assertEquals(1, message.getError().getDetails().size());
51+
Assert.assertEquals("request_uri", message.getError().getDetails().get(0).getParameterName());
52+
}
53+
}

0 commit comments

Comments
 (0)