Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error caused in the #792 scenario #807

Merged
merged 2 commits into from
Aug 11, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented Aug 11, 2021

This pull request improves the developer experience in the scenario described in #792

Category (place an x in each of the [ ])

  • bolt (Bolt for Java)
  • bolt-{sub modules} (Bolt for Java - optional modules)
  • slack-api-client (Slack API Clients)
  • slack-api-model (Slack API Data Models)
  • slack-api-*-kotlin-extension (Kotlin Extensions for Slack API Clients)
  • slack-app-backend (The primitive layer of Bolt for Java)

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to the those rules.

@seratch seratch added enhancement M-T: A feature request for new functionality project:slack-api-client project:slack-api-client labels Aug 11, 2021
@seratch seratch added this to the 1.10.0 milestone Aug 11, 2021
@@ -219,17 +219,29 @@ public UnderlyingWebSocketSession(URI serverUri, Map<String, String> httpHeaders
// FIXME: the proxy settings here may not work
SlackConfig slackConfig = smc.getSlack().getHttpClient().getConfig();
Map<String, String> proxyHeaders = slackConfig.getProxyHeaders();
if (proxyHeaders == null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the getProxyHeaders() method can return null value, we have a null check like we do in the default SocketModeClientTyrusImpl

String proxyUrl = slackConfig.getProxyUrl();
if (proxyUrl != null) {
if (smc.getLogger().isDebugEnabled()) {
smc.getLogger().debug("The SocketMode client's going to use an HTTP proxy: {}", proxyUrl);
}
ProxyUrlUtil.ProxyUrl parsedProxy = ProxyUrlUtil.parse(proxyUrl);
if (parsedProxy.getUsername() != null && parsedProxy.getPassword() != null) {
// see also: https://github.com/slackapi/java-slack-sdk/issues/792#issuecomment-895961176
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see also: #806

@@ -48,14 +48,14 @@ public static ProxyUrl parse(String proxyUrl) {
.username(userAndPassword[0])
.password(userAndPassword[1])
.host(hostAndPort[0])
.port(hostAndPort.length == 2 ? Integer.parseInt(hostAndPort[1]) : 80)
.port(hostAndPort.length == 2 ? Integer.parseInt(hostAndPort[1].replace("/", "")) : 80)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this potential issue while writing unit tests

public void proxyAuth() throws Exception {
SlackConfig config = new SlackConfig();
config.setMethodsEndpointUrlPrefix(webApiServer.getMethodsEndpointPrefix());
config.setProxyUrl("http://user:pass@localhost:9000/");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using "http://localhost:9000/" still works. Also, passing static proxyHeaders also works.

@@ -173,7 +173,7 @@ public String issueSocketModeUrl(String appToken) throws IOException {
} catch (SlackApiException e) {
String message = "Failed to connect to the Socket Mode API endpoint. (" +
"status: " + e.getResponse().code() + ", " +
"error: " + e.getError().getError() +
"error: " + (e.getError() != null ? e.getError().getError() : "") +
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.getError() cannot be null in a usual situation... but, just in case, we want to improve this part not to throw NPE (I encountered with the mock proxy sever returning 502 status)

@codecov
Copy link

codecov bot commented Aug 11, 2021

Codecov Report

Merging #807 (fc09e63) into main (2fb3e82) will increase coverage by 0.31%.
The diff coverage is 33.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #807      +/-   ##
============================================
+ Coverage     76.75%   77.06%   +0.31%     
- Complexity     3395     3401       +6     
============================================
  Files           380      380              
  Lines         10224    10229       +5     
  Branches        997     1000       +3     
============================================
+ Hits           7847     7883      +36     
+ Misses         1800     1762      -38     
- Partials        577      584       +7     
Impacted Files Coverage Δ
...-api-client/src/main/java/com/slack/api/Slack.java 73.57% <0.00%> (ø)
...ain/java/com/slack/api/util/http/ProxyUrlUtil.java 51.72% <0.00%> (+51.72%) ⬆️
...i/socket_mode/impl/SocketModeClientJavaWSImpl.java 63.81% <50.00%> (+1.91%) ⬆️
...va/com/slack/api/socket_mode/SocketModeClient.java 69.73% <0.00%> (+3.94%) ⬆️
.../java/com/slack/api/util/http/SlackHttpClient.java 86.76% <0.00%> (+6.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2fb3e82...fc09e63. Read the comment docs.

InetSocketAddress proxyAddress = new InetSocketAddress(parsedProxy.getHost(), parsedProxy.getPort());
this.setProxy(new Proxy(Proxy.Type.HTTP, proxyAddress));
ProxyUrlUtil.setProxyAuthorizationHeader(proxyHeaders, parsedProxy);
}
if (slackConfig.getProxyHeaders() != null) {
if (proxyHeaders != null && !proxyHeaders.isEmpty()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for improvement; proxyHeaders can be passed for other purposes

@seratch seratch merged commit e576c52 into slackapi:main Aug 11, 2021
@seratch seratch deleted the issue-792-unsupported-scenario branch August 11, 2021 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality project:slack-api-client project:slack-api-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant