Skip to content

Commit

Permalink
Fix #1122 A request toward an invalid webhook URL get 200 OK response…
Browse files Browse the repository at this point in the history
… (expected: 302 redirection) (#1123)
  • Loading branch information
seratch authored Feb 27, 2023
1 parent 1f94362 commit 4a15721
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public static OkHttpClient buildOkHttpClient(SlackConfig config) {

public static OkHttpClient buildOkHttpClient(SlackConfig config, Map<String, String> userAgentCustomInfo) {
final OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();

// For context, this change was applied to resolves https://github.com/slackapi/java-slack-sdk/issues/1122
// There is no use case to follow redirects as of Feb 2023.
// If this SDK needs to enable developers to customize these options,
// we may want to add overloaded buildOkHttpClient() method or add such an option to the SlackConfig object.
okHttpClient.followRedirects(false);
okHttpClient.followSslRedirects(false);

okHttpClient.addInterceptor(new UserAgentInterceptor(userAgentCustomInfo));
if (config.getHttpClientReadTimeoutMillis() != null) {
okHttpClient.readTimeout(config.getHttpClientReadTimeoutMillis(), TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,11 @@ public void headers() throws IOException {
assertThat(response.getCode(), is(200));
assertThat(response.getHeaders().size(),is(greaterThan(0)));
}

@Test
public void issue_1122_invalid_url() throws Exception {
String invalidUrl = "https://hooks.slack.com/services/invalid-url";
WebhookResponse response = slack.send(invalidUrl, Payload.builder().text("Hello world!").build());
assertThat(response.getCode(), is(302));
}
}

0 comments on commit 4a15721

Please sign in to comment.