[java-idp-plugin-duo] 04/15: Add Duo authn controller tests

Phil Smart philip.smart at jisc.ac.uk
Tue Jul 14 14:29:00 UTC 2020


This is an automated email from the git hooks/post-receive script.

philsmart pushed a commit to branch master
in repository java-idp-plugin-duo.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-duo.git;a=commit;h=51c997b630545f5792e2050ce8ff609f14560e0f

commit 51c997b630545f5792e2050ce8ff609f14560e0f
Author: philipsmart <philipsmart at localhost>
AuthorDate: Fri May 29 09:35:04 2020 +0100

    Add Duo authn controller tests
---
 idp-duo-impl/.gitignore                            |  1 +
 .../authn/duo/impl/DuoOIDCAuthnController.java     |  4 +-
 .../authn/duo/impl/DuoOIDCAuthnControllerTest.java | 85 +++++++++++++++-------
 .../util/mock/ShibbolethPropertyConfigurer.java    | 21 ++++++
 4 files changed, 83 insertions(+), 28 deletions(-)

diff --git a/idp-duo-impl/.gitignore b/idp-duo-impl/.gitignore
index 1052633..c7d7bf5 100644
--- a/idp-duo-impl/.gitignore
+++ b/idp-duo-impl/.gitignore
@@ -1,3 +1,4 @@
 /target
 /test-output
 /.DS_Store
+/.factorypath
diff --git a/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnController.java b/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnController.java
index 946dec7..ea9ff1b 100644
--- a/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnController.java
+++ b/idp-duo-impl/src/main/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnController.java
@@ -53,7 +53,7 @@ import net.shibboleth.utilities.java.support.logic.FunctionSupport;
  * 
  */
 @Controller
- at RequestMapping("%{idp.authn.duo.OIDC.externalAuthnPath:/Authn/Duo")
+ at RequestMapping("%{idp.authn.duo.OIDC.externalAuthnPath:/Authn/Duo}")
 public class DuoOIDCAuthnController extends AbstractInitializableComponent{
     
     /** Class logger. */
@@ -99,7 +99,7 @@ public class DuoOIDCAuthnController extends AbstractInitializableComponent{
         final ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(key, httpRequest);
         
         
-        
+        return new RedirectView("DUO");
     }
     
     @GetMapping("/2FA/end")
diff --git a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnControllerTest.java b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnControllerTest.java
index 3e4e079..e380ea8 100644
--- a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnControllerTest.java
+++ b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/duo/impl/DuoOIDCAuthnControllerTest.java
@@ -17,49 +17,82 @@
 package net.shibboleth.idp.plugin.authn.duo.impl;
 
 import static org.junit.jupiter.api.Assertions.*;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import java.util.Properties;
+
+import javax.annotation.Nonnull;
 
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+import org.springframework.mock.web.MockServletContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.testng.annotations.BeforeClass;
+
+import junit.framework.Assert;
+import net.shibboleth.idp.plugin.authn.util.mock.ShibbolethPropertyConfigurer;
 
 /**
  *
  */
+ at ExtendWith(SpringExtension.class)
+ at ContextConfiguration(classes = {DuoOIDCAuthnController.class,ShibbolethPropertyConfigurer.class})
+ at WebAppConfiguration
+ at TestPropertySource(properties = {
+        "idp.authn.duo.OIDC.externalAuthnPath=/Authn/Duo",
+    })
 public class DuoOIDCAuthnControllerTest {
+    
+    /** Class logger. */
+    @Nonnull private final Logger log = LoggerFactory.getLogger(DuoOIDCAuthnControllerTest.class);
+    
+    /** The mock MVC entry point for testing. */ 
+    @Nonnull private MockMvc mockMvc;
+    
+    /** The web application context loaded by the test framework.*/
+    @Autowired private WebApplicationContext webApplicationContext;
 
-    /**
-     * @throws java.lang.Exception
-     */
-    @BeforeAll
-    static void setUpBeforeClass() throws Exception {
-    }
 
-    /**
-     * @throws java.lang.Exception
-     */
-    @AfterAll
-    static void tearDownAfterClass() throws Exception {
-    }
-
-    /**
-     * @throws java.lang.Exception
-     */
     @BeforeEach
-    void setUp() throws Exception {
-    }
-
-    /**
-     * @throws java.lang.Exception
-     */
-    @AfterEach
-    void tearDown() throws Exception {
+    public void setUp() throws Exception {           
+        DuoOIDCAuthnController controller = webApplicationContext.getBean(DuoOIDCAuthnController.class);
+        //check controller is instantiated.
+        Assert.assertNotNull(controller);
+        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();       
     }
+    
+    @Test
+    public void webAppContextTest() throws Exception {
+        assertTrue(webApplicationContext.getServletContext() instanceof MockServletContext);
+    }   
 
     @Test
-    void test() {
-        fail("Not yet implemented");
+    public void test() throws Exception {
+        mockMvc.perform(get("/Authn/Duo/2FA/start").param("conversation", "e1s1")).andExpect(status().is3xxRedirection());
+        
     }
 
 }
diff --git a/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/util/mock/ShibbolethPropertyConfigurer.java b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/util/mock/ShibbolethPropertyConfigurer.java
new file mode 100644
index 0000000..85cc7a8
--- /dev/null
+++ b/idp-duo-impl/src/test/java/net/shibboleth/idp/plugin/authn/util/mock/ShibbolethPropertyConfigurer.java
@@ -0,0 +1,21 @@
+package net.shibboleth.idp.plugin.authn.util.mock;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+
+
+/**
+ * Configure the property sources placeholder to use the correct placeholder prefix of {@literal %}
+ */
+ at Configuration
+public class ShibbolethPropertyConfigurer {
+    
+    @Bean
+    public static PropertySourcesPlaceholderConfigurer properties() throws Exception {
+        final PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
+        pspc.setPlaceholderPrefix("%{");
+        return pspc;
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list