Skip to content

Commit

Permalink
Merge pull request #190 from dpires/master
Browse files Browse the repository at this point in the history
Set webhook endpoint to random uuid based string if not set
Fix #191
  • Loading branch information
kmadel committed Mar 17, 2016
2 parents 976cd09 + de8e461 commit 585494d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;

import java.util.List;
import java.util.UUID;
import java.util.ArrayList;

import java.util.logging.Logger;
Expand Down Expand Up @@ -49,7 +50,7 @@ public WebhookEndpoint() {
public String getUrlName() {
String url = globalConfig.getSlackOutgoingWebhookURL();
if (url == null || url.equals(""))
return null;
return UUID.randomUUID().toString().replaceAll("-", "");

return "/"+url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.containsString;

Expand Down Expand Up @@ -39,6 +40,8 @@

import jenkins.plugins.slack.webhook.model.SlackTextMessage;

import jenkins.plugins.slack.webhook.WebhookEndpoint;




Expand All @@ -64,6 +67,14 @@ public void setUp() throws Exception {
data.add(new NameValuePair("trigger_word", "jenkins"));
}

@Test
public void testNotNullOutgoingWebhookUrl() throws Exception {
WebhookEndpoint endpoint = new WebhookEndpoint();
String url = endpoint.getUrlName();
assertThat(url, is(not(nullValue())));
assertThat(url.isEmpty(), is(false));
}

@Test
public void testUnconfiguredSlackURL() throws Exception {
WebResponse response = makeRequest(null);
Expand Down

0 comments on commit 585494d

Please sign in to comment.