-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from wakatime/feature/proxy-env-vars
Load proxy settings from environment
- Loading branch information
Showing
4 changed files
with
81 additions
and
17 deletions.
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 |
---|---|---|
|
@@ -1846,6 +1846,22 @@ func TestLoad_API_ProxyURL_FlagTakesPrecedence(t *testing.T) { | |
assert.Equal(t, "https://john:[email protected]:8888", params.ProxyURL) | ||
} | ||
|
||
func TestLoad_API_ProxyURL_UserDefinedTakesPrecedenceOverEnvironment(t *testing.T) { | ||
v := viper.New() | ||
v.Set("key", "00000000-0000-4000-8000-000000000000") | ||
v.Set("proxy", "https://john:[email protected]:8888") | ||
|
||
err := os.Setenv("HTTPS_PROXY", "https://papa:[email protected]:9000") | ||
require.NoError(t, err) | ||
|
||
defer os.Unsetenv("HTTPS_PROXY") | ||
|
||
params, err := paramscmd.LoadAPIParams(v) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "https://john:[email protected]:8888", params.ProxyURL) | ||
} | ||
|
||
func TestLoad_API_ProxyURL_FromConfig(t *testing.T) { | ||
v := viper.New() | ||
v.Set("key", "00000000-0000-4000-8000-000000000000") | ||
|
@@ -1857,6 +1873,36 @@ func TestLoad_API_ProxyURL_FromConfig(t *testing.T) { | |
assert.Equal(t, "https://john:[email protected]:8888", params.ProxyURL) | ||
} | ||
|
||
func TestLoad_API_ProxyURL_FromEnvironment(t *testing.T) { | ||
v := viper.New() | ||
v.Set("key", "00000000-0000-4000-8000-000000000000") | ||
|
||
err := os.Setenv("HTTPS_PROXY", "https://john:[email protected]:8888") | ||
require.NoError(t, err) | ||
|
||
defer os.Unsetenv("HTTPS_PROXY") | ||
|
||
params, err := paramscmd.LoadAPIParams(v) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "https://john:[email protected]:8888", params.ProxyURL) | ||
} | ||
|
||
func TestLoad_API_ProxyURL_NoProxyFromEnvironment(t *testing.T) { | ||
v := viper.New() | ||
v.Set("key", "00000000-0000-4000-8000-000000000000") | ||
|
||
err := os.Setenv("NO_PROXY", "https://some.org,https://api.wakatime.com") | ||
require.NoError(t, err) | ||
|
||
defer os.Unsetenv("NO_PROXY") | ||
|
||
params, err := paramscmd.LoadAPIParams(v) | ||
require.NoError(t, err) | ||
|
||
assert.Empty(t, params.ProxyURL) | ||
} | ||
|
||
func TestLoad_API_ProxyURL_InvalidFormat(t *testing.T) { | ||
v := viper.New() | ||
v.Set("key", "00000000-0000-4000-8000-000000000000") | ||
|
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