Atlas › Test

TestMaskYaml

Exact test identity: go.temporal.io/server/common/masker/TestMaskYaml

Package
go.temporal.io/server/common/masker
Suite / test hierarchy
TestMaskYaml
Test
TestMaskYaml
Introduced at
masker.go ×6 Frontier kind: Joint frontier
Covered ranges
6
Covered lines
21
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/masker/masker.go 21 covered LOC · 6 ranges

Open complete file

16 // MaskYaml replace password values with mask and returns copy of the string.
17 // Does recursive replacement for entire yamlStr.
18 > func MaskYaml(yamlStr string, fieldNamesToMask []string) (string, error) { masker.go
19 > fns := make(map[string]struct{}, len(fieldNamesToMask))
20 > for _, fieldName := range fieldNamesToMask {
21 > fns[fieldName] = struct{}{}
22 > }
23
24 > var parsedYaml map[string]any masker.go
25 > err := yaml.Unmarshal([]byte(yamlStr), &parsedYaml)
26 > if err != nil {
27 return yamlStr, err
28 }
29
30 > maskMap(parsedYaml, fns) masker.go
31 >
32 > strBytes, err := yaml.Marshal(parsedYaml)
33 > if err != nil {
34 return yamlStr, err
35 }
36 > return string(strBytes), nil masker.go
37 }
38
71 }
72
73 > func maskMap(m map[string]any, fns map[string]struct{}) { masker.go
74 > for key, value := range m {
75 > if _, ok := fns[key]; ok {
76 > m[key] = passwordMask
77 > }
78
79 > if valueMap, ok := value.(map[string]any); ok { masker.go
80 > maskMap(valueMap, fns)
81 > }
82 }
83 }