-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3058 from mercedes-benz/feature-1483-make-browser…
…-of-ajaxspider-configurable Make browser to use during ajax scan configurable #1483
- Loading branch information
Showing
8 changed files
with
106 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...p/src/main/java/com/mercedesbenz/sechub/zapwrapper/cli/ZAPAcceptedBrowserIdValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.zapwrapper.cli; | ||
|
||
import com.beust.jcommander.IParameterValidator; | ||
import com.beust.jcommander.ParameterException; | ||
import com.mercedesbenz.sechub.zapwrapper.config.ZAPAcceptedBrowserId; | ||
|
||
public class ZAPAcceptedBrowserIdValidator implements IParameterValidator { | ||
|
||
@Override | ||
public void validate(String name, String value) throws ParameterException { | ||
if (value == null) { | ||
throw new ParameterException("Specified browser id was null, only following browser ids are accepted: " + ZAPAcceptedBrowserId.values()); | ||
} | ||
boolean isValid = false; | ||
for (ZAPAcceptedBrowserId browserId : ZAPAcceptedBrowserId.values()) { | ||
if (browserId.getBrowserId().equals(value)) { | ||
isValid = true; | ||
break; | ||
} | ||
} | ||
if (!isValid) { | ||
throw new ParameterException("Specified browser id was " + value + ", only follwing browser ids are accepted: " + ZAPAcceptedBrowserId.values()); | ||
} | ||
} | ||
|
||
} |
16 changes: 13 additions & 3 deletions
16
...z/sechub/zapwrapper/config/BrowserId.java → ...pwrapper/config/ZAPAcceptedBrowserId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.zapwrapper.config; | ||
|
||
public enum BrowserId { | ||
public enum ZAPAcceptedBrowserId { | ||
|
||
FIREFOX_HEADLESS("firefox-headless"), | ||
|
||
FIREFOX("firefox"), | ||
|
||
CHROME_HEADLESS("chrome-headless"), | ||
|
||
CHROME("chrome"), | ||
|
||
HTMLUNIT("htmlunit"), | ||
|
||
SAFARI("safari"), | ||
|
||
; | ||
|
||
private String browserId; | ||
|
||
private BrowserId(String browserId) { | ||
private ZAPAcceptedBrowserId(String browserId) { | ||
this.browserId = browserId; | ||
} | ||
|
||
public String getBrowserId() { | ||
return browserId; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...c/test/java/com/mercedesbenz/sechub/zapwrapper/cli/ZAPAcceptedBrowserIdValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.zapwrapper.cli; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import com.beust.jcommander.ParameterException; | ||
import com.mercedesbenz.sechub.zapwrapper.config.ZAPAcceptedBrowserId; | ||
|
||
class ZAPAcceptedBrowserIdValidatorTest { | ||
|
||
private ZAPAcceptedBrowserIdValidator validatorToTest = new ZAPAcceptedBrowserIdValidator(); | ||
|
||
@ParameterizedTest | ||
@NullSource | ||
@ValueSource(strings = { "1", "invalid", "FIREFOX-HEADLESS" }) | ||
void invalid_values_throw_an_parameter_exception(String browserId) { | ||
/* execute + test */ | ||
assertThrows(ParameterException.class, () -> validatorToTest.validate(null, browserId)); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(ZAPAcceptedBrowserId.class) | ||
void all_valid_browser_ids_are_accepted(ZAPAcceptedBrowserId browserId) { | ||
/* execute + test */ | ||
assertDoesNotThrow(() -> validatorToTest.validate(null, browserId.getBrowserId())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters