use of org.parosproxy.paros.core.scanner.Variant in project zaproxy by zaproxy.
the class VariantFactoryUnitTest method shouldUseVariantScripts.
@Test
@SuppressWarnings("unchecked")
void shouldUseVariantScripts() {
// Given
VariantScript script = mock(TARGET_INTERFACE);
CachedScript<VariantScript> cachedScript = createCachedScript(script);
ScriptsCache<VariantScript> scriptsCache = createScriptsCache(cachedScript);
given(extensionScript.<VariantScript>createScriptsCache(any())).willReturn(scriptsCache);
// When
List<Variant> variants = factory.createSiteModifyingVariants();
// Then
verify(scriptsCache, times(1)).refreshAndExecute(any(ScriptWrapperAction.class));
assertThat(variants, hasSize(1));
assertThat(variants.get(0), is(instanceOf(VariantCustom.class)));
}
use of org.parosproxy.paros.core.scanner.Variant in project zaproxy by zaproxy.
the class VariantFactoryUnitTest method shouldReturnNoVariantsWhenUnset.
@Test
void shouldReturnNoVariantsWhenUnset() {
// Given
ScannerParam scanOptions = Mockito.mock(ScannerParam.class, withSettings().lenient());
Mockito.when(scanOptions.getConfig()).thenReturn(new ZapXmlConfiguration());
HttpMessage message = new HttpMessage();
scanOptions.setTargetParamsInjectable(0);
// When
List<Variant> variants = factory.createVariants(scanOptions, message);
// Then
assertThat(variants.size(), is(equalTo(0)));
}
use of org.parosproxy.paros.core.scanner.Variant in project zaproxy by zaproxy.
the class VariantFactoryUnitTest method shouldReturnCustomVariants.
@Test
void shouldReturnCustomVariants() {
// Given
factory.addVariant(TestVariant.class);
ScannerParam scanOptions = new ScannerParam();
HttpMessage message = new HttpMessage();
// When
List<Variant> variants = factory.createVariants(scanOptions, message);
// Then
assertThat(variants.size(), is(equalTo(11)));
assertThat(variants.get(0).getClass(), is(equalTo(VariantURLQuery.class)));
assertThat(variants.get(1).getClass(), is(equalTo(VariantODataIdQuery.class)));
assertThat(variants.get(2).getClass(), is(equalTo(VariantODataFilterQuery.class)));
assertThat(variants.get(3).getClass(), is(equalTo(VariantDdnPath.class)));
assertThat(variants.get(4).getClass(), is(equalTo(VariantFormQuery.class)));
assertThat(variants.get(5).getClass(), is(equalTo(VariantMultipartFormParameters.class)));
assertThat(variants.get(6).getClass(), is(equalTo(VariantXMLQuery.class)));
assertThat(variants.get(7).getClass(), is(equalTo(VariantJSONQuery.class)));
assertThat(variants.get(8).getClass(), is(equalTo(VariantGWTQuery.class)));
assertThat(variants.get(9).getClass(), is(equalTo(VariantDirectWebRemotingQuery.class)));
assertThat(variants.get(10).getClass(), is(equalTo(TestVariant.class)));
}
use of org.parosproxy.paros.core.scanner.Variant in project zaproxy by zaproxy.
the class VariantFactoryUnitTest method shouldScanNullJsonValuesAsDefinedInOptions.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void shouldScanNullJsonValuesAsDefinedInOptions(boolean scanNulls) {
// Given
ScannerParam scanOptions = mock(ScannerParam.class);
given(scanOptions.getTargetParamsInjectable()).willReturn(ScannerParam.TARGET_POSTDATA);
given(scanOptions.getTargetParamsEnabledRPC()).willReturn(ScannerParam.RPC_JSON);
given(scanOptions.isScanNullJsonValues()).willReturn(scanNulls);
HttpMessage message = new HttpMessage();
// When
List<Variant> variants = factory.createVariants(scanOptions, message);
// Then
VariantJSONQuery jsonVariant = getVariant(variants, VariantJSONQuery.class);
assertThat(jsonVariant.isScanNullValues(), is(equalTo(scanNulls)));
}
use of org.parosproxy.paros.core.scanner.Variant in project zaproxy by zaproxy.
the class ScriptsActiveScannerUnitTest method shouldScanParamsWithActiveScript.
@Test
@SuppressWarnings("unchecked")
void shouldScanParamsWithActiveScript() throws Exception {
// Given
ActiveScript script1 = mock(ActiveScript.class);
ScriptWrapper scriptWrapper1 = createScriptWrapper(script1, ActiveScript.class);
ActiveScript script2 = mock(ActiveScript.class);
ScriptWrapper scriptWrapper2 = createScriptWrapper(script2, ActiveScript.class);
given(extensionScript.getScripts(SCRIPT_TYPE)).willReturn(asList(scriptWrapper1, scriptWrapper2));
ScriptsCache<ActiveScript> scriptsCache = createScriptsCache(createCachedScript(script1, scriptWrapper1), createCachedScript(script2, scriptWrapper2));
given(extensionScript.<ActiveScript>createScriptsCache(any())).willReturn(scriptsCache);
given(parent.getScannerParam()).willReturn(mock(ScannerParam.class));
String name1 = "Name1";
String value1 = "Value1";
NameValuePair param1 = param(name1, value1);
String name2 = "Name2";
String value2 = "Value2";
NameValuePair param2 = param(name2, value2);
Variant variant = mock(Variant.class);
given(variant.getParamList()).willReturn(asList(param1, param2));
VariantFactory variantFactory = mock(VariantFactory.class);
given(variantFactory.createVariants(any(), any())).willReturn(asList(variant));
given(model.getVariantFactory()).willReturn(variantFactory);
ScriptsActiveScanner scriptsActiveScanner = new ScriptsActiveScanner();
scriptsActiveScanner.init(message, parent);
// When
scriptsActiveScanner.scan();
// Then
verify(scriptsCache, times(2)).refresh();
verify(scriptsCache, times(2)).getCachedScripts();
verify(script1, times(1)).scan(scriptsActiveScanner, message, name1, value1);
verify(script1, times(1)).scan(scriptsActiveScanner, message, name2, value2);
verify(script2, times(1)).scan(scriptsActiveScanner, message, name1, value1);
verify(script2, times(1)).scan(scriptsActiveScanner, message, name2, value2);
}
Aggregations