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));
}
Aggregations