Skip to content

Commit

Permalink
fix: TestMakeSensorEnvMap should test for automatic proxy vs manual
Browse files Browse the repository at this point in the history
  • Loading branch information
redhatrises committed Feb 8, 2024
1 parent 207750b commit 6977b7e
Showing 1 changed file with 16 additions and 115 deletions.
131 changes: 16 additions & 115 deletions pkg/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,147 +87,48 @@ func TestProxyPort(t *testing.T) {
}
}

func TestGetProxyInfo(t *testing.T) {
os.Setenv("HTTPS_PROXY", "https://test:1234")
host, port := "https://test", "1234"
gotHost, gotPort := getProxyInfo()
if !reflect.DeepEqual(gotHost, host) {
t.Errorf("getProxyInfo() = host: %v, want host: %v", gotHost, host)
}
if !reflect.DeepEqual(gotPort, port) {
t.Errorf("getProxyInfo() = port: %v, want port: %v", gotPort, port)
}

os.Setenv("HTTP_PROXY", "http://user:password@test:1234")
host, port = "http://user:password@test", "1234"
gotHost, gotPort = getProxyInfo()
if !reflect.DeepEqual(gotHost, host) {
t.Errorf("getProxyInfo() = host: %v, want host: %v", gotHost, host)
}
if !reflect.DeepEqual(gotPort, port) {
t.Errorf("getProxyInfo() = port: %v, want port: %v", gotPort, port)
}

os.Unsetenv("HTTPS_PROXY")
os.Unsetenv("HTTP_PROXY")
host, port = "", ""
gotHost, gotPort = getProxyInfo()
if !reflect.DeepEqual(gotHost, host) {
t.Errorf("getProxyInfo() = host: %v, want host: %v", gotHost, host)
}
if !reflect.DeepEqual(gotPort, port) {
t.Errorf("getProxyInfo() = port: %v, want port: %v", gotPort, port)
}
}

func TestMakeSensorEnvMap(t *testing.T) {
falconNode := falconv1alpha1.FalconNodeSensor{}
falconSensor := falconNode.Spec.Falcon
sensorConfig := make(map[string]string)
proxy := NewProxyInfo()
port := 1234
pDisabled := false
cid := "test"

falconSensor.APH = "test"
falconSensor.APP = &port
falconSensor.APD = &pDisabled
falconSensor.Billing = "test"
falconSensor.CID = &cid
falconSensor.PToken = "test"
falconSensor.Tags = []string{"test"}
falconSensor.Trace = "debug"

os.Setenv("HTTPS_PROXY", "https://test.proxy:666")
os.Setenv("HTTPS_PROXY", "https://test-automatic.proxy:666")
proxy := NewProxyInfo()

// Set proxy values from environment variables if they exist
if proxy.Host() != "" {
sensorConfig["FALCONCTL_OPT_APH"] = proxy.Host()
}
if proxy.Port() != "" {
sensorConfig["FALCONCTL_OPT_APP"] = proxy.Port()
}
// Test getting proxy from environment
sensorConfig["FALCONCTL_OPT_APH"] = strings.TrimPrefix(proxy.Host(), "https://")
sensorConfig["FALCONCTL_OPT_APH"] = strings.TrimPrefix(proxy.Host(), "http://")
sensorConfig["FALCONCTL_OPT_APP"] = proxy.Port()

// Set sensor values from CRD
if falconSensor.APD != nil {
sensorConfig["FALCONCTL_OPT_APD"] = strconv.FormatBool(*falconSensor.APD)
}
if falconSensor.APH != "" {
sensorConfig["FALCONCTL_OPT_APH"] = falconSensor.APH
}
if falconSensor.APP != nil {
sensorConfig["FALCONCTL_OPT_APP"] = strconv.Itoa(*falconSensor.APP)
}
if falconSensor.Billing != "" {
sensorConfig["FALCONCTL_OPT_BILLING"] = falconSensor.Billing
}
if falconSensor.PToken != "" {
sensorConfig["FALCONCTL_OPT_PROVISIONING_TOKEN"] = falconSensor.PToken
}
if len(falconSensor.Tags) > 0 {
sensorConfig["FALCONCTL_OPT_TAGS"] = strings.Join(falconSensor.Tags, ",")
}
if falconSensor.Trace != "" {
sensorConfig["FALCONCTL_OPT_TRACE"] = falconSensor.Trace
}
sensorConfig["FALCONCTL_OPT_APD"] = strconv.FormatBool(*falconSensor.APD)
sensorConfig["FALCONCTL_OPT_BILLING"] = falconSensor.Billing
sensorConfig["FALCONCTL_OPT_PROVISIONING_TOKEN"] = falconSensor.PToken
sensorConfig["FALCONCTL_OPT_TAGS"] = strings.Join(falconSensor.Tags, ",")
sensorConfig["FALCONCTL_OPT_TRACE"] = falconSensor.Trace

if got := MakeSensorEnvMap(falconSensor); !reflect.DeepEqual(got, sensorConfig) {
t.Errorf("MakeSensorEnvMap() = %v, want %v", got, sensorConfig)
}
}

/*
func TestMakeSensorEnvMapWithAutomaticProxy(t *testing.T) {
falconNode := falconv1alpha1.FalconNodeSensor{}
falconSensor := falconNode.Spec.Falcon
sensorConfig := make(map[string]string)
pDisabled := false
cid := "test"
falconSensor.APD = &pDisabled
falconSensor.Billing = "test"
falconSensor.CID = &cid
falconSensor.PToken = "test"
falconSensor.Tags = []string{"test"}
falconSensor.Trace = "debug"
os.Setenv("HTTPS_PROXY", "https://test.proxy:666")
proxy := NewProxyInfo()
// Set proxy values from environment variables if they exist
if proxy.Host() != "" {
sensorConfig["FALCONCTL_OPT_APH"] = strings.TrimPrefix(proxy.Host(), "https://")
sensorConfig["FALCONCTL_OPT_APH"] = strings.TrimPrefix(proxy.Host(), "http://")
}
if proxy.Port() != "" {
sensorConfig["FALCONCTL_OPT_APP"] = proxy.Port()
}
// Test getting proxy when APH and APP are set manually
falconSensor.APH = "testmanually"
falconSensor.APP = &port

// Set sensor values from CRD
if falconSensor.APD != nil {
sensorConfig["FALCONCTL_OPT_APD"] = strconv.FormatBool(*falconSensor.APD)
}
if falconSensor.APH != "" {
sensorConfig["FALCONCTL_OPT_APH"] = falconSensor.APH
}
if falconSensor.APP != nil {
sensorConfig["FALCONCTL_OPT_APP"] = strconv.Itoa(*falconSensor.APP)
}
if falconSensor.Billing != "" {
sensorConfig["FALCONCTL_OPT_BILLING"] = falconSensor.Billing
}
if falconSensor.PToken != "" {
sensorConfig["FALCONCTL_OPT_PROVISIONING_TOKEN"] = falconSensor.PToken
}
if len(falconSensor.Tags) > 0 {
sensorConfig["FALCONCTL_OPT_TAGS"] = strings.Join(falconSensor.Tags, ",")
}
if falconSensor.Trace != "" {
sensorConfig["FALCONCTL_OPT_TRACE"] = falconSensor.Trace
}
sensorConfig["FALCONCTL_OPT_APH"] = falconSensor.APH
sensorConfig["FALCONCTL_OPT_APP"] = strconv.Itoa(*falconSensor.APP)

if got := MakeSensorEnvMap(falconSensor); !reflect.DeepEqual(got, sensorConfig) {
t.Errorf("MakeSensorEnvMap() = %v, want %v", got, sensorConfig)
}
}
*/

0 comments on commit 6977b7e

Please sign in to comment.