Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/openshift/client/IHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public interface IHttpClient {

public void setUserAgent(String userAgent);

public String getUserAgent();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added to allow actually testing the code.


public void setVersion(String serviceVersion);

public String get(URL url) throws HttpClientException, SocketTimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

public String getUserAgent() {
return userAgent;
}

public void setVersion(String version) {
this.version = version;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ public UrlConnectionHttpClientBuilder setVersion(String version) {
}

public IHttpClient client() {
if (authKey != null && authKey.trim().length() > 0)
userAgent = "OpenShift";
return new UrlConnectionHttpClient(username, password, userAgent, sslChecks, requestMediaType,
acceptedMediaType, version, authKey, authIV);
if (authKey != null && authKey.trim().length() > 0) {
if (userAgent == null) {
userAgent = "OpenShift";
} else if (!userAgent.startsWith("OpenShift")) {
userAgent = "OpenShift-" + userAgent;
}
}
return new UrlConnectionHttpClient(username, password, userAgent,
sslChecks, requestMediaType, acceptedMediaType, version,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here sslChecks is passed in - should it not be sufficient to check that for true/false instead of always having to do the useragent checks/munging blindly ?

Copy link
Member

Choose a reason for hiding this comment

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

I basically agree on the patch. But the ssl-checks are not related to the auth-keys. The UrlConnection is verifying SSL certificates by default. The flag was meant to provide the ability to turn those checks off

authKey, authIV);
}
}
18 changes: 18 additions & 0 deletions src/test/java/com/openshift/internal/client/HttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ public void canAcceptJson() throws SocketTimeoutException, HttpClientException,
assertNotNull(response);
assertTrue(response.indexOf(ACCEPT_APPLICATION_JSON) > 0);
}

@Test
public void hasProperAgentWhenUsingKeys() {
httpClient = new UrlConnectionHttpClientBuilder()
.setUserAgent("com.needskey").setCredentials("blah", "bluh", "authkey", "authiv")
.client();

assertEquals("OpenShift-com.needskey", httpClient.getUserAgent());
}

@Test
public void hasProperAgentWhenUsingKeysAndNoAgent() {
httpClient = new UrlConnectionHttpClientBuilder()
.setCredentials("blah", "bluh", "authkey", "authiv")
.client();

assertEquals("OpenShift", httpClient.getUserAgent());
}

@Test
public void shouldEncodeParametersCorrectly() throws HttpClientException, FileNotFoundException, IOException,
Expand Down