Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a5df09ba
Commit
a5df09ba
authored
Jul 10, 2017
by
Cao Shufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a regression test for Audit-ID http header
This change add a test for:
https://github.com/kubernetes/kubernetes/pull/48492
parent
07449649
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
1 deletion
+78
-1
BUILD
staging/src/k8s.io/apiserver/pkg/endpoints/filters/BUILD
+2
-0
audit_test.go
.../src/k8s.io/apiserver/pkg/endpoints/filters/audit_test.go
+76
-1
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/filters/BUILD
View file @
a5df09ba
...
@@ -21,11 +21,13 @@ go_test(
...
@@ -21,11 +21,13 @@ go_test(
library = ":go_default_library",
library = ":go_default_library",
tags = ["automanaged"],
tags = ["automanaged"],
deps = [
deps = [
"//vendor/github.com/pborman/uuid:go_default_library",
"//vendor/k8s.io/api/authentication/v1:go_default_library",
"//vendor/k8s.io/api/authentication/v1:go_default_library",
"//vendor/k8s.io/api/batch/v1:go_default_library",
"//vendor/k8s.io/api/batch/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apiserver/pkg/apis/audit:go_default_library",
"//vendor/k8s.io/apiserver/pkg/apis/audit:go_default_library",
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/filters/audit_test.go
View file @
a5df09ba
...
@@ -30,8 +30,11 @@ import (
...
@@ -30,8 +30,11 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/pborman/uuid"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
auditinternal
"k8s.io/apiserver/pkg/apis/audit"
auditinternal
"k8s.io/apiserver/pkg/apis/audit"
auditv1alpha1
"k8s.io/apiserver/pkg/apis/audit/v1alpha1"
auditv1alpha1
"k8s.io/apiserver/pkg/apis/audit/v1alpha1"
...
@@ -436,6 +439,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -436,6 +439,7 @@ func TestAuditJson(t *testing.T) {
desc
string
desc
string
path
string
path
string
verb
string
verb
string
auditID
string
handler
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
handler
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
expected
[]
auditv1alpha1
.
Event
expected
[]
auditv1alpha1
.
Event
}{
}{
...
@@ -444,6 +448,27 @@ func TestAuditJson(t *testing.T) {
...
@@ -444,6 +448,27 @@ func TestAuditJson(t *testing.T) {
"read-only empty"
,
"read-only empty"
,
shortRunningPath
,
shortRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
[]
auditv1alpha1
.
Event
{
{
Stage
:
auditinternal
.
StageRequestReceived
,
Verb
:
"get"
,
RequestURI
:
shortRunningPath
,
},
{
Stage
:
auditinternal
.
StageResponseComplete
,
Verb
:
"get"
,
RequestURI
:
shortRunningPath
,
ResponseStatus
:
&
metav1
.
Status
{
Code
:
200
},
},
},
},
{
"short running with auditID"
,
shortRunningPath
,
"GET"
,
uuid
.
NewRandom
()
.
String
(),
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
[]
auditv1alpha1
.
Event
{
[]
auditv1alpha1
.
Event
{
{
{
...
@@ -463,6 +488,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -463,6 +488,7 @@ func TestAuditJson(t *testing.T) {
"read-only panic"
,
"read-only panic"
,
shortRunningPath
,
shortRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
panic
(
"kaboom"
)
panic
(
"kaboom"
)
},
},
...
@@ -485,6 +511,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -485,6 +511,7 @@ func TestAuditJson(t *testing.T) {
"writing empty"
,
"writing empty"
,
shortRunningPath
,
shortRunningPath
,
"PUT"
,
"PUT"
,
""
,
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
[]
auditv1alpha1
.
Event
{
[]
auditv1alpha1
.
Event
{
{
{
...
@@ -504,6 +531,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -504,6 +531,7 @@ func TestAuditJson(t *testing.T) {
"writing sleep"
,
"writing sleep"
,
shortRunningPath
,
shortRunningPath
,
"PUT"
,
"PUT"
,
""
,
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
time
.
Sleep
(
delay
)
time
.
Sleep
(
delay
)
},
},
...
@@ -525,6 +553,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -525,6 +553,7 @@ func TestAuditJson(t *testing.T) {
"writing 403+write"
,
"writing 403+write"
,
shortRunningPath
,
shortRunningPath
,
"PUT"
,
"PUT"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
WriteHeader
(
403
)
w
.
WriteHeader
(
403
)
w
.
Write
([]
byte
(
"foo"
))
w
.
Write
([]
byte
(
"foo"
))
...
@@ -547,6 +576,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -547,6 +576,7 @@ func TestAuditJson(t *testing.T) {
"writing panic"
,
"writing panic"
,
shortRunningPath
,
shortRunningPath
,
"PUT"
,
"PUT"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
panic
(
"kaboom"
)
panic
(
"kaboom"
)
},
},
...
@@ -568,6 +598,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -568,6 +598,7 @@ func TestAuditJson(t *testing.T) {
"writing write+panic"
,
"writing write+panic"
,
shortRunningPath
,
shortRunningPath
,
"PUT"
,
"PUT"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
Write
([]
byte
(
"foo"
))
w
.
Write
([]
byte
(
"foo"
))
panic
(
"kaboom"
)
panic
(
"kaboom"
)
...
@@ -591,6 +622,33 @@ func TestAuditJson(t *testing.T) {
...
@@ -591,6 +622,33 @@ func TestAuditJson(t *testing.T) {
"empty longrunning"
,
"empty longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
[]
auditv1alpha1
.
Event
{
{
Stage
:
auditinternal
.
StageRequestReceived
,
Verb
:
"watch"
,
RequestURI
:
longRunningPath
,
},
{
Stage
:
auditinternal
.
StageResponseStarted
,
Verb
:
"watch"
,
RequestURI
:
longRunningPath
,
ResponseStatus
:
&
metav1
.
Status
{
Code
:
200
},
},
{
Stage
:
auditinternal
.
StageResponseComplete
,
Verb
:
"watch"
,
RequestURI
:
longRunningPath
,
ResponseStatus
:
&
metav1
.
Status
{
Code
:
200
},
},
},
},
{
"empty longrunning"
,
longRunningPath
,
"GET"
,
uuid
.
NewRandom
()
.
String
(),
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{},
[]
auditv1alpha1
.
Event
{
[]
auditv1alpha1
.
Event
{
{
{
...
@@ -616,6 +674,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -616,6 +674,7 @@ func TestAuditJson(t *testing.T) {
"sleep longrunning"
,
"sleep longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
{
time
.
Sleep
(
delay
)
time
.
Sleep
(
delay
)
},
},
...
@@ -643,6 +702,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -643,6 +702,7 @@ func TestAuditJson(t *testing.T) {
"sleep+403 longrunning"
,
"sleep+403 longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
time
.
Sleep
(
delay
)
time
.
Sleep
(
delay
)
w
.
WriteHeader
(
403
)
w
.
WriteHeader
(
403
)
...
@@ -671,6 +731,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -671,6 +731,7 @@ func TestAuditJson(t *testing.T) {
"write longrunning"
,
"write longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
Write
([]
byte
(
"foo"
))
w
.
Write
([]
byte
(
"foo"
))
},
},
...
@@ -698,6 +759,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -698,6 +759,7 @@ func TestAuditJson(t *testing.T) {
"403+write longrunning"
,
"403+write longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
WriteHeader
(
403
)
w
.
WriteHeader
(
403
)
w
.
Write
([]
byte
(
"foo"
))
w
.
Write
([]
byte
(
"foo"
))
...
@@ -726,6 +788,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -726,6 +788,7 @@ func TestAuditJson(t *testing.T) {
"panic longrunning"
,
"panic longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
panic
(
"kaboom"
)
panic
(
"kaboom"
)
},
},
...
@@ -747,6 +810,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -747,6 +810,7 @@ func TestAuditJson(t *testing.T) {
"write+panic longrunning"
,
"write+panic longrunning"
,
longRunningPath
,
longRunningPath
,
"GET"
,
"GET"
,
""
,
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
Write
([]
byte
(
"foo"
))
w
.
Write
([]
byte
(
"foo"
))
panic
(
"kaboom"
)
panic
(
"kaboom"
)
...
@@ -783,6 +847,9 @@ func TestAuditJson(t *testing.T) {
...
@@ -783,6 +847,9 @@ func TestAuditJson(t *testing.T) {
})
})
req
,
_
:=
http
.
NewRequest
(
test
.
verb
,
test
.
path
,
nil
)
req
,
_
:=
http
.
NewRequest
(
test
.
verb
,
test
.
path
,
nil
)
if
test
.
auditID
!=
""
{
req
.
Header
.
Add
(
"Audit-ID"
,
test
.
auditID
)
}
req
.
RemoteAddr
=
"127.0.0.1"
req
.
RemoteAddr
=
"127.0.0.1"
func
()
{
func
()
{
...
@@ -799,7 +866,7 @@ func TestAuditJson(t *testing.T) {
...
@@ -799,7 +866,7 @@ func TestAuditJson(t *testing.T) {
t
.
Errorf
(
"[%s] Unexpected amount of lines in audit log: %d"
,
test
.
desc
,
len
(
line
))
t
.
Errorf
(
"[%s] Unexpected amount of lines in audit log: %d"
,
test
.
desc
,
len
(
line
))
continue
continue
}
}
expectedID
:=
types
.
UID
(
""
)
for
i
,
expect
:=
range
test
.
expected
{
for
i
,
expect
:=
range
test
.
expected
{
// decode events back to check json elements.
// decode events back to check json elements.
event
:=
&
auditv1alpha1
.
Event
{}
event
:=
&
auditv1alpha1
.
Event
{}
...
@@ -820,6 +887,14 @@ func TestAuditJson(t *testing.T) {
...
@@ -820,6 +887,14 @@ func TestAuditJson(t *testing.T) {
if
event
.
RequestURI
!=
expect
.
RequestURI
{
if
event
.
RequestURI
!=
expect
.
RequestURI
{
t
.
Errorf
(
"[%s] Unexpected RequestURI: %s"
,
test
.
desc
,
event
.
RequestURI
)
t
.
Errorf
(
"[%s] Unexpected RequestURI: %s"
,
test
.
desc
,
event
.
RequestURI
)
}
}
if
test
.
auditID
!=
""
&&
event
.
AuditID
!=
types
.
UID
(
test
.
auditID
)
{
t
.
Errorf
(
"[%s] Unexpected AuditID in audit event, AuditID should be the same with Audit-ID http header"
,
test
.
desc
)
}
if
expectedID
==
types
.
UID
(
""
)
{
expectedID
=
event
.
AuditID
}
else
if
expectedID
!=
event
.
AuditID
{
t
.
Errorf
(
"[%s] Audits for one request should share the same AuditID, %s differs from %s"
,
test
.
desc
,
expectedID
,
event
.
AuditID
)
}
if
(
event
.
ResponseStatus
==
nil
)
!=
(
expect
.
ResponseStatus
==
nil
)
{
if
(
event
.
ResponseStatus
==
nil
)
!=
(
expect
.
ResponseStatus
==
nil
)
{
t
.
Errorf
(
"[%s] Unexpected ResponseStatus: %v"
,
test
.
desc
,
event
.
ResponseStatus
)
t
.
Errorf
(
"[%s] Unexpected ResponseStatus: %v"
,
test
.
desc
,
event
.
ResponseStatus
)
continue
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment