Skip to content

Commit

Permalink
Merge pull request #435 from cqse/ts/38166_useless-proxy-warning
Browse files Browse the repository at this point in the history
don't warn about proxy port when no port is set
  • Loading branch information
DreierF committed Mar 28, 2024
2 parents bad83f1 + 824807d commit 43fa715
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ We use [semantic versioning](http://semver.org/):

# Next Release
- [feature] Docker: agent copies itself to `/transfer` if this is mounted into the container
- [fix] Disable warning about proxy port not being correct when no proxy port was set at all

# 33.1.2
- [fix] _teamscale-maven-plugin_: Revision and end commit could not be set via command line (user property)
Expand Down
Expand Up @@ -70,7 +70,8 @@ public String getProxyHost() {
}

/**
* Read the http(s).proxyPort system variable
* Read the http(s).proxyPort system variable.
* Returns -1 if no or an invalid port was set.
*/
public int getProxyPort() {
return parsePort(System.getProperty(getProxyPortSystemPropertyName()));
Expand Down Expand Up @@ -102,6 +103,14 @@ public void setProxyPort(String proxyPort) {
System.setProperty(getProxyPortSystemPropertyName(), proxyPort);
}

/**
* Removes the http(s).proxyPort system variable.
* For testing.
*/
/*package*/ void removeProxyPort() {
System.clearProperty(getProxyPortSystemPropertyName());
}

@NotNull
private String getProxyPortSystemPropertyName() {
return protocol + PROXY_PORT_SYSTEM_PROPERTY;
Expand Down Expand Up @@ -146,7 +155,12 @@ private String getProxyPasswordSystemPropertyName() {
return protocol + PROXY_PASSWORD_SYSTEM_PROPERTY;
}

/** Parses the given port string. Returns -1 if the string is null or not a valid number. */
private int parsePort(String portString) {
if (portString == null) {
return -1;
}

try {
return Integer.parseInt(portString);
} catch (NumberFormatException e) {
Expand Down
@@ -0,0 +1,28 @@
package com.teamscale.client;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

class ProxySystemPropertiesTest {

private static ProxySystemProperties properties = new ProxySystemProperties(ProxySystemProperties.Protocol.HTTP);

@AfterAll
static void teardown() {
properties.removeProxyPort();
}

@Test
void testPortParsing() {
properties.setProxyPort(9876);
Assertions.assertThat(properties.getProxyPort()).isEqualTo(9876);
properties.setProxyPort("");
Assertions.assertThat(properties.getProxyPort()).isEqualTo(-1);
properties.setProxyPort("nonsense");
Assertions.assertThat(properties.getProxyPort()).isEqualTo(-1);
properties.removeProxyPort();
Assertions.assertThat(properties.getProxyPort()).isEqualTo(-1);
}

}

0 comments on commit 43fa715

Please sign in to comment.