Skip to content

Commit

Permalink
Check that an SNS message is surrounded by double quotes before strip…
Browse files Browse the repository at this point in the history
…ping them

Fix for [JENKINS-19337]

Stripping the double quotes is now captured in an if/else clause.

Note that I was unable to duplicate creating a double-quote-surrounded message in SNS.
Also I tried to write a test case that passed in a message surrounded by double quotes
(as the plug-in was originally coded) but this causes an earlier line of code in the
extractJsonFromPayload function to error.
So I'm not really sure how it ever worked.
  • Loading branch information
Jesse Zoldak committed Nov 18, 2015
1 parent 2f650b2 commit 6b38220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -77,7 +77,10 @@ private JSONObject extractJsonFromPayload(String payload) {
if(json.has("Type")) {
String msg = json.getString("Message");
if(msg != null) {
msg = msg.substring(1,msg.length()-1); //remove the leading and trailing double quotes
char ch[] = msg.toCharArray();
if((ch[0] == '"') && (ch[msg.length()-1]) == '"') {
msg = msg.substring(1,msg.length()-1); //remove the leading and trailing double quotes
}
return JSONObject.fromObject(msg);
}
} else if (json.has("repository")){
Expand Down
Expand Up @@ -75,4 +75,12 @@ public void shouldNotTriggerWithBadPayload() throws Exception {
gtp.processGitHubPayload(payload, sbt.getClass());
verify(sbt, never()).onPost();
}

@Test
public void shouldTriggerUnquotedSnsMsg() throws Exception {
payload = "{\"Type\" : \"Notification\", \"Message\" : \"{'repository': {'owner': {'name': 'foo'}, 'url': 'https://github.com/foo/bar', 'name': 'bar'}}\", }";
GitHubTriggerProcessor gtp = new GitHubTriggerProcessor();
gtp.processGitHubPayload(payload, sbt.getClass());
verify(sbt).onPost();
}
}

0 comments on commit 6b38220

Please sign in to comment.