From 6ece7f5efc5fe0c126a70584326c7b082db6c2d5 Mon Sep 17 00:00:00 2001 From: William Kim Date: Wed, 24 Jul 2013 16:14:27 -0400 Subject: [PATCH] Static server and client configuration tests done. --- .../TestStaticClientConfigurationService.java | 88 +++++++++++++++++++ .../TestStaticServerConfigurationService.java | 81 +++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticClientConfigurationService.java create mode 100644 openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticServerConfigurationService.java diff --git a/openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticClientConfigurationService.java b/openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticClientConfigurationService.java new file mode 100644 index 000000000..27a9a0768 --- /dev/null +++ b/openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticClientConfigurationService.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright 2013 The MITRE Corporation + * and the MIT Kerberos and Internet Trust Consortium + * + * Licensed 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.mitre.openid.connect.client.service.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mitre.oauth2.model.RegisteredClient; +import org.mitre.openid.connect.config.ServerConfiguration; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +/** + * @author wkim + * + */ +@RunWith(MockitoJUnitRunner.class) +public class TestStaticClientConfigurationService { + + private StaticClientConfigurationService service; + + private String issuer = "https://www.example.com/"; + + @Mock + private RegisteredClient mockClient; + + @Mock + private ServerConfiguration mockServerConfig; + + @Before + public void prepare() { + + service = new StaticClientConfigurationService(); + + Map clients = new HashMap(); + clients.put(issuer, mockClient); + + service.setClients(clients); + + Mockito.when(mockServerConfig.getIssuer()).thenReturn(issuer); + } + + @Test + public void getClientConfiguration_success() { + + RegisteredClient result = service.getClientConfiguration(mockServerConfig); + + assertThat(mockClient, is(notNullValue())); + assertEquals(mockClient, result); + } + + /** + * Checks the behavior when the issuer is not known. + */ + @Test + public void getClientConfiguration_noIssuer() { + Mockito.when(mockServerConfig.getIssuer()).thenReturn("www.badexample.net"); + + RegisteredClient actualClient = service.getClientConfiguration(mockServerConfig); + + assertThat(actualClient, is(nullValue())); + } + +} diff --git a/openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticServerConfigurationService.java b/openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticServerConfigurationService.java new file mode 100644 index 000000000..54e121a17 --- /dev/null +++ b/openid-connect-client/src/test/java/org/mitre/openid/connect/client/service/impl/TestStaticServerConfigurationService.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright 2013 The MITRE Corporation + * and the MIT Kerberos and Internet Trust Consortium + * + * Licensed 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.mitre.openid.connect.client.service.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mitre.openid.connect.config.ServerConfiguration; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +/** + * @author wkim + * + */ +@RunWith(MockitoJUnitRunner.class) +public class TestStaticServerConfigurationService { + + + private StaticServerConfigurationService service; + + private String issuer = "https://www.example.com/"; + + @Mock + private ServerConfiguration mockServerConfig; + + @Before + public void prepare() { + + service = new StaticServerConfigurationService(); + + Map servers = new HashMap(); + servers.put(issuer, mockServerConfig); + + service.setServers(servers); + } + + @Test + public void getServerConfiguration_success() { + + ServerConfiguration result = service.getServerConfiguration(issuer); + + assertThat(mockServerConfig, is(notNullValue())); + assertEquals(mockServerConfig, result); + } + + /** + * Checks the behavior when the issuer is not known. + */ + @Test + public void getClientConfiguration_noIssuer() { + + ServerConfiguration result = service.getServerConfiguration("www.badexample.net"); + + assertThat(result, is(nullValue())); + } + +}