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

don't warn about proxy port when no port is set #435

Merged
merged 1 commit into from Mar 28, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}

}