Skip to content

Commit 1f9774c

Browse files
committed
fix method name in tests, add one more test
1 parent 609f351 commit 1f9774c

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

core-codemods/src/test/resources/codeql-log-injection/template/Templates.java.after

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.roller.weblogger.ui.struts2.editor;
2020

21-
import static io.github.pixee.security.Newlines.stripNewLines;
21+
import static io.github.pixee.security.Newlines.stripAll;
2222
import org.apache.commons.lang3.StringUtils;
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
@@ -123,7 +123,7 @@ public class Templates extends UIAction {
123123

124124
} catch (WebloggerException ex) {
125125
log.error("Error getting templates for weblog - "
126-
+ stripNewLines(getActionWeblog().getHandle()), ex);
126+
+ stripAll(getActionWeblog().getHandle()), ex);
127127
addError("Error getting template list - check Roller logs");
128128
}
129129

@@ -196,7 +196,7 @@ public class Templates extends UIAction {
196196
setNewTmplAction(null);
197197

198198
} catch (WebloggerException ex) {
199-
log.error("Error adding new template for weblog - " + stripNewLines(getActionWeblog().getHandle()), ex);
199+
log.error("Error adding new template for weblog - " + stripAll(getActionWeblog().getHandle()), ex);
200200
addError("Error adding new template - check Roller logs");
201201
}
202202
}
@@ -254,7 +254,7 @@ public class Templates extends UIAction {
254254
}
255255

256256
} catch (Exception ex) {
257-
log.error("Error removing page - " + stripNewLines(getRemoveId()), ex);
257+
log.error("Error removing page - " + stripAll(getRemoveId()), ex);
258258
addError("editPages.remove.error");
259259
}
260260
} else {

core-codemods/src/test/resources/codeql-log-injection/templateedit/TemplateEdit.java.after

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package org.apache.roller.weblogger.ui.struts2.editor;
2020

21-
import static io.github.pixee.security.Newlines.stripNewLines;
21+
import static io.github.pixee.security.Newlines.stripAll;
2222
import org.apache.commons.lang3.StringUtils;
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
@@ -61,7 +61,7 @@ public class TemplateEdit extends UIAction {
6161
try {
6262
setTemplate(WebloggerFactory.getWeblogger().getWeblogManager().getTemplate(getBean().getId()));
6363
} catch (WebloggerException ex) {
64-
log.error("Error looking up template - " + stripNewLines(getBean().getId()), ex);
64+
log.error("Error looking up template - " + stripAll(getBean().getId()), ex);
6565
}
6666
}
6767

@@ -89,7 +89,7 @@ public class TemplateEdit extends UIAction {
8989
}
9090

9191
} catch (WebloggerException ex) {
92-
log.error("Error updating page - " + stripNewLines(getBean().getId()), ex);
92+
log.error("Error updating page - " + stripAll(getBean().getId()), ex);
9393
addError("Error saving template - check Roller logs");
9494
}
9595

@@ -126,7 +126,7 @@ public class TemplateEdit extends UIAction {
126126

127127
// save template
128128
WebloggerFactory.getWeblogger().getWeblogManager().saveTemplate(templateToSave);
129-
log.debug("Saved template: " + stripNewLines(templateToSave.getId()));
129+
log.debug("Saved template: " + stripAll(templateToSave.getId()));
130130

131131
//flush
132132
WebloggerFactory.getWeblogger().flush();
@@ -138,7 +138,7 @@ public class TemplateEdit extends UIAction {
138138
addMessage("pageForm.save.success", templateToSave.getName());
139139

140140
} catch (Exception ex) {
141-
log.error("Error updating page - " + stripNewLines(getBean().getId()), ex);
141+
log.error("Error updating page - " + stripAll(getBean().getId()), ex);
142142
addError("Error updating template - check Roller logs");
143143
}
144144
}

framework/codemodder-base/src/test/java/io/codemodder/remediation/loginjection/LogInjectionRemediatorTest.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ void setup() throws IOException {
3232

3333
private static Stream<Arguments> fixableSamples() {
3434
return Stream.of(
35+
Arguments.of(
36+
"""
37+
class Foo {
38+
void foo(String msg) {
39+
log.info("hi" + msg);
40+
}
41+
}
42+
""",
43+
"""
44+
import static io.github.pixee.security.Newlines.stripAll;
45+
class Foo {
46+
void foo(String msg) {
47+
log.info("hi" + stripAll(msg));
48+
}
49+
}
50+
""",
51+
3),
3552
Arguments.of(
3653
"""
3754
class Foo {
@@ -41,10 +58,10 @@ void foo(String msg) {
4158
}
4259
""",
4360
"""
44-
import static io.github.pixee.security.Newlines.stripNewLines;
61+
import static io.github.pixee.security.Newlines.stripAll;
4562
class Foo {
4663
void foo(String msg) {
47-
log.info(stripNewLines(msg));
64+
log.info(stripAll(msg));
4865
}
4966
}
5067
""",
@@ -58,11 +75,11 @@ void foo(String msg, MyException ex) {
5875
}
5976
""",
6077
"""
61-
import static io.github.pixee.security.Newlines.stripNewLines;
78+
import static io.github.pixee.security.Newlines.stripAll;
6279
6380
class Foo {
6481
void foo(String msg, MyException ex) {
65-
log.info(stripNewLines(msg), ex);
82+
log.info(stripAll(msg), ex);
6683
}
6784
}
6885
""",
@@ -77,12 +94,12 @@ void foo(String msg) {
7794
}
7895
""",
7996
"""
80-
import static io.github.pixee.security.Newlines.stripNewLines;
97+
import static io.github.pixee.security.Newlines.stripAll;
8198
8299
class Foo {
83100
void foo(String msg) {
84101
MyException ex = null;
85-
log.info(stripNewLines(msg), ex);
102+
log.info(stripAll(msg), ex);
86103
}
87104
}
88105
""",
@@ -100,14 +117,14 @@ void foo(String msg) {
100117
}
101118
""",
102119
"""
103-
import static io.github.pixee.security.Newlines.stripNewLines;
120+
import static io.github.pixee.security.Newlines.stripAll;
104121
105122
class Foo {
106123
void foo(String msg) {
107124
try {
108125
doThing();
109126
} catch(MyException e) {
110-
log.info(stripNewLines(msg), e);
127+
log.info(stripAll(msg), e);
111128
}
112129
}
113130
}
@@ -122,11 +139,11 @@ void foo(String user, MyException ex) {
122139
}
123140
""",
124141
"""
125-
import static io.github.pixee.security.Newlines.stripNewLines;
142+
import static io.github.pixee.security.Newlines.stripAll;
126143
127144
class Foo {
128145
void foo(String user, MyException ex) {
129-
log.info("hi " + stripNewLines(user), ex);
146+
log.info("hi " + stripAll(user), ex);
130147
}
131148
}
132149
""",
@@ -140,11 +157,11 @@ void foo(String user, MyException ex) {
140157
}
141158
""",
142159
"""
143-
import static io.github.pixee.security.Newlines.stripNewLines;
160+
import static io.github.pixee.security.Newlines.stripAll;
144161
145162
class Foo {
146163
void foo(String user, MyException ex) {
147-
log.info("hi " + stripNewLines(user) + " its me!", ex);
164+
log.info("hi " + stripAll(user) + " its me!", ex);
148165
}
149166
}
150167
""",
@@ -158,11 +175,11 @@ void foo(String user, MyException ex) {
158175
}
159176
""",
160177
"""
161-
import static io.github.pixee.security.Newlines.stripNewLines;
178+
import static io.github.pixee.security.Newlines.stripAll;
162179
163180
class Foo {
164181
void foo(String user, MyException ex) {
165-
log.info("hi {}", stripNewLines(user), ex);
182+
log.info("hi {}", stripAll(user), ex);
166183
}
167184
}
168185
""",

0 commit comments

Comments
 (0)