This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn on validation on customers and hmac by default now you must be explicit on turning it off by setting it to `0` or `false` started by @ivanayov Signed-off-by: Martin Dekov (VMware) <[email protected]>
- Loading branch information
1 parent
d3bb7e2
commit 4899ff2
Showing
10 changed files
with
168 additions
and
30 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
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,13 @@ | ||
package sdk | ||
|
||
import "os" | ||
|
||
// ValidateCustomers checks environmental | ||
// variable validate_customers if customer | ||
// validation is explicitly disabled | ||
func ValidateCustomers() bool { | ||
if val, exists := os.LookupEnv("validate_customers"); exists { | ||
return val != "false" && val != "0" | ||
} | ||
return true | ||
} |
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,55 @@ | ||
package sdk | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_ValidateCustomers(t *testing.T) { | ||
tests := []struct { | ||
title string | ||
value string | ||
expectedBool bool | ||
}{ | ||
{ | ||
title: "environmental variable `validate_customers` is unset", | ||
value: "", | ||
expectedBool: true, | ||
}, | ||
{ | ||
title: "environmental variable `validate_customers` is set to true", | ||
value: "true", | ||
expectedBool: true, | ||
}, | ||
{ | ||
title: "environmental variable `validate_customers` is set to 1", | ||
value: "1", | ||
expectedBool: true, | ||
}, | ||
{ | ||
title: "environmental variable `validate_customers` is set with random value", | ||
value: "random", | ||
expectedBool: true, | ||
}, | ||
{ | ||
title: "environmental variable `validate_customers` is set with explicit `0`", | ||
value: "0", | ||
expectedBool: false, | ||
}, | ||
{ | ||
title: "environmental variable `validate_customers` is set with explicit `false`", | ||
value: "false", | ||
expectedBool: false, | ||
}, | ||
} | ||
customersEnvVar := "validate_customers" | ||
for _, test := range tests { | ||
t.Run(test.title, func(t *testing.T) { | ||
os.Setenv(customersEnvVar, test.value) | ||
value := ValidateCustomers() | ||
if value != test.expectedBool { | ||
t.Errorf("Expected value: %v got: %v", test.expectedBool, value) | ||
} | ||
}) | ||
} | ||
} |
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