...
1 package util_test
2
3 import (
4 "testing"
5
6 "edge-infra.dev/pkg/edge/iam/util"
7 )
8
9 func TestMaskURL(t *testing.T) {
10 const defaultURL = "/a?k1=some-k1-value123&k2=987654321"
11 tcs := []struct {
12 name string
13 url string
14 keysToMask []string
15 expected string
16 }{
17 {"NON-EXISTING-KEY", defaultURL, []string{"NON-EXISTING-KEY"}, defaultURL},
18 {"MASK-ONE-KEY", defaultURL, []string{"k1"}, "/a?k1=xxxxxue123&k2=987654321"},
19 {"MASK-TWO-KEYS", defaultURL, []string{"k1", "k2"}, "/a?k1=xxxxxue123&k2=xxxxx54321"},
20 {"MASK-ALL-IF-SHORT-VALUE", defaultURL + "&k3=123", []string{"k3"}, "/a?k1=some-k1-value123&k2=987654321&k3=xxxxx"},
21 {"DO-NOT-ENCODE-URL", defaultURL + "&k3=http%3A%2F%2Flocalhost%3A8088%2Fverify%2Fcallback", []string{"k1", "k2"}, "/a?k1=xxxxxue123&k2=xxxxx54321&k3=http%3A%2F%2Flocalhost%3A8088%2Fverify%2Fcallback"},
22 }
23
24 t.Parallel()
25 for _, tc := range tcs {
26 t.Run(tc.name, func(t *testing.T) {
27 got, _ := util.MaskURLQuery(tc.url, tc.keysToMask...)
28 if got != tc.expected {
29 t.Errorf("%s: MaskURLQuery(%s, %s) expected `%v` got `%v`", tc.name, tc.url, tc.keysToMask, tc.expected, got)
30 }
31 })
32 }
33 }
34
View as plain text