Skip to content

Commit

Permalink
fix: concatenation of url (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Nov 24, 2020
1 parent e76f23f commit 2cb5b11
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Bug Fixes
1. [#173](https://github.com/influxdata/influxdb-client-java/pull/173): Query error could be after _success_ table
1. [#176](https://github.com/influxdata/influxdb-client-java/pull/176): Blocking API batches Point by precision
1. [#180](https://github.com/influxdata/influxdb-client-java/pull/180): Fixed concatenation of url

## 1.13.0 [2020-10-30]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import okhttp3.Call;
import okhttp3.Cookie;
import okhttp3.Credentials;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -117,7 +118,7 @@ void initToken(@Nonnull final OkHttpClient okHttpClient) {
.basic(influxDBClientOptions.getUsername(), string(influxDBClientOptions.getPassword()));

Request authRequest = new Request.Builder()
.url(influxDBClientOptions.getUrl() + "/api/v2/signin")
.url(buildPath("api/v2/signin"))
.addHeader("Authorization", credentials)
.post(RequestBody.create(null, ""))
.build();
Expand Down Expand Up @@ -155,14 +156,27 @@ void signout() throws IOException {
this.sessionToken = null;

Request authRequest = new Request.Builder()
.url(influxDBClientOptions.getUrl() + "/api/v2/signout")
.url(buildPath("api/v2/signout"))
.post(RequestBody.create(null, ""))
.build();

Response response = this.okHttpClient.newCall(authRequest).execute();
response.close();
}

@Nonnull
String buildPath(final String buildPath) {

Arguments.checkNotNull(buildPath, "buildPath");

return HttpUrl
.parse(influxDBClientOptions.getUrl())
.newBuilder()
.addEncodedPathSegments(buildPath)
.build()
.toString();
}

@Nonnull
private String string(final char[] password) {
return String.valueOf(password);
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/com/influxdb/client/write/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Point addField(@Nonnull final String field, @Nullable final Number value)
}

/**
* Add {@link Boolean} field.
* Add {@link String} field.
*
* @param field the field name
* @param value the field value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @author Jakub Bednar (bednar@github) (25/03/2019 09:52)
*/
@RunWith(JUnitPlatform.class)
@Disabled("https://github.com/influxdata/influxdb/issues/20163")
class ITTemplatesApi extends AbstractITClientTest {

private TemplatesApi templatesApi;
Expand Down
3 changes: 0 additions & 3 deletions client/src/test/java/com/influxdb/client/QueryApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package com.influxdb.client;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import com.influxdb.client.domain.Dialect;
import com.influxdb.client.domain.Query;
Expand Down Expand Up @@ -405,7 +404,5 @@ void parametersFromOptions() throws InterruptedException, IOException {
request = takeRequest();

Assertions.assertThat(request.getRequestUrl().queryParameter("org")).isEqualTo("123456");


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,93 @@ void authorizationSession() throws IOException, InterruptedException {
.isEqualTo("session=yCgXaEBF8mYSmJUweRcW0g_5jElMs7mv6_-G1bNcau4Z0ZLQYtj0BkHZYRnBVA6uXHtyuhflcOzyNDNRxnaC0A==");
}

@Test
public void buildPath() {

InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.url("http://localhost:8086")
.authenticate("user", "secret".toCharArray())
.build();

Assertions
.assertThat("http://localhost:8086/api/v2/signin")
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));

options = InfluxDBClientOptions.builder()
.url("http://localhost:8086/")
.authenticate("user", "secret".toCharArray())
.build();

Assertions
.assertThat("http://localhost:8086/api/v2/signin")
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));

options = InfluxDBClientOptions.builder()
.url("http://localhost:8086/proxy")
.authenticate("user", "secret".toCharArray())
.build();

Assertions
.assertThat("http://localhost:8086/proxy/api/v2/signin")
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));

options = InfluxDBClientOptions.builder()
.url("http://localhost:8086/proxy/")
.authenticate("user", "secret".toCharArray())
.build();

Assertions
.assertThat("http://localhost:8086/proxy/api/v2/signin")
.isEqualTo(new AuthenticateInterceptor(options).buildPath("api/v2/signin"));
}

@Test
void connectionStringSigInSignOutURL() {

InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.connectionString("http://localhost:8086?writeTimeout=1000&connectTimeout=1000&logLevel=BODY")
.authenticate("user", "secret".toCharArray())
.build();

AuthenticateInterceptor interceptor = new AuthenticateInterceptor(options);

Assertions
.assertThat("http://localhost:8086/api/v2/signin")
.isEqualTo(interceptor.buildPath("api/v2/signin"));

Assertions
.assertThat("http://localhost:8086/api/v2/signout")
.isEqualTo(interceptor.buildPath("api/v2/signout"));

Assertions
.assertThat("http://localhost:8086/api/v2/setup")
.isEqualTo(interceptor.buildPath("api/v2/setup"));
}


@Test
void connectionStringSigInSignOutURLProxy() {

InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.connectionString("http://localhost:8086/proxy?writeTimeout=1000&connectTimeout=1000&logLevel=BODY")
.authenticate("user", "secret".toCharArray())
.build();

AuthenticateInterceptor interceptor = new AuthenticateInterceptor(options);

Assertions
.assertThat("http://localhost:8086/proxy/api/v2/signin")
.isEqualTo(interceptor.buildPath("api/v2/signin"));

Assertions
.assertThat("http://localhost:8086/proxy/api/v2/signout")
.isEqualTo(interceptor.buildPath("api/v2/signout"));

Assertions
.assertThat("http://localhost:8086/proxy/api/v2/setup")
.isEqualTo(interceptor.buildPath("api/v2/setup"));
}

@Test
void authorizationSessionWithoutCookie() throws IOException, InterruptedException {

Expand Down

0 comments on commit 2cb5b11

Please sign in to comment.