Skip to content

Commit

Permalink
Fix Class cast exception occurs because VarMaskRegexEntry data is not…
Browse files Browse the repository at this point in the history
… bound.
  • Loading branch information
arthas-choi authored and MarkEWaite committed Oct 6, 2023
1 parent 93ee333 commit 6989acc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public ConsoleLogFilter createLoggerDecorator(Run<?, ?> build) {
// global regexes
List<MaskPasswordsConfig.VarMaskRegexEntry> globalVarMaskRegexes = config.getGlobalVarMaskRegexesU();
for(MaskPasswordsConfig.VarMaskRegexEntry globalVarMaskRegex: globalVarMaskRegexes) {
allRegexes.add(globalVarMaskRegex.getValue().getRegex());
allRegexes.add(globalVarMaskRegex.getValue());
}

// job's passwords
Expand Down Expand Up @@ -531,7 +531,7 @@ public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContex
continue;
}
writer.startNode(VAR_MASK_REGEX_NODE);
writer.addAttribute(REGEX_NAME, varMaskRegex.getName());
writer.addAttribute(REGEX_NAME, varMaskRegex.getKey());
writer.addAttribute(REGEX_ATT, varMaskRegex.getRegexString());
writer.endNode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,18 +655,18 @@ public void setRegex(VarMaskRegex regex) {
}

public String getKey() {
return this.getName();
return this.key;
}

public void setKey(String key) {
this.key = key;
}

public VarMaskRegex getValue() {
return this.getRegex();
public String getValue() {
return this.getRegex().getRegex();
}
public void setValue(VarMaskRegex regex) {
this.setRegex(regex);
public void setValue(String regex) {
this.setRegex(new VarMaskRegex(regex));
}

public String getRegexString() {
Expand All @@ -684,7 +684,7 @@ public String toString() {
@SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "We do not expect anybody to use this class."
+ "If they do, they must override clone() as well")
public Object clone() {
return new VarMaskRegexEntry(this.getName(), this.getRegex());
return new VarMaskRegexEntry(this.getKey(), this.getRegex());
}

@Override
Expand All @@ -702,7 +702,7 @@ public boolean equals(Object other) {
return false;
} else {
VarMaskRegexEntry otherE = (VarMaskRegexEntry) other;
return (this.getName().equals(otherE.getName())) && this.getRegex().equals(otherE.getRegex());
return (this.getKey().equals(otherE.getKey())) && this.getRegex().equals(otherE.getRegex());
}
}

Expand All @@ -717,7 +717,7 @@ public String getDisplayName() {
public UninstantiatedDescribable customUninstantiate(@NonNull UninstantiatedDescribable step) {
Map<String, ?> arguments = step.getArguments();
Map<String, Object> newMap1 = new HashMap<>();
newMap1.put("name", arguments.get("name"));
newMap1.put("key", arguments.get("key"));
newMap1.put("value", arguments.get("value"));
return step.withArguments(newMap1);
}
Expand All @@ -726,8 +726,8 @@ public UninstantiatedDescribable customUninstantiate(@NonNull UninstantiatedDesc
@Override
public Map<String, Object> customInstantiate(@NonNull Map<String, Object> arguments) {
Map<String, Object> newMap = new HashMap<>();
newMap.put("name", arguments.get("name"));
newMap.put("value", new VarMaskRegex((String)arguments.get("value")));
newMap.put("key", arguments.get("key"));
newMap.put("value", String.valueOf(arguments.get("value")));
return newMap;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public OutputStream decorateLogger(Run _ignore, OutputStream logger) throws IOEx
// global regexes
List<MaskPasswordsConfig.VarMaskRegexEntry> globalVarMaskRegexes = config.getGlobalVarMaskRegexesU();
for(MaskPasswordsConfig.VarMaskRegexEntry globalVarMaskRegex: globalVarMaskRegexes) {
regexes.add(globalVarMaskRegex.getValue().getRegex());
regexes.add(globalVarMaskRegex.getValue());
}
return new MaskPasswordsOutputStream(logger, passwords, regexes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void regexConfigRoundTrip() throws Exception {
story.then(step -> {
MaskPasswordsBuildWrapper bw1 = new MaskPasswordsBuildWrapper(
null,
Collections.singletonList(new MaskPasswordsConfig.VarMaskRegexEntry("test", new MaskPasswordsBuildWrapper.VarMaskRegex("foobar")))
Collections.singletonList(new MaskPasswordsConfig.VarMaskRegexEntry("test", "foobar"))
);
CoreWrapperStep step1 = new CoreWrapperStep(bw1);
CoreWrapperStep step2 = new StepConfigTester(step).configRoundTrip(step1);
Expand All @@ -98,7 +98,7 @@ public void regexConfigRoundTrip() throws Exception {
assertEquals(1, regexes.size());
MaskPasswordsConfig.VarMaskRegexEntry regex = regexes.get(0);
assertEquals("foobar", regex.getRegexString());
assertEquals("test", regex.getName());
assertEquals("test", regex.getKey());
});
}

Expand Down

0 comments on commit 6989acc

Please sign in to comment.