Class DuoOIDCAuthnControllerTest
- java.lang.Object
-
- org.springframework.test.context.testng.AbstractTestNGSpringContextTests
-
- net.shibboleth.idp.plugin.authn.duo.impl.DuoOIDCAuthnControllerTest
-
- All Implemented Interfaces:
Aware,ApplicationContextAware,IHookable,ITestNGListener
@ContextConfiguration(classes={net.shibboleth.idp.plugin.authn.duo.impl.DuoOIDCAuthnController.class,IdPPropertyConfigurer.class}) @WebAppConfiguration @TestPropertySource(properties="idp.authn.duo.OIDC.externalAuthnPath=/Authn/Duo/2FA") public class DuoOIDCAuthnControllerTest extends AbstractTestNGSpringContextTests
Tests for theDuoOIDCAuthnController.
-
-
Field Summary
Fields Modifier and Type Field Description private StringAPI_HOSTDuo host the integration uses, and redirects should goto.private StringCODEDuo OIDC authz code.private StringKEYSWF key.private org.slf4j.LoggerlogClass logger.private MockMvcmockMvcThe mock MVC entry point for testing.private StringNONCEDuo OIDC nonce component of the state parameter.private javax.servlet.ServletContextservletContextThe mock servlet context.private StringstateDuo OIDC state parameter.private WebApplicationContextwebApplicationContextThe web application context loaded by the test framework.-
Fields inherited from class org.springframework.test.context.testng.AbstractTestNGSpringContextTests
applicationContext, logger
-
-
Constructor Summary
Constructors Constructor Description DuoOIDCAuthnControllerTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private ProfileRequestContextbuildProfileRequestContext()Build aProfileRequestContextby configuring a suitable context tree for external authentication e.g.private voidexportServletContextAttributes()Export the FlowExecutor to the servlet context with the correct set of configured contexts.private net.shibboleth.idp.plugin.authn.duo.context.DuoOIDCAuthenticationContextextractDuoContext()Extract theDuoOIDCAuthenticationContextfrom theProfileRequestContextultimately stored in theServletContext.private voidremoveDuoContext()Remove the Duo authentication context from the profile request context.voidsetUp()Setup.voidtestCallbackNoCode()Test an exception is thrown if the callback does not contain an auth_code parameter.voidtestCallbackNoDuoAuthenticationContext()Remove the Duo authentication context from the authentication context and check the controller encodes an error as a http request attribute when ending a 2FA request.voidtestCallbackNoState()Test an exception is thrown if the callback does not contain a state parameter.voidtestIncorrectStateNoExecutionKey()Checks that a state response with no key component triggers and error.voidtestIncorrectStateNoNonce()Checks that a state response with no nonce component triggers and error.voidtestSuccessfulAuthorizeRequest()Start a Duo 2FA request.voidtestSuccessfulCallback()Ensure the 2FA end controller adds the correct Duo response information into the Duo authentication context.-
Methods inherited from class org.springframework.test.context.testng.AbstractTestNGSpringContextTests
run, setApplicationContext, springTestContextAfterTestClass, springTestContextAfterTestMethod, springTestContextBeforeTestClass, springTestContextBeforeTestMethod, springTestContextPrepareTestInstance
-
-
-
-
Field Detail
-
API_HOST
@Nonnull private final String API_HOST
Duo host the integration uses, and redirects should goto.- See Also:
- Constant Field Values
-
KEY
@Nonnull private final String KEY
SWF key.- See Also:
- Constant Field Values
-
NONCE
@Nonnull private String NONCE
Duo OIDC nonce component of the state parameter.
-
state
@NonnullAfterInit private String state
Duo OIDC state parameter.
-
CODE
@Nonnull private final String CODE
Duo OIDC authz code.- See Also:
- Constant Field Values
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
mockMvc
@Nonnull private MockMvc mockMvc
The mock MVC entry point for testing.
-
servletContext
@Nonnull @Autowired private javax.servlet.ServletContext servletContext
The mock servlet context.
-
webApplicationContext
@Nonnull @Autowired private WebApplicationContext webApplicationContext
The web application context loaded by the test framework.
-
-
Method Detail
-
setUp
@BeforeMethod public void setUp() throws Exception
Setup.- Throws:
Exception- on error.
-
testSuccessfulAuthorizeRequest
public void testSuccessfulAuthorizeRequest() throws ExceptionStart a Duo 2FA request.- Throws:
Exception- on exception.
-
testIncorrectStateNoExecutionKey
public void testIncorrectStateNoExecutionKey() throws ExceptionChecks that a state response with no key component triggers and error.- Throws:
Exception- on exception.
-
testIncorrectStateNoNonce
public void testIncorrectStateNoNonce() throws ExceptionChecks that a state response with no nonce component triggers and error.- Throws:
Exception- on exception.
-
testSuccessfulCallback
public void testSuccessfulCallback() throws ExceptionEnsure the 2FA end controller adds the correct Duo response information into the Duo authentication context.- Throws:
Exception- on exception.
-
testCallbackNoDuoAuthenticationContext
public void testCallbackNoDuoAuthenticationContext() throws ExceptionRemove the Duo authentication context from the authentication context and check the controller encodes an error as a http request attribute when ending a 2FA request.- Throws:
Exception- on exception.
-
testCallbackNoCode
public void testCallbackNoCode() throws ExceptionTest an exception is thrown if the callback does not contain an auth_code parameter.- Throws:
Exception- on exception.
-
testCallbackNoState
public void testCallbackNoState() throws ExceptionTest an exception is thrown if the callback does not contain a state parameter.- Throws:
Exception- on exception.
-
exportServletContextAttributes
private void exportServletContextAttributes() throws DuoClientExceptionExport the FlowExecutor to the servlet context with the correct set of configured contexts. Mimicking the IdP's configuration of theServletContextAttributeExporter.- Throws:
DuoClientException- on error creating the duoclient.
-
buildProfileRequestContext
@Nonnull private ProfileRequestContext buildProfileRequestContext() throws DuoClientException
Build aProfileRequestContextby configuring a suitable context tree for external authentication e.g. aAuthenticationContextandExternalAuthenticationContext.- Returns:
- a profile request context.
- Throws:
DuoClientException- on error creating the duo client
-
removeDuoContext
private void removeDuoContext()
Remove the Duo authentication context from the profile request context.
-
extractDuoContext
@Nonnull private net.shibboleth.idp.plugin.authn.duo.context.DuoOIDCAuthenticationContext extractDuoContext()
Extract theDuoOIDCAuthenticationContextfrom theProfileRequestContextultimately stored in theServletContext.- Returns:
- the Duo authentication context extracted from the profile request context.
-
-