mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-20 14:11:11 +02:00
This field might contain sensitive information, so better to hide it in the logs. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package log_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
metadata "google.golang.org/grpc/metadata"
|
|
|
|
"github.com/talos-systems/talos/pkg/grpc/middleware/log"
|
|
)
|
|
|
|
func TestExtractMetadata(t *testing.T) {
|
|
for _, test := range []struct {
|
|
name string
|
|
md metadata.MD
|
|
expected string
|
|
}{
|
|
{
|
|
name: "empty",
|
|
md: metadata.MD{},
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "regular",
|
|
md: metadata.Pairs("foo", "bar", "one", "two", "a", "b"),
|
|
expected: "a=b;foo=bar;one=two",
|
|
},
|
|
{
|
|
name: "sensitive",
|
|
md: metadata.Pairs("foo", "bar", "token", "secret"),
|
|
expected: "foo=bar;token=<hidden>",
|
|
},
|
|
} {
|
|
ctx := context.Background()
|
|
ctx = metadata.NewIncomingContext(ctx, test.md)
|
|
|
|
assert.Equal(t, test.expected, log.ExtractMetadata(ctx), test.name)
|
|
}
|
|
}
|