-
Notifications
You must be signed in to change notification settings - Fork 10
/
basculeLogging_test.go
72 lines (62 loc) · 1.71 KB
/
basculeLogging_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2016 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/xmidt-org/sallust"
"go.uber.org/zap/zaptest"
)
func TestSanitizeHeaders(t *testing.T) {
testCases := []struct {
Description string
Input http.Header
Expected http.Header
}{
{
Description: "Filtered",
Input: http.Header{"Authorization": []string{"Basic xyz"}, "HeaderA": []string{"x"}},
Expected: http.Header{"HeaderA": []string{"x"}, "Authorization-Type": []string{"Basic"}},
},
{
Description: "Handled human error",
Input: http.Header{"Authorization": []string{"BasicXYZ"}, "HeaderB": []string{"y"}},
Expected: http.Header{"HeaderB": []string{"y"}},
},
{
Description: "Not a perfect system",
Input: http.Header{"Authorization": []string{"MySecret IWantToLeakIt"}},
Expected: http.Header{"Authorization-Type": []string{"MySecret"}},
},
}
for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
assert := assert.New(t)
actual := sanitizeHeaders(tc.Input)
assert.Equal(tc.Expected, actual)
})
}
}
func TestAddFieldToLog_NotNil(t *testing.T) {
testCases := []struct {
name string
kvs []interface{}
}{
{
name: "header",
kvs: []interface{}{"headerName", "petasos"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
testCtx, cancel := context.WithCancel(context.Background())
defer cancel()
testLogger := zaptest.NewLogger(t)
assert := assert.New(t)
ctx := addFieldsToLog(testCtx, testLogger, tc.kvs)
assert.NotNil(sallust.Get(ctx))
})
}
}