Atlas › Test

TestMaskStruct

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

Package
go.temporal.io/server/common/masker
Suite / test hierarchy
TestMaskStruct
Test
TestMaskStruct
Introduced at
masker.go ×4 Frontier kind: Joint frontier
Covered ranges
5
Covered lines
22
Covered files
1

Covered source

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

go.temporal.io/server/common/masker/masker.go 22 covered LOC · 5 ranges

Open complete file

39 // MaskStruct replace password values with mask and returns copy of the strct.
40 // Original strct value is not modified. Doesn't go recursively through strct properties.
41 > func MaskStruct(strct any, fieldNamesToMask []string) any { masker.go
42 > strctV := reflect.ValueOf(strct)
43 >
44 > if strct == nil || (strctV.Kind() == reflect.Pointer && strctV.IsNil()) {
45 return strct
46 }
47
48 > for t := reflect.TypeOf(strct); t.Kind() == reflect.Pointer; t = t.Elem() { masker.go
49 > strctV = strctV.Elem()
50 > }
51
52 // strctV is not a pointer now. Create a copy using assignment.
53 > strctCopy := strctV.Interface() masker.go
54 > strctCopyPV := pointerTo(strctCopy)
55 > strctCopyV := strctCopyPV.Elem()
56 >
57 > for _, passwordFieldName := range fieldNamesToMask {
58 > passwordF := strctCopyV.FieldByName(passwordFieldName)
59 > if passwordF.CanSet() && passwordF.Kind() == reflect.String {
60 > passwordF.SetString(passwordMask)
61 > }
62 }
63
64 > return strctCopyPV.Interface() masker.go
65 }
66
67 > func pointerTo(val any) reflect.Value { masker.go
68 > valPtr := reflect.New(reflect.TypeOf(val))
69 > valPtr.Elem().Set(reflect.ValueOf(val))
70 > return valPtr
71 > }
72
73 func maskMap(m map[string]any, fns map[string]struct{}) {