// Copyright 2026 Alibaba Group // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package logging import "testing" func TestIsSensitiveKey(t *testing.T) { t.Parallel() tests := []struct { key string want bool }{ {"Authorization", true}, {"authorization", true}, {"x-user-access-token", true}, {"X-User-Access-Token", true}, {"client_secret", true}, {"client-secret", true}, {"token", true}, {"password", true}, {"cookie", true}, {"Content-Type", false}, {"X-Cli-Source", false}, {"method", false}, {"", false}, } for _, tt := range tests { t.Run(tt.key, func(t *testing.T) { t.Parallel() if got := IsSensitiveKey(tt.key); got != tt.want { t.Errorf("IsSensitiveKey(%q) = %v, want %v", tt.key, got, tt.want) } }) } } func TestRedactValue(t *testing.T) { t.Parallel() tests := []struct { input string want string }{ {"short", "***"}, {"12345678", "***"}, {"123456789", "1234***"}, {"a-very-long-token-value", "a-ve***"}, } for _, tt := range tests { t.Run(tt.input, func(t *testing.T) { t.Parallel() if got := RedactValue(tt.input); got != tt.want { t.Errorf("RedactValue(%q) = %q, want %q", tt.input, got, tt.want) } }) } }