-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: label values not validated (#355)
Updated changelog
- Loading branch information
Showing
3 changed files
with
59 additions
and
5 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
42 changes: 42 additions & 0 deletions
42
tests/add_operator_labels/add_operator_labels_suite_test.go
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,42 @@ | ||
package add_operator_labels | ||
|
||
import ( | ||
"github.com/k8ssandra/cass-operator/pkg/oplabels" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
/** | ||
A valid label must be an empty string or consist of alphanumeric characters, | ||
'-', '_' or '.', and must start and end with an alphanumeric. | ||
*/ | ||
func TestLabelNameClean(t *testing.T) { | ||
|
||
var cleaned = oplabels.CleanLabelName("+!*(-_)cor @#$%^&rect_ LABEL.name-1=<>_?,.") | ||
require.EqualValues(t, "correct_LABEL.name-1", cleaned, | ||
"expect label name w/ outlier blacklist chars to be cleaned") | ||
|
||
cleaned = oplabels.CleanLabelName("cor!@#$%^&*()rect__ LABEL.name") | ||
require.EqualValues(t, "correct__LABEL.name", cleaned, | ||
"expect label name w/ inside blacklist chars to be cleaned") | ||
|
||
cleaned = oplabels.CleanLabelName("correct") | ||
require.EqualValues(t, "correct", cleaned, | ||
"expect label name without blacklist chars to be correct") | ||
|
||
cleaned = oplabels.CleanLabelName("") | ||
require.EqualValues(t, "", cleaned, | ||
"expect label name as empty without blacklist chars to be correct") | ||
|
||
cleaned = oplabels.CleanLabelName("-_!@#$%-^&*.()<>?._-&*.") | ||
require.EqualValues(t, "", cleaned, | ||
"expect label name as empty as contains all blacklist chars") | ||
|
||
cleaned = oplabels.CleanLabelName("-_!@#$%-^&*.()<>?._-&*.X") | ||
require.EqualValues(t, "X", cleaned, | ||
"expect label name as last char only") | ||
|
||
cleaned = oplabels.CleanLabelName("Y-_!@#$%-^&*.()<>?._-&*.") | ||
require.EqualValues(t, "Y", cleaned, | ||
"expect label name as first char only") | ||
} |