Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
85d08ded
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
85d08ded
编写于
6月 17, 2020
作者:
K
KubeSphere CI Bot
提交者:
GitHub
6月 17, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2216 from wanjunlei/auditing
fix the bug "Cannot read property 'get' of undefined"
上级
692271bb
0933e2f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
7 deletion
+43
-7
pkg/apiserver/auditing/types.go
pkg/apiserver/auditing/types.go
+15
-6
pkg/apiserver/auditing/types_test.go
pkg/apiserver/auditing/types_test.go
+28
-1
未找到文件。
pkg/apiserver/auditing/types.go
浏览文件 @
85d08ded
package
auditing
import
(
"bufio"
"bytes"
"encoding/json"
"fmt"
"github.com/google/uuid"
"io/ioutil"
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
...
@@ -14,6 +16,7 @@ import (
"kubesphere.io/kubesphere/pkg/apiserver/request"
"kubesphere.io/kubesphere/pkg/client/listers/auditing/v1alpha1"
"kubesphere.io/kubesphere/pkg/utils/iputil"
"net"
"net/http"
"time"
)
...
...
@@ -186,7 +189,6 @@ type ResponseCapture struct {
wroteHeader
bool
status
int
body
*
bytes
.
Buffer
StopCh
chan
interface
{}
}
func
NewResponseCapture
(
w
http
.
ResponseWriter
)
*
ResponseCapture
{
...
...
@@ -194,7 +196,6 @@ func NewResponseCapture(w http.ResponseWriter) *ResponseCapture {
ResponseWriter
:
w
,
wroteHeader
:
false
,
body
:
new
(
bytes
.
Buffer
),
StopCh
:
make
(
chan
interface
{},
1
),
}
}
...
...
@@ -204,10 +205,6 @@ func (c *ResponseCapture) Header() http.Header {
func
(
c
*
ResponseCapture
)
Write
(
data
[]
byte
)
(
int
,
error
)
{
defer
func
()
{
c
.
StopCh
<-
struct
{}{}
}()
c
.
WriteHeader
(
http
.
StatusOK
)
c
.
body
.
Write
(
data
)
return
c
.
ResponseWriter
.
Write
(
data
)
...
...
@@ -216,6 +213,7 @@ func (c *ResponseCapture) Write(data []byte) (int, error) {
func
(
c
*
ResponseCapture
)
WriteHeader
(
statusCode
int
)
{
if
!
c
.
wroteHeader
{
c
.
status
=
statusCode
c
.
ResponseWriter
.
WriteHeader
(
statusCode
)
c
.
wroteHeader
=
true
}
}
...
...
@@ -227,3 +225,14 @@ func (c *ResponseCapture) Bytes() []byte {
func
(
c
*
ResponseCapture
)
StatusCode
()
int
{
return
c
.
status
}
// Hijack implements the http.Hijacker interface. This expands
// the Response to fulfill http.Hijacker if the underlying
// http.ResponseWriter supports it.
func
(
c
*
ResponseCapture
)
Hijack
()
(
net
.
Conn
,
*
bufio
.
ReadWriter
,
error
)
{
hijacker
,
ok
:=
c
.
ResponseWriter
.
(
http
.
Hijacker
)
if
!
ok
{
return
nil
,
nil
,
fmt
.
Errorf
(
"ResponseWriter doesn't support Hijacker interface"
)
}
return
hijacker
.
Hijack
()
}
pkg/apiserver/auditing/types_test.go
浏览文件 @
85d08ded
...
...
@@ -16,6 +16,7 @@ import (
ksinformers
"kubesphere.io/kubesphere/pkg/client/informers/externalversions"
"kubesphere.io/kubesphere/pkg/utils/iputil"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
...
...
@@ -248,7 +249,7 @@ func TestAuditing_LogResponseObject(t *testing.T) {
e
:=
a
.
LogRequestObject
(
req
,
info
)
resp
:=
&
ResponseCapture
{}
resp
:=
NewResponseCapture
(
httptest
.
NewRecorder
())
resp
.
WriteHeader
(
200
)
a
.
LogResponseObject
(
e
,
resp
,
info
)
...
...
@@ -295,3 +296,29 @@ func TestAuditing_LogResponseObject(t *testing.T) {
assert
.
EqualValues
(
t
,
string
(
expectedBs
),
string
(
bs
))
}
func
TestResponseCapture_WriteHeader
(
t
*
testing
.
T
)
{
record
:=
httptest
.
NewRecorder
()
resp
:=
NewResponseCapture
(
record
)
resp
.
WriteHeader
(
404
)
assert
.
EqualValues
(
t
,
404
,
resp
.
StatusCode
())
assert
.
EqualValues
(
t
,
404
,
record
.
Code
)
}
func
TestResponseCapture_Write
(
t
*
testing
.
T
)
{
record
:=
httptest
.
NewRecorder
()
resp
:=
NewResponseCapture
(
record
)
body
:=
[]
byte
(
"123"
)
_
,
err
:=
resp
.
Write
(
body
)
if
err
!=
nil
{
panic
(
err
)
}
assert
.
EqualValues
(
t
,
body
,
resp
.
Bytes
())
assert
.
EqualValues
(
t
,
body
,
record
.
Body
.
Bytes
())
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录