mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2025-02-02 02:41:38 +00:00
Support parse boolean flag with no value (#579)
* Support parse boolean flag with no value * Add test for parse boolean flag with false value Co-authored-by: Roberto Rojas <robertojrojas@gmail.com>
This commit is contained in:
parent
d988b81540
commit
0b07f40c9b
20
check/data
20
check/data
@ -308,6 +308,26 @@ groups:
|
|||||||
value: '^1\.12.*$'
|
value: '^1\.12.*$'
|
||||||
set: true
|
set: true
|
||||||
|
|
||||||
|
- id: 27
|
||||||
|
text: "check boolean flag with no value"
|
||||||
|
tests:
|
||||||
|
test_items:
|
||||||
|
- flag: "--peer-client-cert-auth"
|
||||||
|
compare:
|
||||||
|
op: eq
|
||||||
|
value: true
|
||||||
|
set: true
|
||||||
|
|
||||||
|
- id: 28
|
||||||
|
text: "check boolean flag with false value"
|
||||||
|
tests:
|
||||||
|
test_items:
|
||||||
|
- flag: "--peer-client-cert-auth"
|
||||||
|
compare:
|
||||||
|
op: eq
|
||||||
|
value: false
|
||||||
|
set: true
|
||||||
|
|
||||||
- id: 2.1
|
- id: 2.1
|
||||||
text: "audit and audit_config commands"
|
text: "audit and audit_config commands"
|
||||||
checks:
|
checks:
|
||||||
|
@ -114,9 +114,14 @@ func (t *testItem) execute(s string) *testOutput {
|
|||||||
if len(vals) > 0 {
|
if len(vals) > 0 {
|
||||||
if vals[3] != "" {
|
if vals[3] != "" {
|
||||||
flagVal = vals[3]
|
flagVal = vals[3]
|
||||||
|
} else {
|
||||||
|
// --bool-flag
|
||||||
|
if strings.HasPrefix(t.Flag, "--") {
|
||||||
|
flagVal = "true"
|
||||||
} else {
|
} else {
|
||||||
flagVal = vals[1]
|
flagVal = vals[1]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "invalid flag in testitem definition")
|
fmt.Fprintf(os.Stderr, "invalid flag in testitem definition")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -156,6 +156,30 @@ func TestTestExecute(t *testing.T) {
|
|||||||
controls.Groups[0].Checks[26],
|
controls.Groups[0].Checks[26],
|
||||||
"currentMasterVersion: 1.12.7",
|
"currentMasterVersion: 1.12.7",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
controls.Groups[0].Checks[27],
|
||||||
|
"--peer-client-cert-auth",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
controls.Groups[0].Checks[27],
|
||||||
|
"--abc=true --peer-client-cert-auth --efg=false",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
controls.Groups[0].Checks[27],
|
||||||
|
"--abc --peer-client-cert-auth --efg",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
controls.Groups[0].Checks[27],
|
||||||
|
"--peer-client-cert-auth=true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
controls.Groups[0].Checks[27],
|
||||||
|
"--abc --peer-client-cert-auth=true --efg",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
controls.Groups[0].Checks[28],
|
||||||
|
"--abc --peer-client-cert-auth=false --efg",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
Loading…
Reference in New Issue
Block a user