Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
kube-bench
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
aquasecurity
kube-bench
Commits
7600dd9d
Commit
7600dd9d
authored
7 years ago
by
Liz Rice
Browse files
Options
Downloads
Patches
Plain Diff
Make the ps / fakeps function global so we don’t have to pass it around so much
parent
0bc00e00
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/common.go
+1
-1
1 addition, 1 deletion
cmd/common.go
cmd/util.go
+11
-3
11 additions, 3 deletions
cmd/util.go
cmd/util_test.go
+6
-2
6 additions, 2 deletions
cmd/util_test.go
with
18 additions
and
6 deletions
cmd/common.go
+
1
−
1
View file @
7600dd9d
...
@@ -165,7 +165,7 @@ func verifyNodeType(t check.NodeType) {
...
@@ -165,7 +165,7 @@ func verifyNodeType(t check.NodeType) {
}
}
for
_
,
bin
:=
range
bins
{
for
_
,
bin
:=
range
bins
{
if
!
verifyBin
(
bin
,
ps
)
{
if
!
verifyBin
(
bin
)
{
printlnWarn
(
fmt
.
Sprintf
(
"%s is not running"
,
bin
))
printlnWarn
(
fmt
.
Sprintf
(
"%s is not running"
,
bin
))
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
cmd/util.go
+
11
−
3
View file @
7600dd9d
...
@@ -22,6 +22,14 @@ var (
...
@@ -22,6 +22,14 @@ var (
}
}
)
)
var
psFunc
func
(
string
)
string
var
statFunc
func
(
string
)
(
os
.
FileInfo
,
error
)
func
init
()
{
psFunc
=
ps
statFunc
=
os
.
Stat
}
func
printlnWarn
(
msg
string
)
{
func
printlnWarn
(
msg
string
)
{
fmt
.
Fprintf
(
os
.
Stderr
,
"[%s] %s
\n
"
,
fmt
.
Fprintf
(
os
.
Stderr
,
"[%s] %s
\n
"
,
colors
[
check
.
WARN
]
.
Sprintf
(
"%s"
,
check
.
WARN
),
colors
[
check
.
WARN
]
.
Sprintf
(
"%s"
,
check
.
WARN
),
...
@@ -76,7 +84,7 @@ func ps(proc string) string {
...
@@ -76,7 +84,7 @@ func ps(proc string) string {
}
}
// verifyBin checks that the binary specified is running
// verifyBin checks that the binary specified is running
func
verifyBin
(
bin
string
,
psFunc
func
(
string
)
string
)
bool
{
func
verifyBin
(
bin
string
)
bool
{
// Strip any quotes
// Strip any quotes
bin
=
strings
.
Trim
(
bin
,
"'
\"
"
)
bin
=
strings
.
Trim
(
bin
,
"'
\"
"
)
...
@@ -103,9 +111,9 @@ func verifyBin(bin string, psFunc func(string) string) bool {
...
@@ -103,9 +111,9 @@ func verifyBin(bin string, psFunc func(string) string) bool {
}
}
// findExecutable looks through a list of possible executable names and finds the first one that's running
// findExecutable looks through a list of possible executable names and finds the first one that's running
func
findExecutable
(
candidates
[]
string
,
psFunc
func
(
string
)
string
)
(
string
,
error
)
{
func
findExecutable
(
candidates
[]
string
)
(
string
,
error
)
{
for
_
,
c
:=
range
candidates
{
for
_
,
c
:=
range
candidates
{
if
verifyBin
(
c
,
psFunc
)
{
if
verifyBin
(
c
)
{
return
c
,
nil
return
c
,
nil
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
cmd/util_test.go
+
6
−
2
View file @
7600dd9d
...
@@ -97,10 +97,11 @@ func TestVerifyBin(t *testing.T) {
...
@@ -97,10 +97,11 @@ func TestVerifyBin(t *testing.T) {
{
proc
:
"cmd param"
,
psOut
:
"cmd"
,
exp
:
false
},
{
proc
:
"cmd param"
,
psOut
:
"cmd"
,
exp
:
false
},
}
}
psFunc
=
fakeps
for
id
,
c
:=
range
cases
{
for
id
,
c
:=
range
cases
{
t
.
Run
(
strconv
.
Itoa
(
id
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
strconv
.
Itoa
(
id
),
func
(
t
*
testing
.
T
)
{
g
=
c
.
psOut
g
=
c
.
psOut
v
:=
verifyBin
(
c
.
proc
,
fakeps
)
v
:=
verifyBin
(
c
.
proc
)
if
v
!=
c
.
exp
{
if
v
!=
c
.
exp
{
t
.
Fatalf
(
"Expected %v got %v"
,
c
.
exp
,
v
)
t
.
Fatalf
(
"Expected %v got %v"
,
c
.
exp
,
v
)
}
}
...
@@ -120,12 +121,15 @@ func TestFindExecutable(t *testing.T) {
...
@@ -120,12 +121,15 @@ func TestFindExecutable(t *testing.T) {
{
candidates
:
[]
string
{
"one double"
,
"two double"
,
"three double"
},
psOut
:
"two double is running"
,
exp
:
"two double"
},
{
candidates
:
[]
string
{
"one double"
,
"two double"
,
"three double"
},
psOut
:
"two double is running"
,
exp
:
"two double"
},
{
candidates
:
[]
string
{
"one"
,
"two"
,
"three"
},
psOut
:
"blah"
,
expErr
:
true
},
{
candidates
:
[]
string
{
"one"
,
"two"
,
"three"
},
psOut
:
"blah"
,
expErr
:
true
},
{
candidates
:
[]
string
{
"one double"
,
"two double"
,
"three double"
},
psOut
:
"two"
,
expErr
:
true
},
{
candidates
:
[]
string
{
"one double"
,
"two double"
,
"three double"
},
psOut
:
"two"
,
expErr
:
true
},
{
candidates
:
[]
string
{
"apiserver"
,
"kube-apiserver"
},
psOut
:
"kube-apiserver"
,
exp
:
"kube-apiserver"
},
{
candidates
:
[]
string
{
"apiserver"
,
"kube-apiserver"
,
"hyperkube-apiserver"
},
psOut
:
"kube-apiserver"
,
exp
:
"kube-apiserver"
},
}
}
psFunc
=
fakeps
for
id
,
c
:=
range
cases
{
for
id
,
c
:=
range
cases
{
t
.
Run
(
strconv
.
Itoa
(
id
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
strconv
.
Itoa
(
id
),
func
(
t
*
testing
.
T
)
{
g
=
c
.
psOut
g
=
c
.
psOut
e
,
err
:=
findExecutable
(
c
.
candidates
,
fakeps
)
e
,
err
:=
findExecutable
(
c
.
candidates
)
if
e
!=
c
.
exp
{
if
e
!=
c
.
exp
{
t
.
Fatalf
(
"Expected %v got %v"
,
c
.
exp
,
e
)
t
.
Fatalf
(
"Expected %v got %v"
,
c
.
exp
,
e
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment