Class AbstractAuthnXmlFlowExecutionTests
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.springframework.webflow.test.execution.AbstractFlowExecutionTests
-
- org.springframework.webflow.test.execution.AbstractExternalizedFlowExecutionTests
-
- net.shibboleth.idp.plugin.authn.spring.CustomAbstractXmlFlowExecutionTests
-
- net.shibboleth.idp.plugin.authn.duo.impl.AbstractAuthnXmlFlowExecutionTests
-
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
DuoAuthnFlowTest
public abstract class AbstractAuthnXmlFlowExecutionTests extends CustomAbstractXmlFlowExecutionTests
Base test class for testing webflows in isolation from the rest of the IdP.
Each flow test reinitialises the mock beans. See
setUp()andregisterMockBeanDefinitions(MockFlowBuilderContext).Extends the
CustomAbstractXmlFlowExecutionTestsover the standardAbstractExternalizedFlowExecutionTestsfor the sole reason of being able to set aCustomFlowModelFlowBuilderwith a placeholder prefix of%{to be compatible with those used by the IdP. We also set this prefix in various other locations, but those are either ignored by the inbuilt SWF flow builder when it substitutes the placeholder inside the bean import, or do not share the same Mock properties source as is set in theregisterMockPropertySource(MockFlowBuilderContext)method. If a better way is found to support that, switch back to theAbstractExternalizedFlowExecutionTests.In addition, the
AnnotationParameterNameDiscovererclass is also registered with theDefaultListableBeanFactoryfor the context created by theCustomFlowModelFlowBuilder.Note, you can not use test context creation annotations e.g. @SpringJUnitWebConfig to help build the application context because the
AbstractExternalizedFlowExecutionTestscreates a newStaticApplicationContextwhen building the flow (see buildFlow). This is different from theApplicationContextcreated byContextConfigurationannotation processors. As a result, those bean configurations and environment variables need to be injected insideconfigureFlowBuilderContext(MockFlowBuilderContext)These test use JUnit (for SWF test compatibility), and work with the TestNG to JUnit bridge
-
-
Field Summary
Fields Modifier and Type Field Description private DuoOIDCClientFactoryclientFactoryThe Duo client factory to use.protected MockExternalContextexternalContextMock external context.private Map<String,String>flowModelResourcesMap of additional flow resources used to support the construction of the test flow.private StringflowPathThe path resource to the authentication flow to be tested.private org.slf4j.LoggerlogClass logger.private Map<String,String>mockPropertiesMap of properties to set.protected MockHttpServletRequestmockRequestMock request.protected MockHttpServletResponsemockResponseMock response.private booleanremoveDefaultContextCleanupHookIf true the default DuoContext removal cleanup hook is removed, so the context can be inspected by the test conditions.private List<Flow>subflowsMock flows to add as stub subflows when executing the main test flow.
-
Constructor Summary
Constructors Constructor Description AbstractAuthnXmlFlowExecutionTests()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddBeanDefinition(MockFlowBuilderContext builderContext, String beanName, BeanDefinition bean)Adds the bean to theStaticApplicationContextcontained in the builder context.voidaddHttpBasicAuthHeader(String username, String password)Add HTTP basic authentication headers to the request.protected ProfileRequestContextbuildProfileRequestContext(boolean forceAuthn, boolean addC14Context)Build aProfileRequestContextby configuring a suitable context tree e.g.protected voidconfigureFlowBuilderContext(MockFlowBuilderContext builderContext)protected FlowDefinitionResource[]getModelResources(FlowDefinitionResourceFactory resourceFactory)Template method subclasses may override to return pointers to "flow model resources" needed to build the definition of the flow being tested.protected FlowDefinitionResourcegetResource(FlowDefinitionResourceFactory resourceFactory)protected booleanisRemoveDefaultContextCleanupHook()Is the default duo context cleanup hook to be removed?private voidregisterMockBeanDefinitions(MockFlowBuilderContext builderContext)Register mock beans that are not necessary to configure for authentication testing but are required for authentication flows to proceed.private voidregisterMockPropertySource(MockFlowBuilderContext builderContext)private voidregisterMockSubflows(MockFlowBuilderContext builderContext)Register the subflows with the builder context.voidsetClientFactory(DuoOIDCClientFactory factory)Set the Duo client factory to use.voidsetFlowModelResources(Map<String,String> testFlowModelResources)Set the flow model resources (parent flows) that support the assembly of the flow to test.voidsetFlowPath(String testFlowPath)Set the path to the flow to test.voidsetMockProperties(Map<String,String> properties)Set the mock properties to use within a property source.protected voidsetRemoveDefaultContextCleanupHook(boolean removeDefaultContextCleanupHook)Set the remove default context cleanup hook.voidsetSubflows(List<Flow> mockSubflows)Set the mock subflows to be used with the flow to test.voidsetUp()Setup the mock objects before each method.-
Methods inherited from class net.shibboleth.idp.plugin.authn.spring.CustomAbstractXmlFlowExecutionTests
createFlowBuilder, registerMockFlowBeans
-
Methods inherited from class org.springframework.webflow.test.execution.AbstractExternalizedFlowExecutionTests
buildFlow, createResourceLoader, getFlow, getFlowDefinition, getFlowDefinitionRegistry, getResourceFactory, isCacheFlowDefinition, setCacheFlowDefinition, setFlowExecutionAttributes, setFlowExecutionListener, setFlowExecutionListeners
-
Methods inherited from class org.springframework.webflow.test.execution.AbstractFlowExecutionTests
assertActiveFlowEquals, assertCurrentStateEquals, assertFlowExecutionActive, assertFlowExecutionEnded, assertFlowExecutionOutcomeEquals, assertResponseWrittenEquals, createFlowExecutionFactory, getConversationAttribute, getConversationScope, getFlowAttribute, getFlowExecution, getFlowExecutionFactory, getFlowExecutionOutcome, getFlowScope, getRequiredConversationAttribute, getRequiredConversationAttribute, getRequiredFlowAttribute, getRequiredFlowAttribute, getRequiredViewAttribute, getRequiredViewAttribute, getViewAttribute, getViewScope, resumeFlow, setCurrentState, startFlow, startFlow, updateFlowExecution
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, tearDown, toString
-
-
-
-
Field Detail
-
mockRequest
protected MockHttpServletRequest mockRequest
Mock request.
-
mockResponse
protected MockHttpServletResponse mockResponse
Mock response.
-
externalContext
protected MockExternalContext externalContext
Mock external context.
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
flowPath
@Nonnull private String flowPath
The path resource to the authentication flow to be tested.
-
flowModelResources
@Nonnull private Map<String,String> flowModelResources
Map of additional flow resources used to support the construction of the test flow. These are only possible parents of the flow, and can not be used to load other flows.The key is the path to the resource, the value is the flowID.
-
subflows
@Nonnull private List<Flow> subflows
Mock flows to add as stub subflows when executing the main test flow.
-
clientFactory
@Nullable private DuoOIDCClientFactory clientFactory
The Duo client factory to use.
-
removeDefaultContextCleanupHook
private boolean removeDefaultContextCleanupHook
If true the default DuoContext removal cleanup hook is removed, so the context can be inspected by the test conditions.
-
-
Method Detail
-
setFlowModelResources
public void setFlowModelResources(@Nonnull Map<String,String> testFlowModelResources)Set the flow model resources (parent flows) that support the assembly of the flow to test.- Parameters:
testFlowModelResources- the parent flows.
-
setClientFactory
public void setClientFactory(@Nonnull DuoOIDCClientFactory factory)Set the Duo client factory to use.- Parameters:
factory- the Duo client factory.
-
setFlowPath
public void setFlowPath(@Nonnull @NotEmpty String testFlowPath)
Set the path to the flow to test.- Parameters:
testFlowPath- the path to the file to test.
-
setMockProperties
public void setMockProperties(@Nonnull Map<String,String> properties)Set the mock properties to use within a property source.- Parameters:
properties- the mock properties.
-
setSubflows
public void setSubflows(@Nonnull @NonnullElements List<Flow> mockSubflows)
Set the mock subflows to be used with the flow to test.- Parameters:
mockSubflows- the mock subflows.
-
addHttpBasicAuthHeader
public void addHttpBasicAuthHeader(@Nonnull String username, @Nonnull String password)Add HTTP basic authentication headers to the request.- Parameters:
username- the usernamepassword- the password
-
setUp
public void setUp() throws NoSuchFieldException, SecurityException, ExceptionSetup the mock objects before each method.- Overrides:
setUpin classjunit.framework.TestCase- Throws:
Exception- on errorSecurityException- on errorNoSuchFieldException- on error
-
getResource
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory)
- Specified by:
getResourcein classAbstractExternalizedFlowExecutionTests
-
getModelResources
protected FlowDefinitionResource[] getModelResources(FlowDefinitionResourceFactory resourceFactory)
Description copied from class:CustomAbstractXmlFlowExecutionTestsTemplate method subclasses may override to return pointers to "flow model resources" needed to build the definition of the flow being tested. Typically overridden when the flow being tested extends from another flow. Default returns null, assuming no inheritance.- Overrides:
getModelResourcesin classCustomAbstractXmlFlowExecutionTests- Parameters:
resourceFactory- the resource factory- Returns:
- the flow definition model resources
-
configureFlowBuilderContext
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext)
- Overrides:
configureFlowBuilderContextin classAbstractExternalizedFlowExecutionTests
-
registerMockSubflows
private void registerMockSubflows(@Nonnull MockFlowBuilderContext builderContext)Register the subflows with the builder context.- Parameters:
builderContext- the builder context to register the subflows with.
-
registerMockBeanDefinitions
private void registerMockBeanDefinitions(@Nonnull MockFlowBuilderContext builderContext)Register mock beans that are not necessary to configure for authentication testing but are required for authentication flows to proceed.- Parameters:
builderContext- the context used to register the beans.
-
addBeanDefinition
private void addBeanDefinition(@Nonnull MockFlowBuilderContext builderContext, @Nonnull String beanName, @Nonnull BeanDefinition bean)Adds the bean to theStaticApplicationContextcontained in the builder context.- Parameters:
builderContext- to add the bean to.beanName- the name of the bean.bean- the bean.
-
registerMockPropertySource
private void registerMockPropertySource(@Nonnull MockFlowBuilderContext builderContext)Register aMockPropertySourcewith theEnvironmentof the current flow buildersApplicationContext. Set properties required to run an authentication flow.- Parameters:
builderContext- the builder context to attach the mock property source to.
-
buildProfileRequestContext
@Nonnull protected ProfileRequestContext buildProfileRequestContext(@Nonnull boolean forceAuthn, @Nonnull boolean addC14Context)
Build aProfileRequestContextby configuring a suitable context tree e.g. aAuthenticationContext.- Parameters:
forceAuthn- force authenticationaddC14Context- add the c14 context, yes or no.- Returns:
- a profile request context.
-
isRemoveDefaultContextCleanupHook
protected boolean isRemoveDefaultContextCleanupHook()
Is the default duo context cleanup hook to be removed?- Returns:
- Returns the removeDefaultContextCleanupHook.
-
setRemoveDefaultContextCleanupHook
protected void setRemoveDefaultContextCleanupHook(boolean removeDefaultContextCleanupHook)
Set the remove default context cleanup hook.- Parameters:
removeDefaultContextCleanupHook- The removeDefaultContextCleanupHook to set.
-
-