Skip to content

Commit 1aa9f57

Browse files
committed
BugFix prevent exception exposing internal logic/data
1 parent 5ee16c4 commit 1aa9f57

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,22 @@ private static String encode(String data, String key) throws Exception {
9797
* @throws IOException problem while parsing
9898
*/
9999
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException {
100+
100101
GogsResults result = new GogsResults();
102+
103+
try {
104+
internalDoIndex(result, req, rsp);
105+
106+
} catch (final RuntimeException re) {
107+
LOGGER.severe(re.toString());
108+
result.setStatus(500, "GogsWebHook execution error.");
109+
exitWebHook(result, rsp);
110+
return;
111+
}
112+
}
113+
114+
void internalDoIndex(GogsResults result, StaplerRequest req, StaplerResponse rsp) throws IOException {
115+
101116
GogsPayloadProcessor payloadProcessor = new GogsPayloadProcessor();
102117

103118
//Check that we have something to process

src/test/java/org/jenkinsci/plugins/gogs/GogsWebHookTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void callDoIndexWithNullReqMessageMustThrowException() throws IOException
5050
GogsWebHook gogsWebHook = new GogsWebHook();
5151
StaplerResponse staplerResponse = Mockito.mock(ResponseImpl.class);
5252
try {
53-
gogsWebHook.doIndex(null, staplerResponse);
53+
gogsWebHook.internalDoIndex(new GogsResults(),null, staplerResponse);
5454
} catch (NullPointerException e) {
5555
String expectedErrMsg = "Null request submitted to doIndex method";
5656
assertEquals("Not the expected error message.", expectedErrMsg, e.getMessage());
@@ -65,7 +65,7 @@ public void callDoIndexWithNullResponseMessageMustThrowException() throws IOExce
6565
GogsWebHook gogsWebHook = new GogsWebHook();
6666
StaplerRequest staplerRequest = Mockito.mock(RequestImpl.class);
6767
try {
68-
gogsWebHook.doIndex(staplerRequest, null);
68+
gogsWebHook.internalDoIndex(new GogsResults(), staplerRequest, null);
6969
} catch (NullPointerException e) {
7070
String expectedErrMsg = "Null reply submitted to doIndex method";
7171
assertEquals("Not the expected error message.", expectedErrMsg, e.getMessage());
@@ -128,7 +128,7 @@ public void whenQueryStringIsNullMustThrowException() throws Exception {
128128

129129

130130
try {
131-
gogsWebHook.doIndex(staplerRequest, staplerResponse);
131+
gogsWebHook.internalDoIndex(new GogsResults(), staplerRequest, staplerResponse);
132132
} catch (NullPointerException e) {
133133
String expectedErrMsg = "The queryString in the request is null";
134134
assertEquals("Not the expected error message.", expectedErrMsg, e.getMessage());

0 commit comments

Comments
 (0)