-
Notifications
You must be signed in to change notification settings - Fork 233
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
Adding fix for and tests for no proxy support for deployer #729
Open
Enquier
wants to merge
1
commit into
jfrog:dev
Choose a base branch
from
Enquier:bugfix/gradle-no-proxy-fix2
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,24 @@ import ( | |
) | ||
|
||
const ( | ||
host = "localhost" | ||
port = "8888" | ||
proxy = "http://" + host + ":" + port | ||
host = "localhost" | ||
port = "8888" | ||
proxy = "http://" + host + ":" + port | ||
noproxy = "some.other.url.com" | ||
othernoproxy = "some.different.url.com" | ||
) | ||
|
||
func TestCreateDefaultPropertiesFile(t *testing.T) { | ||
proxyOrg := getOriginalProxyValue() | ||
noproxyOrg := getOriginalNoProxyValue() | ||
setProxy("", t) | ||
setNoProxy("", t) | ||
|
||
for index := range ProjectTypes { | ||
testCreateDefaultPropertiesFile(ProjectType(index), t) | ||
} | ||
setProxy(proxyOrg, t) | ||
setNoProxy(noproxyOrg, t) | ||
} | ||
|
||
func testCreateDefaultPropertiesFile(projectType ProjectType, t *testing.T) { | ||
|
@@ -51,9 +56,11 @@ func testCreateDefaultPropertiesFile(projectType ProjectType, t *testing.T) { | |
compareViperConfigs(t, actualConfig, expectedConfig, projectType) | ||
} | ||
|
||
func TestCreateSimplePropertiesFileWithProxy(t *testing.T) { | ||
func TestCreateSimplePropertiesFileWithProxyAndWithoutNoProxy(t *testing.T) { | ||
proxyOrg := getOriginalProxyValue() | ||
noproxyOrg := getOriginalNoProxyValue() | ||
setProxy(proxy, t) | ||
setNoProxy("", t) | ||
var propertiesFileConfig = map[string]string{ | ||
"artifactory.resolve.contextUrl": "http://some.url.com", | ||
"artifactory.publish.contextUrl": "http://some.other.url.com", | ||
|
@@ -63,21 +70,55 @@ func TestCreateSimplePropertiesFileWithProxy(t *testing.T) { | |
} | ||
createSimplePropertiesFile(t, propertiesFileConfig) | ||
setProxy(proxyOrg, t) | ||
setNoProxy(noproxyOrg, t) | ||
} | ||
|
||
func TestCreateSimplePropertiesFileWithoutProxy(t *testing.T) { | ||
func TestCreateSimplePropertiesFileWithoutProxyAndNoProxy(t *testing.T) { | ||
proxyOrg := getOriginalProxyValue() | ||
noproxyOrg := getOriginalNoProxyValue() | ||
setProxy("", t) | ||
setNoProxy("", t) | ||
var propertiesFileConfig = map[string]string{ | ||
"artifactory.resolve.contextUrl": "http://some.url.com", | ||
"artifactory.publish.contextUrl": "http://some.other.url.com", | ||
"artifactory.deploy.build.name": "buildName", | ||
} | ||
createSimplePropertiesFile(t, propertiesFileConfig) | ||
setProxy(proxyOrg, t) | ||
setNoProxy(noproxyOrg, t) | ||
|
||
} | ||
|
||
func TestCreateSimplePropertiesFileWithProxyAndNoProxy(t *testing.T) { | ||
proxyOrg := getOriginalProxyValue() | ||
noproxyOrg := getOriginalNoProxyValue() | ||
setProxy(proxy, t) | ||
setNoProxy(noproxy, t) | ||
var propertiesFileConfig = map[string]string{ | ||
"artifactory.resolve.contextUrl": "http://some.url.com", | ||
"artifactory.publish.contextUrl": "http://some.other.url.com", | ||
"artifactory.deploy.build.name": "buildName", | ||
} | ||
createSimplePropertiesFile(t, propertiesFileConfig) | ||
setProxy(proxyOrg, t) | ||
setNoProxy(noproxyOrg, t) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a test where the proxy matches the noproxy |
||
|
||
func TestCreateSimplePropertiesFileWithProxyAndDifferentNoProxy(t *testing.T) { | ||
proxyOrg := getOriginalProxyValue() | ||
noproxyOrg := getOriginalNoProxyValue() | ||
setProxy(proxy, t) | ||
setNoProxy(othernoproxy, t) | ||
var propertiesFileConfig = map[string]string{ | ||
"artifactory.resolve.contextUrl": "http://some.url.com", | ||
"artifactory.publish.contextUrl": "http://some.other.url.com", | ||
"artifactory.deploy.build.name": "buildName", | ||
} | ||
createSimplePropertiesFile(t, propertiesFileConfig) | ||
setProxy(proxyOrg, t) | ||
setNoProxy(noproxyOrg, t) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test has the proxy and the no proxy not matching and should return proxy/port |
||
func createSimplePropertiesFile(t *testing.T, propertiesFileConfig map[string]string) { | ||
var yamlConfig = map[string]string{ | ||
RESOLVER_PREFIX + URL: "http://some.url.com", | ||
|
@@ -191,9 +232,20 @@ func getOriginalProxyValue() string { | |
return os.Getenv(HttpProxy) | ||
} | ||
|
||
func getOriginalNoProxyValue() string { | ||
return os.Getenv(NoProxy) | ||
} | ||
|
||
func setProxy(proxy string, t *testing.T) { | ||
err := os.Setenv(HttpProxy, proxy) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func setNoProxy(noproxy string, t *testing.T) { | ||
err := os.Setenv(NoProxy, noproxy) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a chance I'm missing something here, but it looks like
deployProxyURL
is used only for the debug logging. My guess is that your intention was to extract the host and the post values fromdeployProxyURL
before adding them to the properties file.If this is the case, I suggest simplifying the implementation of this function and doing it once, instead of twice. In other words, we can use the
http.ProxyFromEnvironment
API regardless of whethernoProxy
is defined or not.Notice that the tests are also wrong, because when they set no_proxy, the no_proxy value is identical to the http_proxy value, and that's why no host and port are added to the properties file.
The tests should use no_proxy values with wildcards, and check that the no proxy filtering works properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this could be simplified.
DeployURLProxy is used as a logic operation to determine if the proxy should be set or not depending on the environment’s No_Proxy rules. The key element here is the introduction of the
http.ProxyFromEnvironment
API which has a robust “NoProxy” logic in that if it returns nil, nil then you should not set the proxy flag and if it returns nil, <proxy_url> then you should set the proxy flag to that URL.As you suggest I could effectively pull most of this code out (I tried to keep the flow of the original code) and replace it with http.ProxyFromEnvironment. I think it also was this way due to the fact that I originally thought that it mattered if we set it for Deploy vs Resolve but after digging in I realized that Gradle handles that part itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for the tests there are two sets of tests. One set where the No Proxy is identical and one where they differ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add tests that test the full gambit of no_proxy rules, I figured that was best left to the
http.ProxyFromEnvironment
team. Instead, I simply wanted a test that proved if the proxy was set or not depending on the variables we passed