Skip to content

Commit e9fec2a

Browse files
authored
Merge pull request #5266 from thc202/automation/parse-locale
automation: correct threshold/strength parsing
2 parents b70ecf8 + a3c3d9a commit e9fec2a

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

addOns/automation/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7-
7+
### Fixed
8+
- Correct parsing of attack strength and alert threshold in some locales.
89

910
## [0.35.0] - 2024-01-16
1011
### Added

addOns/automation/src/main/java/org/zaproxy/addon/automation/jobs/JobUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static AttackStrength parseAttackStrength(
8787
}
8888
if (o instanceof String) {
8989
try {
90-
strength = AttackStrength.valueOf(((String) o).toUpperCase());
90+
strength = AttackStrength.valueOf(((String) o).toUpperCase(Locale.ROOT));
9191
} catch (Exception e) {
9292
progress.warn(
9393
Constant.messages.getString("automation.error.ascan.strength", jobName, o));
@@ -107,7 +107,7 @@ public static AlertThreshold parseAlertThreshold(
107107
}
108108
if (o instanceof String) {
109109
try {
110-
threshold = AlertThreshold.valueOf(((String) o).toUpperCase());
110+
threshold = AlertThreshold.valueOf(((String) o).toUpperCase(Locale.ROOT));
111111
} catch (Exception e) {
112112
progress.warn(
113113
Constant.messages.getString(

addOns/automation/src/test/java/org/zaproxy/addon/automation/jobs/JobUtilsUnitTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@
3939
import java.util.List;
4040
import java.util.Locale;
4141
import java.util.Map;
42+
import java.util.stream.Stream;
4243
import org.junit.jupiter.api.BeforeAll;
4344
import org.junit.jupiter.api.Test;
45+
import org.junit.jupiter.params.ParameterizedTest;
46+
import org.junit.jupiter.params.provider.MethodSource;
4447
import org.mockito.quality.Strictness;
4548
import org.parosproxy.paros.Constant;
4649
import org.parosproxy.paros.control.Control;
50+
import org.parosproxy.paros.core.scanner.Plugin.AlertThreshold;
51+
import org.parosproxy.paros.core.scanner.Plugin.AttackStrength;
4752
import org.parosproxy.paros.extension.ExtensionLoader;
4853
import org.parosproxy.paros.model.Model;
4954
import org.zaproxy.addon.automation.AutomationEnvironment;
@@ -409,6 +414,47 @@ void shouldReturnFileFromRelativePathWithVars() {
409414
assertFilePath(f, "/full/path/dir/relative/path/to/file");
410415
}
411416

417+
static Stream<Locale> locales() {
418+
return Stream.of(
419+
Locale.ROOT, Locale.ENGLISH, new Locale.Builder().setLanguage("TR").build());
420+
}
421+
422+
@ParameterizedTest
423+
@MethodSource("locales")
424+
void shouldParseAttackStrengthInDifferentLocales(Locale locale) {
425+
Locale defaultLocale = Locale.getDefault();
426+
try {
427+
// Given
428+
Locale.setDefault(locale);
429+
AutomationProgress progress = mock(AutomationProgress.class);
430+
// When
431+
AttackStrength attackStrength = JobUtils.parseAttackStrength("medium", "job", progress);
432+
// Then
433+
assertThat(attackStrength, is(equalTo(AttackStrength.MEDIUM)));
434+
verifyNoInteractions(progress);
435+
} finally {
436+
Locale.setDefault(defaultLocale);
437+
}
438+
}
439+
440+
@ParameterizedTest
441+
@MethodSource("locales")
442+
void shouldParseAlertThresholdInDifferentLocales(Locale locale) {
443+
Locale defaultLocale = Locale.getDefault();
444+
try {
445+
// Given
446+
Locale.setDefault(locale);
447+
AutomationProgress progress = mock(AutomationProgress.class);
448+
// When
449+
AlertThreshold alertThreshold = JobUtils.parseAlertThreshold("medium", "job", progress);
450+
// Then
451+
assertThat(alertThreshold, is(equalTo(AlertThreshold.MEDIUM)));
452+
verifyNoInteractions(progress);
453+
} finally {
454+
Locale.setDefault(defaultLocale);
455+
}
456+
}
457+
412458
private static void assertFilePath(File file, String path) {
413459
assertThat(
414460
file.toPath().normalize().toAbsolutePath(), is(Paths.get(path).toAbsolutePath()));

0 commit comments

Comments
 (0)