diff --git a/.github/workflows/release-artifact.yml b/.github/workflows/release-artifact.yml index a260978..21e2c20 100644 --- a/.github/workflows/release-artifact.yml +++ b/.github/workflows/release-artifact.yml @@ -37,6 +37,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: target/DuoPlugin.jar - asset_name: DuoPlugin.jar + asset_path: target/DuoUniversalPlugin.jar + asset_name: DuoUniversalPlugin.jar asset_content_type: application/java-archive diff --git a/pom.xml b/pom.xml index 591dde4..ec0f194 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ src/main/resources/META-INF/MANIFEST.MF - DuoPlugin + DuoUniversalPlugin false diff --git a/src/main/assembly/duo-oam-assembly.xml b/src/main/assembly/duo-oam-assembly.xml index 80af165..a329b55 100644 --- a/src/main/assembly/duo-oam-assembly.xml +++ b/src/main/assembly/duo-oam-assembly.xml @@ -20,7 +20,7 @@ - ./src/main/resources/DuoPlugin.xml + ./src/main/resources/DuoUniversalPlugin.xml / diff --git a/src/main/java/com/duosecurity/plugin/DuoPlugin.java b/src/main/java/com/duosecurity/plugin/DuoUniversalPlugin.java similarity index 99% rename from src/main/java/com/duosecurity/plugin/DuoPlugin.java rename to src/main/java/com/duosecurity/plugin/DuoUniversalPlugin.java index 972d5de..36a4aba 100644 --- a/src/main/java/com/duosecurity/plugin/DuoPlugin.java +++ b/src/main/java/com/duosecurity/plugin/DuoUniversalPlugin.java @@ -36,7 +36,7 @@ import com.duosecurity.Client; import com.duosecurity.model.Token; -public class DuoPlugin extends AbstractAuthenticationPlugIn { +public class DuoUniversalPlugin extends AbstractAuthenticationPlugIn { private static final String JAR_VERSION = "1.0.0"; private static final String CLIENT_ID_PARAM = "Client ID"; @@ -358,7 +358,7 @@ public void setMonitoringStatus(final boolean status) { @Override public String getPluginName() { - return "DuoPlugin"; + return "DuoUniversalPlugin"; } diff --git a/src/main/resources/DuoPlugin.xml b/src/main/resources/DuoUniversalPlugin.xml similarity index 94% rename from src/main/resources/DuoPlugin.xml rename to src/main/resources/DuoUniversalPlugin.xml index 7004ed8..d377cdb 100644 --- a/src/main/resources/DuoPlugin.xml +++ b/src/main/resources/DuoUniversalPlugin.xml @@ -1,4 +1,4 @@ - + Duo Security support@duosecurity.com 12:00:00 2021-01-20 diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF index 73f0ba4..9348552 100644 --- a/src/main/resources/META-INF/MANIFEST.MF +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-Version: 10 -Bundle-Name: DuoPlugin -Bundle-Activator: com.duosecurity.plugin.DuoPlugin +Bundle-Name: DuoUniversalPlugin +Bundle-Activator: com.duosecurity.plugin.DuoUniversalPlugin Bundle-ManifestVersion: 2 Import-Package: org.osgi.framework;version="1.3.0",oracle.security.am.plugin,oracle.security.am.plugin.authn,oracle.security.am.plugin.impl,oracle.security.am.plugin.api,oracle.security.am.common.utilities.principal,oracle.security.idm,javax.security.auth,oracle.security.am.engines.common.identity.provider,oracle.security.am.common.policy.runtime,javax.crypto,javax.crypto.spec,javax.net,javax.net.ssl,org.w3c.dom -Bundle-SymbolicName: DuoPlugin +Bundle-SymbolicName: DuoUniversalPlugin diff --git a/src/test/java/com/duosecurity/plugin/DuoPluginPhase1Test.java b/src/test/java/com/duosecurity/plugin/DuoPluginPhase1Test.java deleted file mode 100644 index 475e860..0000000 --- a/src/test/java/com/duosecurity/plugin/DuoPluginPhase1Test.java +++ /dev/null @@ -1,77 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Duo Security support@duosecurity.com -// -// SPDX-License-Identifier: BSD-3-Clause - -package com.duosecurity.plugin; - -import com.duosecurity.Client; -import com.duosecurity.exception.DuoException; -import oracle.security.am.plugin.ExecutionStatus; -import oracle.security.am.plugin.authn.AuthenticationContext; -import oracle.security.am.plugin.impl.AuthnContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.doNothing; - -public class DuoPluginPhase1Test { - DuoPlugin duoPlugin; - - // Just use a stub AuthenticationContext instance - AuthenticationContext context = new AuthnContext(); - - @BeforeEach - public void setUp() { - duoPlugin = Mockito.mock(DuoPlugin.class); - duoPlugin.failmode = DuoPlugin.Failmode.OPEN; - duoPlugin.username = "username"; - duoPlugin.duoClient = Mockito.mock(Client.class); - - // Mock some methods dealing with AuthenticationContext - doNothing().when(duoPlugin).updatePluginResponse(isA(AuthenticationContext.class)); - doNothing().when(duoPlugin).storeStateInSession(isA(AuthenticationContext.class), any(String.class)); - doNothing().when(duoPlugin).issueRedirect(isA(AuthenticationContext.class), any(String.class)); - - Mockito.when(duoPlugin.duoClient.generateState()).thenReturn("GOOD_STATE"); - - // Call the real Phase 1 method - Mockito.when(duoPlugin.handlePhase1(isA(AuthenticationContext.class), isA(Client.class))).thenCallRealMethod(); - } - - @Test - public void testSuccess() throws DuoException { - Mockito.when(duoPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoPlugin.Failmode.class))).thenReturn(DuoPlugin.FailmodeResult.AUTH); - Mockito.when(duoPlugin.duoClient.createAuthUrl(anyString(), anyString())).thenReturn("url"); - - ExecutionStatus result = duoPlugin.handlePhase1(context, duoPlugin.duoClient); - assertEquals(ExecutionStatus.PAUSE, result); - } - - @Test - public void testFailOpen() { - Mockito.when(duoPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoPlugin.Failmode.class))).thenReturn(DuoPlugin.FailmodeResult.ALLOW); - - ExecutionStatus result = duoPlugin.handlePhase1(context, duoPlugin.duoClient); - assertEquals(ExecutionStatus.SUCCESS, result); - } - - @Test - public void testFailClosed() { - Mockito.when(duoPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoPlugin.Failmode.class))).thenReturn(DuoPlugin.FailmodeResult.BLOCK); - - ExecutionStatus result = duoPlugin.handlePhase1(context, duoPlugin.duoClient); - assertEquals(ExecutionStatus.FAILURE, result); - } - - @Test - public void testAuthUrlExceptionFailure() throws DuoException { - Mockito.when(duoPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoPlugin.Failmode.class))).thenReturn(DuoPlugin.FailmodeResult.AUTH); - Mockito.when(duoPlugin.duoClient.createAuthUrl(anyString(), anyString())).thenThrow(new DuoException("woops")); - - ExecutionStatus result = duoPlugin.handlePhase1(context, duoPlugin.duoClient); - assertEquals(ExecutionStatus.FAILURE, result); - } -} diff --git a/src/test/java/com/duosecurity/plugin/DuoPluginConfigTest.java b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginConfigTest.java similarity index 60% rename from src/test/java/com/duosecurity/plugin/DuoPluginConfigTest.java rename to src/test/java/com/duosecurity/plugin/DuoUniversalPluginConfigTest.java index a1dcd20..ff03a7d 100644 --- a/src/test/java/com/duosecurity/plugin/DuoPluginConfigTest.java +++ b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginConfigTest.java @@ -11,52 +11,52 @@ import static org.junit.jupiter.api.Assertions.*; -public class DuoPluginConfigTest { - DuoPlugin duoPlugin; +public class DuoUniversalPluginConfigTest { + DuoUniversalPlugin duoUniversalPlugin; @BeforeEach public void setUp() { - duoPlugin = new DuoPlugin(); - duoPlugin.username = "tester"; - duoPlugin.client_id = "DIXXXXXXXXXXXXXXXXXX"; - duoPlugin.client_secret = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; - duoPlugin.host = "fakehosturl"; + duoUniversalPlugin = new DuoUniversalPlugin(); + duoUniversalPlugin.username = "tester"; + duoUniversalPlugin.client_id = "DIXXXXXXXXXXXXXXXXXX"; + duoUniversalPlugin.client_secret = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; + duoUniversalPlugin.host = "fakehosturl"; } @Test public void testGetDescription() { - String ret_description = duoPlugin.getDescription(); + String ret_description = duoUniversalPlugin.getDescription(); String description = "Duo Security's Plugin to allow users to 2FA with Duo"; assertEquals(description, ret_description); } @Test public void testGetMonitoringData() { - Map data = duoPlugin.getMonitoringData(); + Map data = duoUniversalPlugin.getMonitoringData(); assertNull(data); } @Test public void testGetMonitoringStatus() { - boolean data = duoPlugin.getMonitoringStatus(); + boolean data = duoUniversalPlugin.getMonitoringStatus(); assertFalse(data); } @Test public void testGetPluginName() { - String data = duoPlugin.getPluginName(); - assertEquals(data, "DuoPlugin"); + String data = duoUniversalPlugin.getPluginName(); + assertEquals(data, "DuoUniversalPlugin"); } @Test public void testGetRevision() { - int data = duoPlugin.getRevision(); + int data = duoUniversalPlugin.getRevision(); assertEquals(data, 0); } @Test public void testGetUserAgent() { - String ua = duoPlugin.getUserAgent(); + String ua = duoUniversalPlugin.getUserAgent(); assertNotNull(ua); assertTrue(ua.toLowerCase().contains("duo_universal_oam/")); assertTrue(ua.toLowerCase().contains("java.version")); diff --git a/src/test/java/com/duosecurity/plugin/DuoPluginFailmodeTest.java b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginFailmodeTest.java similarity index 58% rename from src/test/java/com/duosecurity/plugin/DuoPluginFailmodeTest.java rename to src/test/java/com/duosecurity/plugin/DuoUniversalPluginFailmodeTest.java index 74b3253..5d7ef56 100644 --- a/src/test/java/com/duosecurity/plugin/DuoPluginFailmodeTest.java +++ b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginFailmodeTest.java @@ -13,14 +13,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class DuoPluginFailmodeTest { - DuoPlugin duoPlugin; +public class DuoUniversalPluginFailmodeTest { + DuoUniversalPlugin duoUniversalPlugin; Client duoClient; HealthCheckResponse hcResponse; @BeforeEach public void setUp() { - duoPlugin = new DuoPlugin(); + duoUniversalPlugin = new DuoUniversalPlugin(); duoClient = Mockito.mock(Client.class); hcResponse = Mockito.mock(HealthCheckResponse.class); } @@ -30,7 +30,7 @@ public void testDuoHealthy() throws DuoException { Mockito.when(hcResponse.wasSuccess()).thenReturn(Boolean.TRUE); Mockito.when(duoClient.healthCheck()).thenReturn(hcResponse); - boolean result = duoPlugin.isDuoHealthy(duoClient); + boolean result = duoUniversalPlugin.isDuoHealthy(duoClient); assertEquals(true, result); } @@ -40,7 +40,7 @@ public void testDuoUnhealthy() throws DuoException { Mockito.when(hcResponse.wasSuccess()).thenReturn(Boolean.FALSE); Mockito.when(duoClient.healthCheck()).thenReturn(hcResponse); - boolean result = duoPlugin.isDuoHealthy(duoClient); + boolean result = duoUniversalPlugin.isDuoHealthy(duoClient); assertEquals(false, result); } @@ -49,7 +49,7 @@ public void testDuoUnhealthy() throws DuoException { public void testDuoHealthCheckException() throws DuoException { Mockito.when(duoClient.healthCheck()).thenThrow(new DuoException("health check exception")); - boolean result = duoPlugin.isDuoHealthy(duoClient); + boolean result = duoUniversalPlugin.isDuoHealthy(duoClient); assertEquals(false, result); } @@ -60,9 +60,9 @@ public void testDuoHealthyFailOpen() throws DuoException { Mockito.when(hcResponse.wasSuccess()).thenReturn(Boolean.TRUE); Mockito.when(duoClient.healthCheck()).thenReturn(hcResponse); - DuoPlugin.FailmodeResult result = duoPlugin.performHealthCheckAndFailmode(duoClient, DuoPlugin.Failmode.OPEN); + DuoUniversalPlugin.FailmodeResult result = duoUniversalPlugin.performHealthCheckAndFailmode(duoClient, DuoUniversalPlugin.Failmode.OPEN); - assertEquals(DuoPlugin.FailmodeResult.AUTH, result); + assertEquals(DuoUniversalPlugin.FailmodeResult.AUTH, result); } @Test @@ -70,9 +70,9 @@ public void testDuoUnhealthyFailOpen() throws DuoException { Mockito.when(hcResponse.wasSuccess()).thenReturn(Boolean.FALSE); Mockito.when(duoClient.healthCheck()).thenReturn(hcResponse); - DuoPlugin.FailmodeResult result = duoPlugin.performHealthCheckAndFailmode(duoClient, DuoPlugin.Failmode.OPEN); + DuoUniversalPlugin.FailmodeResult result = duoUniversalPlugin.performHealthCheckAndFailmode(duoClient, DuoUniversalPlugin.Failmode.OPEN); - assertEquals(DuoPlugin.FailmodeResult.ALLOW, result); + assertEquals(DuoUniversalPlugin.FailmodeResult.ALLOW, result); } @Test @@ -80,62 +80,62 @@ public void testDuoUnhealthyFailClosed() throws DuoException { Mockito.when(hcResponse.wasSuccess()).thenReturn(Boolean.FALSE); Mockito.when(duoClient.healthCheck()).thenReturn(hcResponse); - DuoPlugin.FailmodeResult result = duoPlugin.performHealthCheckAndFailmode(duoClient, DuoPlugin.Failmode.CLOSED); + DuoUniversalPlugin.FailmodeResult result = duoUniversalPlugin.performHealthCheckAndFailmode(duoClient, DuoUniversalPlugin.Failmode.CLOSED); - assertEquals(DuoPlugin.FailmodeResult.BLOCK, result); + assertEquals(DuoUniversalPlugin.FailmodeResult.BLOCK, result); } @Test public void testNullFailmodeConfig() { Object configParam = null; - DuoPlugin.Failmode result = DuoPlugin.determineFailmode(configParam); + DuoUniversalPlugin.Failmode result = DuoUniversalPlugin.determineFailmode(configParam); - assertEquals(DuoPlugin.Failmode.CLOSED, result); + assertEquals(DuoUniversalPlugin.Failmode.CLOSED, result); } @Test public void testNonStringFailmodeConfig() { Integer configParam = 7; - DuoPlugin.Failmode result = DuoPlugin.determineFailmode(configParam); + DuoUniversalPlugin.Failmode result = DuoUniversalPlugin.determineFailmode(configParam); - assertEquals(DuoPlugin.Failmode.CLOSED, result); + assertEquals(DuoUniversalPlugin.Failmode.CLOSED, result); } @Test public void testNonsenseFailmodeConfig() { String configParam = "not a failmode"; - DuoPlugin.Failmode result = DuoPlugin.determineFailmode(configParam); + DuoUniversalPlugin.Failmode result = DuoUniversalPlugin.determineFailmode(configParam); - assertEquals(DuoPlugin.Failmode.CLOSED, result); + assertEquals(DuoUniversalPlugin.Failmode.CLOSED, result); } @Test public void testClosedFailmodeConfig() { String configParam = "closed"; - DuoPlugin.Failmode result = DuoPlugin.determineFailmode(configParam); + DuoUniversalPlugin.Failmode result = DuoUniversalPlugin.determineFailmode(configParam); - assertEquals(DuoPlugin.Failmode.CLOSED, result); + assertEquals(DuoUniversalPlugin.Failmode.CLOSED, result); } @Test public void testOpenFailmodeConfig() { String configParam = "open"; - DuoPlugin.Failmode result = DuoPlugin.determineFailmode(configParam); + DuoUniversalPlugin.Failmode result = DuoUniversalPlugin.determineFailmode(configParam); - assertEquals(DuoPlugin.Failmode.OPEN, result); + assertEquals(DuoUniversalPlugin.Failmode.OPEN, result); } @Test public void testOpenMixedCaseFailmodeConfig() { String configParam = "oPen"; - DuoPlugin.Failmode result = DuoPlugin.determineFailmode(configParam); + DuoUniversalPlugin.Failmode result = DuoUniversalPlugin.determineFailmode(configParam); - assertEquals(DuoPlugin.Failmode.OPEN, result); + assertEquals(DuoUniversalPlugin.Failmode.OPEN, result); } } diff --git a/src/test/java/com/duosecurity/plugin/DuoPluginLogSanitizationTest.java b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginLogSanitizationTest.java similarity index 74% rename from src/test/java/com/duosecurity/plugin/DuoPluginLogSanitizationTest.java rename to src/test/java/com/duosecurity/plugin/DuoUniversalPluginLogSanitizationTest.java index 1a5425d..60356ee 100644 --- a/src/test/java/com/duosecurity/plugin/DuoPluginLogSanitizationTest.java +++ b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginLogSanitizationTest.java @@ -7,13 +7,13 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -public class DuoPluginLogSanitizationTest { +public class DuoUniversalPluginLogSanitizationTest { @Test public void testSanitizeEmailInputUnchanged() { String testString = "a_good_user@example.com"; String expectedResult = testString; - String actualResult = DuoPlugin.sanitizeForLogging(testString); + String actualResult = DuoUniversalPlugin.sanitizeForLogging(testString); assertEquals(expectedResult, actualResult); } @@ -23,7 +23,7 @@ public void testSanitizeAlphanumOnlyUnchanged() { String testString = "agooduser001"; String expectedResult = testString; - String actualResult = DuoPlugin.sanitizeForLogging(testString); + String actualResult = DuoUniversalPlugin.sanitizeForLogging(testString); assertEquals(expectedResult, actualResult); } @@ -33,7 +33,7 @@ public void testSanitizeAlphanumMixedCaseUnchanged() { String testString = "JamesBond007"; String expectedResult = testString; - String actualResult = DuoPlugin.sanitizeForLogging(testString); + String actualResult = DuoUniversalPlugin.sanitizeForLogging(testString); assertEquals(expectedResult, actualResult); } @@ -43,7 +43,7 @@ public void testSanitizeNewlinesRemoved() { String testString = "One\nTwo\nThree"; String expectedResult = "OneTwoThree"; - String actualResult = DuoPlugin.sanitizeForLogging(testString); + String actualResult = DuoUniversalPlugin.sanitizeForLogging(testString); assertEquals(expectedResult, actualResult); } @@ -53,7 +53,7 @@ public void testSanitizeSpecialCharactersRemoved() { String testString = "One:Two\\Three:Four#Five*Six@Seven;"; String expectedResult = "OneTwoThreeFourFiveSix@Seven"; - String actualResult = DuoPlugin.sanitizeForLogging(testString); + String actualResult = DuoUniversalPlugin.sanitizeForLogging(testString); assertEquals(expectedResult, actualResult); } @@ -63,7 +63,7 @@ public void testSanitizeNull() { String testString = null; String expectedResult = ""; - String actualResult = DuoPlugin.sanitizeForLogging(testString); + String actualResult = DuoUniversalPlugin.sanitizeForLogging(testString); assertEquals(expectedResult, actualResult); } diff --git a/src/test/java/com/duosecurity/plugin/DuoUniversalPluginPhase1Test.java b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginPhase1Test.java new file mode 100644 index 0000000..ff0c64e --- /dev/null +++ b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginPhase1Test.java @@ -0,0 +1,77 @@ +// SPDX-FileCopyrightText: 2021 Duo Security support@duosecurity.com +// +// SPDX-License-Identifier: BSD-3-Clause + +package com.duosecurity.plugin; + +import com.duosecurity.Client; +import com.duosecurity.exception.DuoException; +import oracle.security.am.plugin.ExecutionStatus; +import oracle.security.am.plugin.authn.AuthenticationContext; +import oracle.security.am.plugin.impl.AuthnContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.doNothing; + +public class DuoUniversalPluginPhase1Test { + DuoUniversalPlugin duoUniversalPlugin; + + // Just use a stub AuthenticationContext instance + AuthenticationContext context = new AuthnContext(); + + @BeforeEach + public void setUp() { + duoUniversalPlugin = Mockito.mock(DuoUniversalPlugin.class); + duoUniversalPlugin.failmode = DuoUniversalPlugin.Failmode.OPEN; + duoUniversalPlugin.username = "username"; + duoUniversalPlugin.duoClient = Mockito.mock(Client.class); + + // Mock some methods dealing with AuthenticationContext + doNothing().when(duoUniversalPlugin).updatePluginResponse(isA(AuthenticationContext.class)); + doNothing().when(duoUniversalPlugin).storeStateInSession(isA(AuthenticationContext.class), any(String.class)); + doNothing().when(duoUniversalPlugin).issueRedirect(isA(AuthenticationContext.class), any(String.class)); + + Mockito.when(duoUniversalPlugin.duoClient.generateState()).thenReturn("GOOD_STATE"); + + // Call the real Phase 1 method + Mockito.when(duoUniversalPlugin.handlePhase1(isA(AuthenticationContext.class), isA(Client.class))).thenCallRealMethod(); + } + + @Test + public void testSuccess() throws DuoException { + Mockito.when(duoUniversalPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoUniversalPlugin.Failmode.class))).thenReturn(DuoUniversalPlugin.FailmodeResult.AUTH); + Mockito.when(duoUniversalPlugin.duoClient.createAuthUrl(anyString(), anyString())).thenReturn("url"); + + ExecutionStatus result = duoUniversalPlugin.handlePhase1(context, duoUniversalPlugin.duoClient); + assertEquals(ExecutionStatus.PAUSE, result); + } + + @Test + public void testFailOpen() { + Mockito.when(duoUniversalPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoUniversalPlugin.Failmode.class))).thenReturn(DuoUniversalPlugin.FailmodeResult.ALLOW); + + ExecutionStatus result = duoUniversalPlugin.handlePhase1(context, duoUniversalPlugin.duoClient); + assertEquals(ExecutionStatus.SUCCESS, result); + } + + @Test + public void testFailClosed() { + Mockito.when(duoUniversalPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoUniversalPlugin.Failmode.class))).thenReturn(DuoUniversalPlugin.FailmodeResult.BLOCK); + + ExecutionStatus result = duoUniversalPlugin.handlePhase1(context, duoUniversalPlugin.duoClient); + assertEquals(ExecutionStatus.FAILURE, result); + } + + @Test + public void testAuthUrlExceptionFailure() throws DuoException { + Mockito.when(duoUniversalPlugin.performHealthCheckAndFailmode(isA(Client.class), isA(DuoUniversalPlugin.Failmode.class))).thenReturn(DuoUniversalPlugin.FailmodeResult.AUTH); + Mockito.when(duoUniversalPlugin.duoClient.createAuthUrl(anyString(), anyString())).thenThrow(new DuoException("woops")); + + ExecutionStatus result = duoUniversalPlugin.handlePhase1(context, duoUniversalPlugin.duoClient); + assertEquals(ExecutionStatus.FAILURE, result); + } +} diff --git a/src/test/java/com/duosecurity/plugin/DuoPluginPhase2Test.java b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginPhase2Test.java similarity index 52% rename from src/test/java/com/duosecurity/plugin/DuoPluginPhase2Test.java rename to src/test/java/com/duosecurity/plugin/DuoUniversalPluginPhase2Test.java index 6e63f62..a7bb58a 100644 --- a/src/test/java/com/duosecurity/plugin/DuoPluginPhase2Test.java +++ b/src/test/java/com/duosecurity/plugin/DuoUniversalPluginPhase2Test.java @@ -19,8 +19,8 @@ import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doNothing; -public class DuoPluginPhase2Test { - DuoPlugin duoPlugin; +public class DuoUniversalPluginPhase2Test { + DuoUniversalPlugin duoUniversalPlugin; CredentialParam GOOD_PARAM = new CredentialParam(); String GOOD_STATE = "GOOD_STATE"; @@ -31,50 +31,50 @@ public class DuoPluginPhase2Test { @BeforeEach public void setUp() { - duoPlugin = Mockito.mock(DuoPlugin.class); - duoPlugin.username = "username"; - duoPlugin.duoClient = Mockito.mock(Client.class); + duoUniversalPlugin = Mockito.mock(DuoUniversalPlugin.class); + duoUniversalPlugin.username = "username"; + duoUniversalPlugin.duoClient = Mockito.mock(Client.class); - doNothing().when(duoPlugin).updatePluginResponse(isA(AuthenticationContext.class)); + doNothing().when(duoUniversalPlugin).updatePluginResponse(isA(AuthenticationContext.class)); GOOD_PARAM.setValue("GOOD_CODE"); // Call the real Phase 2 method - Mockito.when(duoPlugin.handlePhase2(isA(AuthenticationContext.class), isA(Client.class), isA(CredentialParam.class))).thenCallRealMethod(); + Mockito.when(duoUniversalPlugin.handlePhase2(isA(AuthenticationContext.class), isA(Client.class), isA(CredentialParam.class))).thenCallRealMethod(); } @Test public void testSuccess() { // Mock out calls dealing with AuthenticationContext functionality - Mockito.when(duoPlugin.getStateFromRequest(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); - Mockito.when(duoPlugin.getStateFromSession(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); + Mockito.when(duoUniversalPlugin.getStateFromRequest(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); + Mockito.when(duoUniversalPlugin.getStateFromSession(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); - ExecutionStatus result = duoPlugin.handlePhase2(context, duoPlugin.duoClient, GOOD_PARAM); + ExecutionStatus result = duoUniversalPlugin.handlePhase2(context, duoUniversalPlugin.duoClient, GOOD_PARAM); assertEquals(ExecutionStatus.SUCCESS, result); } @Test public void testStateMismatchFailure() { // Mock out calls dealing with AuthenticationContext functionality - Mockito.when(duoPlugin.getStateFromRequest(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); - Mockito.when(duoPlugin.getStateFromSession(isA(AuthenticationContext.class))).thenReturn(BAD_STATE); + Mockito.when(duoUniversalPlugin.getStateFromRequest(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); + Mockito.when(duoUniversalPlugin.getStateFromSession(isA(AuthenticationContext.class))).thenReturn(BAD_STATE); // Phase 2 should return FAILURE when the states don't match - ExecutionStatus result = duoPlugin.handlePhase2(context, duoPlugin.duoClient, GOOD_PARAM); + ExecutionStatus result = duoUniversalPlugin.handlePhase2(context, duoUniversalPlugin.duoClient, GOOD_PARAM); assertEquals(ExecutionStatus.FAILURE, result); } @Test public void testApiCallExceptionFailure() throws DuoException { // Mock out calls dealing with AuthenticationContext functionality - Mockito.when(duoPlugin.getStateFromRequest(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); - Mockito.when(duoPlugin.getStateFromSession(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); + Mockito.when(duoUniversalPlugin.getStateFromRequest(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); + Mockito.when(duoUniversalPlugin.getStateFromSession(isA(AuthenticationContext.class))).thenReturn(GOOD_STATE); // Mock out the Duo client call - Mockito.when(duoPlugin.duoClient.exchangeAuthorizationCodeFor2FAResult(anyString(), anyString())).thenThrow(new DuoException("Woops")); + Mockito.when(duoUniversalPlugin.duoClient.exchangeAuthorizationCodeFor2FAResult(anyString(), anyString())).thenThrow(new DuoException("Woops")); // Phase 2 should return FAILURE when the Duo API call throws a DuoException - ExecutionStatus result = duoPlugin.handlePhase2(context, duoPlugin.duoClient, GOOD_PARAM); + ExecutionStatus result = duoUniversalPlugin.handlePhase2(context, duoUniversalPlugin.duoClient, GOOD_PARAM); assertEquals(ExecutionStatus.FAILURE, result); }