Skip to content

Commit

Permalink
[sc-249267] Break out testing log output into separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheenacarswell committed Jul 11, 2024
1 parent 5ac68f5 commit de9d2e0
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions internal/httpconfig/httpconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,42 +116,44 @@ func TestNTLMProxyInvalidConfigs(t *testing.T) {

proxyConfig2 := proxyConfig1
proxyConfig2.URL, _ = configtypes.NewOptURLAbsoluteFromString("http://fake-proxy")
mockLog2 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig2, nil, "", mockLog2.Loggers)
_, err = NewHTTPConfig(proxyConfig2, nil, "", ldlog.NewDisabledLoggers())
assert.Equal(t, errNTLMProxyAuthWithoutCredentials, err)
mockLog2.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://fake-proxy$")

proxyConfig3 := proxyConfig2
proxyConfig3.User = "user"
mockLog3 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig3, nil, "", mockLog3.Loggers)
_, err = NewHTTPConfig(proxyConfig3, nil, "", ldlog.NewDisabledLoggers())
assert.Equal(t, errNTLMProxyAuthWithoutCredentials, err)
mockLog3.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://fake-proxy$")

proxyConfig4 := proxyConfig3
proxyConfig4.Password = "pass"
mockLog4 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig4, nil, "", mockLog4.Loggers)
_, err = NewHTTPConfig(proxyConfig4, nil, "", ldlog.NewDisabledLoggers())
assert.NoError(t, err)
mockLog4.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://fake-proxy$")

proxyConfig5 := proxyConfig4
helpers.WithTempFile(func(certFileName string) {
proxyConfig5.CACertFiles = configtypes.NewOptStringList([]string{certFileName})
mockLog5 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig5, nil, "", mockLog5.Loggers)
_, err = NewHTTPConfig(proxyConfig5, nil, "", ldlog.NewDisabledLoggers())
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "invalid CA certificate data")
}
mockLog5.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://fake-proxy$")
})
}

proxyConfig6 := proxyConfig4
url6, _ := url.Parse("http://my-user:my-password@my-proxy")
proxyConfig6.URL, _ = configtypes.NewOptURLAbsolute(url6)
mockLog6 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig6, nil, "", mockLog6.Loggers)
func TestLogsRedactConnectionPassword(t *testing.T) {
// Username and password are specified separately in NTLM auth won't show in logs as they're not part of server name
url1, _ := configtypes.NewOptURLAbsoluteFromString("http://my-proxy")
proxyConfig1 := config.ProxyConfig{NTLMAuth: true, URL: url1, User: "my-user", Password: "my-pass"}
mockLog1 := ldlogtest.NewMockLog()
_, err := NewHTTPConfig(proxyConfig1, nil, "", mockLog1.Loggers)
assert.NoError(t, err)
mockLog6.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://my-user:xxxxx@my-proxy$")
mockLog1.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://my-proxy$")

// When username and password are configured as part of server name, verify the password is redacted
url2, _ := url.Parse("http://my-user:my-password@my-proxy")
url2Absolute, _ := configtypes.NewOptURLAbsolute(url2)
proxyConfig2 := config.ProxyConfig{URL: url2Absolute}
mockLog2 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig2, nil, "", mockLog2.Loggers)
assert.NoError(t, err)
mockLog2.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://my-user:xxxxx@my-proxy$")
}

0 comments on commit de9d2e0

Please sign in to comment.