-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
appsec: allow enabling sca from configuration (#2634)
- Loading branch information
1 parent
192fb73
commit 055b896
Showing
8 changed files
with
187 additions
and
25 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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016 Datadog, Inc. | ||
|
||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry/telemetrytest" | ||
) | ||
|
||
func TestSCAEnabled(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
envVarVal string | ||
telemetryExpected bool | ||
expectedValue bool | ||
}{ | ||
{ | ||
name: "true", | ||
envVarVal: "true", | ||
telemetryExpected: true, | ||
expectedValue: true, | ||
}, | ||
{ | ||
name: "false", | ||
envVarVal: "false", | ||
telemetryExpected: true, | ||
expectedValue: false, | ||
}, | ||
{ | ||
name: "undefined", | ||
envVarVal: "", // special case for undefined | ||
telemetryExpected: false, | ||
expectedValue: false, | ||
}, | ||
{ | ||
name: "parsing error", | ||
envVarVal: "not a boolean string representation [at {all!}]", | ||
telemetryExpected: false, | ||
expectedValue: false, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if tc.envVarVal != "" { | ||
t.Setenv(EnvSCAEnabled, tc.envVarVal) | ||
} | ||
|
||
telemetryClient := new(telemetrytest.MockClient) | ||
telemetryClient.On("RegisterAppConfig", EnvSCAEnabled, tc.expectedValue, "env_var").Return() | ||
|
||
registerSCAAppConfigTelemetry(telemetryClient) | ||
|
||
if tc.telemetryExpected { | ||
telemetryClient.AssertCalled(t, "RegisterAppConfig", EnvSCAEnabled, tc.expectedValue, "env_var") | ||
telemetryClient.AssertNumberOfCalls(t, "RegisterAppConfig", 1) | ||
} else { | ||
telemetryClient.AssertNumberOfCalls(t, "RegisterAppConfig", 0) | ||
} | ||
}) | ||
} | ||
} |
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
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
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