Search in sources :

Example 1 with FormBasedAuthenticationMethod

use of org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod in project zaproxy by zaproxy.

the class ExtensionAuthenticationUnitTest method shouldExportAllAuthContextData.

@Test
void shouldExportAllAuthContextData() {
    // Given
    Context context = new Context(null, 0);
    String loggedInIndicator = "logged in";
    String loggedOutIndicator = "logged out";
    String pollUrl = "https://www.example.com/poll";
    String pollData = "example-poll-data";
    String pollHeaders = "aaa : bbb\\Nccc : ddd";
    int pollFreq = 55;
    FormBasedAuthenticationMethodType type = new FormBasedAuthenticationMethodType();
    FormBasedAuthenticationMethod method = type.createAuthenticationMethod(0);
    method.setAuthCheckingStrategy(AuthCheckingStrategy.POLL_URL);
    method.setPollUrl(pollUrl);
    method.setPollData(pollData);
    method.setPollHeaders(pollHeaders);
    method.setPollFrequencyUnits(AuthPollFrequencyUnits.REQUESTS);
    method.setPollFrequency(pollFreq);
    method.setLoggedInIndicatorPattern(loggedInIndicator);
    method.setLoggedOutIndicatorPattern(loggedOutIndicator);
    context.setAuthenticationMethod(method);
    Configuration config = new ZapXmlConfiguration();
    // When
    extensionAuthentication.exportContextData(context, config);
    // Then
    assertThat(config.getInt(AuthenticationMethod.CONTEXT_CONFIG_AUTH_TYPE), is(2));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_STRATEGY), is(AuthCheckingStrategy.POLL_URL.name()));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_URL), is(pollUrl));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_DATA), is(pollData));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_HEADERS), is(pollHeaders));
    assertThat(config.getInt(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_FREQ), is(pollFreq));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_UNITS), is(AuthPollFrequencyUnits.REQUESTS.name()));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDIN), is(loggedInIndicator));
    assertThat(config.getString(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDOUT), is(loggedOutIndicator));
}
Also used : Context(org.zaproxy.zap.model.Context) Configuration(org.apache.commons.configuration.Configuration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration) FormBasedAuthenticationMethod(org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod) FormBasedAuthenticationMethodType(org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Aggregations

Configuration (org.apache.commons.configuration.Configuration)1 Test (org.junit.jupiter.api.Test)1 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)1 FormBasedAuthenticationMethodType (org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType)1 FormBasedAuthenticationMethod (org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod)1 Context (org.zaproxy.zap.model.Context)1 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)1