Search in sources :

Example 1 with ExtensionHook

use of org.parosproxy.paros.extension.ExtensionHook in project zaproxy by zaproxy.

the class ApiGeneratorUtilsTest method loadCoreApis.

@BeforeEach
void loadCoreApis() throws Exception {
    Control.initSingletonForTesting(Model.getSingleton());
    ExtensionHook hook = new ExtensionHook(Model.getSingleton(), null) {

        @Override
        public void addApiImplementor(ApiImplementor apiImplementor) {
            coreApis.put(apiImplementor.getPrefix(), apiImplementor);
        }
    };
    ExtensionLoader extLoader = Control.getSingleton().getExtensionLoader();
    CoreFunctionality.getBuiltInExtensions().forEach(ext -> {
        extLoader.addExtension(ext);
        ext.init();
        ext.initModel(Model.getSingleton());
        ext.hook(hook);
    });
}
Also used : ExtensionHook(org.parosproxy.paros.extension.ExtensionHook) ExtensionLoader(org.parosproxy.paros.extension.ExtensionLoader) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ExtensionHook

use of org.parosproxy.paros.extension.ExtensionHook in project zaproxy by zaproxy.

the class ExtensionAuthenticationUnitTest method shouldImportAllAuthContextData.

@Test
void shouldImportAllAuthContextData() throws ConfigurationException {
    // 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;
    Configuration config = new ZapXmlConfiguration();
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_TYPE, 2);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_STRATEGY, AuthCheckingStrategy.POLL_URL.name());
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_URL, pollUrl);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_DATA, pollData);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_HEADERS, pollHeaders);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_FREQ, pollFreq);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_POLL_UNITS, AuthPollFrequencyUnits.REQUESTS.name());
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDIN, loggedInIndicator);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDOUT, loggedOutIndicator);
    ExtensionHook hook = new ExtensionHook(Model.getSingleton(), null);
    extensionAuthentication.hook(hook);
    // When
    extensionAuthentication.importContextData(context, config);
    AuthenticationMethod method = context.getAuthenticationMethod();
    // Then
    assertThat(method.getClass().getCanonicalName(), is(FormBasedAuthenticationMethod.class.getCanonicalName()));
    assertThat(method.getAuthCheckingStrategy(), is(AuthCheckingStrategy.POLL_URL));
    assertThat(method.getPollUrl(), is(pollUrl));
    assertThat(method.getPollData(), is(pollData));
    assertThat(method.getPollHeaders(), is(pollHeaders));
    assertThat(method.getPollFrequencyUnits(), is(AuthPollFrequencyUnits.REQUESTS));
    assertThat(method.getPollFrequency(), is(pollFreq));
    assertThat(method.getLoggedInIndicatorPattern().toString(), is(loggedInIndicator));
    assertThat(method.getLoggedOutIndicatorPattern().toString(), 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) ExtensionHook(org.parosproxy.paros.extension.ExtensionHook) FormBasedAuthenticationMethod(org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod) AuthenticationMethod(org.zaproxy.zap.authentication.AuthenticationMethod) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 3 with ExtensionHook

use of org.parosproxy.paros.extension.ExtensionHook in project zaproxy by zaproxy.

the class ExtensionAuthenticationUnitTest method shouldImportContextWithNoPollData.

@Test
void shouldImportContextWithNoPollData() throws ConfigurationException {
    // Given
    Context context = new Context(null, 0);
    String loggedInIndicator = "logged in";
    String loggedOutIndicator = "logged out";
    Configuration config = new ZapXmlConfiguration();
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_TYPE, 2);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDIN, loggedInIndicator);
    config.setProperty(AuthenticationMethod.CONTEXT_CONFIG_AUTH_LOGGEDOUT, loggedOutIndicator);
    ExtensionHook hook = new ExtensionHook(Model.getSingleton(), null);
    extensionAuthentication.hook(hook);
    // When
    extensionAuthentication.importContextData(context, config);
    AuthenticationMethod method = context.getAuthenticationMethod();
    // Then
    assertThat(method.getClass().getCanonicalName(), is(FormBasedAuthenticationMethod.class.getCanonicalName()));
    assertThat(method.getAuthCheckingStrategy(), is(AuthCheckingStrategy.EACH_RESP));
    assertThat(method.getLoggedInIndicatorPattern().toString(), is(loggedInIndicator));
    assertThat(method.getLoggedOutIndicatorPattern().toString(), 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) ExtensionHook(org.parosproxy.paros.extension.ExtensionHook) FormBasedAuthenticationMethod(org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod) AuthenticationMethod(org.zaproxy.zap.authentication.AuthenticationMethod) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Aggregations

ExtensionHook (org.parosproxy.paros.extension.ExtensionHook)3 Configuration (org.apache.commons.configuration.Configuration)2 Test (org.junit.jupiter.api.Test)2 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)2 AuthenticationMethod (org.zaproxy.zap.authentication.AuthenticationMethod)2 FormBasedAuthenticationMethod (org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.FormBasedAuthenticationMethod)2 Context (org.zaproxy.zap.model.Context)2 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ExtensionLoader (org.parosproxy.paros.extension.ExtensionLoader)1