2023-09-15 14:58:45 +00:00
|
|
|
package record
|
2023-02-15 03:21:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRecord_Normalize(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2023-09-15 14:58:45 +00:00
|
|
|
record AccessLog
|
|
|
|
want *AccessLog
|
2023-02-15 03:21:58 +00:00
|
|
|
}{{
|
|
|
|
name: "headers with certain keys should be redacted",
|
2023-09-15 14:58:45 +00:00
|
|
|
record: AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestHeaders: map[string][]string{
|
|
|
|
"authorization": {"AValue"},
|
|
|
|
"grpcgateway-authorization": {"AValue"},
|
|
|
|
"cookie": {"AValue"},
|
|
|
|
"grpcgateway-cookie": {"AValue"},
|
|
|
|
}, ResponseHeaders: map[string][]string{
|
|
|
|
"set-cookie": {"AValue"},
|
|
|
|
},
|
|
|
|
},
|
2023-09-15 14:58:45 +00:00
|
|
|
want: &AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestHeaders: map[string][]string{
|
|
|
|
"authorization": {"[REDACTED]"},
|
|
|
|
"grpcgateway-authorization": {"[REDACTED]"},
|
|
|
|
"cookie": {"[REDACTED]"},
|
|
|
|
"grpcgateway-cookie": {"[REDACTED]"},
|
|
|
|
}, ResponseHeaders: map[string][]string{
|
|
|
|
"set-cookie": {"[REDACTED]"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "header keys should be lower cased",
|
2023-09-15 14:58:45 +00:00
|
|
|
record: AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestHeaders: map[string][]string{"AKey": {"AValue"}},
|
|
|
|
ResponseHeaders: map[string][]string{"AKey": {"AValue"}}},
|
2023-09-15 14:58:45 +00:00
|
|
|
want: &AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestHeaders: map[string][]string{"akey": {"AValue"}},
|
|
|
|
ResponseHeaders: map[string][]string{"akey": {"AValue"}}},
|
|
|
|
}, {
|
|
|
|
name: "an already prune record should stay unchanged",
|
2023-09-15 14:58:45 +00:00
|
|
|
record: AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestURL: "https://my.zitadel.cloud/",
|
|
|
|
RequestHeaders: map[string][]string{
|
|
|
|
"authorization": {"[REDACTED]"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: map[string][]string{},
|
|
|
|
},
|
2023-09-15 14:58:45 +00:00
|
|
|
want: &AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestURL: "https://my.zitadel.cloud/",
|
|
|
|
RequestHeaders: map[string][]string{
|
|
|
|
"authorization": {"[REDACTED]"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: map[string][]string{},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
name: "empty record should stay empty",
|
2023-09-15 14:58:45 +00:00
|
|
|
record: AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestHeaders: map[string][]string{},
|
|
|
|
ResponseHeaders: map[string][]string{},
|
|
|
|
},
|
2023-09-15 14:58:45 +00:00
|
|
|
want: &AccessLog{
|
2023-02-15 03:21:58 +00:00
|
|
|
RequestHeaders: map[string][]string{},
|
|
|
|
ResponseHeaders: map[string][]string{},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-09-15 14:58:45 +00:00
|
|
|
tt.want.normalized = true
|
2023-02-15 03:21:58 +00:00
|
|
|
if got := tt.record.Normalize(); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("Normalize() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|