Debian Codegraph @

shoutrrr/cmd/generate/generate_test.go

raw symbols SCIP
1 package generatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/
2
3 import (
4 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
5 "testingscip-go gomod github.com/golang/go/src . testing/"
6
7 "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/"
8 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/"
9 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/"
10
11 "github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushoverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/"
12 )
13
14 // Test_loadArgsFromAltSources tests the loadArgsFromAltSources function with various scenarios.
15 func Test_loadArgsFromAltSourcesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_loadArgsFromAltSources().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
16 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
17
18 tests := []struct {
19 name string
20 args []string
21 wantService string
22 wantGen string
23 wantNoChange bool
24 }{
25 {
26 name: "positional service only",
27 args: []string{"discord"},
28 wantService: "discord",
29 wantGen: "basic",
30 },
31 {
32 name: "positional both args",
33 args: []string{"discord", "basic"},
34 wantService: "discord",
35 wantGen: "basic",
36 },
37 {
38 name: "no positional args",
39 args: []string{},
40 wantNoChange: true,
41 },
42 }
43
44 for _, tt := range tests {
45 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
46 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
47
48 // Create a cobra command with the expected flags
49 cmd := &cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#{
50 Usescip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Use.: "generate",
51 }
52 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("service", "s", "", "Notification service")
53 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().StringPscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#StringP().("generator", "g", "basic", "Generator to use")
54
55 loadArgsFromAltSourcesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/loadArgsFromAltSources().(cmd, tt.args)
56
57 if tt.wantNoChange {
58 // Verify flags remain at their defaults/empty values
59 service, _ := cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().GetStringscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#GetString().("service")
60 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Emptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Empty().(t, service, "service flag should remain empty")
61 } else {
62 // Verify the flags were set correctly
63 service, _ := cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().GetStringscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#GetString().("service")
64 gen, _ := cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().GetStringscip-go gomod github.com/spf13/pflag v1.0.10 `github.com/spf13/pflag`/FlagSet#GetString().("generator")
65
66 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantService, service, "service flag mismatch")
67 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantGen, gen, "generator flag mismatch")
68 }
69 })
70 }
71 }
72
73 // Test_maskSensitiveURL tests the maskSensitiveURL function with various service schemas.
74 func Test_maskSensitiveURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskSensitiveURL().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
75 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
76
77 tests := []struct {
78 name string
79 serviceSchema string
80 urlStr string
81 want string
82 }{
83 {
84 name: "discord service masks user",
85 serviceSchema: "discord",
86 urlStr: "https://[email protected]/api/webhooks/123",
87 want: "https://[email protected]/api/webhooks/123",
88 },
89 {
90 name: "slack service masks user",
91 serviceSchema: "slack",
92 urlStr: "https://[email protected]/services/123",
93 want: "https://[email protected]/services/123",
94 },
95 {
96 name: "teams service masks user",
97 serviceSchema: "teams",
98 urlStr: "https://[email protected]/webhook",
99 want: "https://[email protected]/webhook",
100 },
101 {
102 name: "smtp service masks password",
103 serviceSchema: "smtp",
104 urlStr: "smtp://user:pass@host:587",
105 want: "smtp://user:REDACTED@host:587",
106 },
107 {
108 name: "pushover service masks token and user",
109 serviceSchema: "pushover",
110 urlStr: "pushover://pushover.net?token=abc&user=def",
111 want: "pushover://pushover.net?token=REDACTED&user=REDACTED",
112 },
113 {
114 name: "pushover service masks userinfo token and encryption key",
115 serviceSchema: "pushover",
116 urlStr: "pushover://Token:secret-api-token@userkey/?encryptionkey=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
117 want: "pushover://Token:REDACTED@userkey/?encryptionkey=REDACTED",
118 },
119 {
120 name: "gotify service masks token",
121 serviceSchema: "gotify",
122 urlStr: "gotify://gotify.net?token=secret",
123 want: "gotify://gotify.net?token=REDACTED",
124 },
125 {
126 name: "signalgrid service masks user and host",
127 serviceSchema: "signalgrid",
128 urlStr: "signalgrid://ClientKey@ChannelToken?title=Alert",
129 want: "signalgrid://REDACTED@REDACTED?title=Alert",
130 },
131 {
132 name: "generic service masks user and query params",
133 serviceSchema: "unknown",
134 urlStr: "https://user:pass@host?a=1&b=2",
135 want: "https://REDACTED@host?a=REDACTED&b=REDACTED",
136 },
137 {
138 name: "invalid URL returns original",
139 serviceSchema: "discord",
140 urlStr: "://invalid",
141 want: "://invalid",
142 },
143 }
144
145 for _, tt := range tests {
146 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
147 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
148
149 got := maskSensitiveURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskSensitiveURL().(tt.serviceSchema, tt.urlStr)
150 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.want, got, "maskSensitiveURL() returned unexpected value")
151 })
152 }
153 }
154
155 // Test_maskSensitiveURL_pushoverGeneratePath verifies that the default generate
156 // path redacts both Config.Token and Config.EncryptionKey.
157 func Test_maskSensitiveURL_pushoverGeneratePathscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskSensitiveURL_pushoverGeneratePath().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
158 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
159
160 cfg := &pushoverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#{
161 Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#Token.: "secret-api-token",
162 Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#User.: "userkey",
163 EncryptionKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#EncryptionKey.: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
164 }
165
166 masked := maskSensitiveURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskSensitiveURL().(pushoverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/.Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Scheme., cfg.GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#GetURL().().Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().())
167
168 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotContainsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotContains().(t, masked, cfg.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#Token., "API token must not appear in the masked URL")
169 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.NotContainsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/NotContains().(t, masked, cfg.EncryptionKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushover`/Config#EncryptionKey., "encryption key must not appear in the masked URL")
170 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Contains().(t, masked, redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr., "masked URL should contain the redaction placeholder")
171 }
172
173 // Test_maskUser tests the maskUser function.
174 func Test_maskUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskUser().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
175 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
176
177 tests := []struct {
178 name string
179 urlStr string
180 placeholder string
181 wantUser string
182 }{
183 {
184 name: "masks user with placeholder",
185 urlStr: "https://token@host/path",
186 placeholder: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
187 wantUser: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
188 },
189 {
190 name: "empty user remains nil",
191 urlStr: "https://host/path",
192 placeholder: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
193 wantUser: "",
194 },
195 }
196
197 for _, tt := range tests {
198 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
199 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
200
201 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.urlStr)
202 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "failed to parse URL")
203
204 maskUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskUser().(parsedURL, tt.placeholder)
205
206 if tt.wantUser == "" {
207 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User., "user should be nil")
208 } else {
209 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantUser, parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().(), "user mismatch")
210 }
211 })
212 }
213 }
214
215 // Test_maskSMTPUser tests the maskSMTPUser function.
216 func Test_maskSMTPUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskSMTPUser().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
217 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
218
219 tests := []struct {
220 name string
221 urlStr string
222 wantUser string
223 wantPass string
224 }{
225 {
226 name: "masks password preserving username",
227 urlStr: "smtp://user:pass@host:587",
228 wantUser: "user",
229 wantPass: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
230 },
231 {
232 name: "user without password gets redacted password",
233 urlStr: "smtp://user@host:587",
234 wantUser: "user",
235 wantPass: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
236 },
237 {
238 name: "nil user remains nil",
239 urlStr: "smtp://host:587",
240 wantUser: "",
241 wantPass: "",
242 },
243 }
244
245 for _, tt := range tests {
246 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
247 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
248
249 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.urlStr)
250 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "failed to parse URL")
251
252 maskSMTPUserscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskSMTPUser().(parsedURL)
253
254 if tt.wantUser == "" {
255 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Nil().(t, parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User., "user should be nil")
256 } else {
257 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantUser, parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().(), "username mismatch")
258
259 pass, hasPass := parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Passwordscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Password().()
260 if tt.wantPass != "" {
261 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, hasPass, "password should be set")
262 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantPass, pass, "password mismatch")
263 }
264 }
265 })
266 }
267 }
268
269 // Test_maskPushoverQuery tests the maskPushoverQuery function.
270 func Test_maskPushoverQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskPushoverQuery().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
271 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
272
273 tests := []struct {
274 name string
275 urlStr string
276 wantTok string
277 wantUser string
278 wantKey string
279 wantKeyParam string
280 wantPass string
281 }{
282 {
283 name: "masks token and user",
284 urlStr: "pushover://?token=abc&user=def",
285 wantTok: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
286 wantUser: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
287 },
288 {
289 name: "masks only token",
290 urlStr: "pushover://?token=abc",
291 wantTok: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
292 wantUser: "",
293 },
294 {
295 name: "leaves other params unchanged",
296 urlStr: "pushover://?other=value",
297 wantTok: "",
298 wantUser: "",
299 },
300 {
301 name: "masks encryptionkey query parameter",
302 urlStr: "pushover://?encryptionkey=secret-hex-key",
303 wantKey: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
304 wantKeyParam: "encryptionkey",
305 },
306 {
307 name: "masks key alias query parameter",
308 urlStr: "pushover://?key=secret-hex-key",
309 wantKey: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
310 wantKeyParam: "key",
311 },
312 {
313 name: "masks API token in URL userinfo",
314 urlStr: "pushover://Token:secret-api-token@userkey/",
315 wantPass: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
316 },
317 }
318
319 for _, tt := range tests {
320 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
321 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
322
323 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.urlStr)
324 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "failed to parse URL")
325
326 maskPushoverQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskPushoverQuery().(parsedURL)
327
328 query := parsedURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().()
329 if tt.wantTok != "" {
330 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantTok, query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().("token"), "token mismatch")
331 }
332
333 if tt.wantUser != "" {
334 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantUser, query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().("user"), "user mismatch")
335 }
336
337 if tt.wantKeyParam != "" {
338 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/True().(t, query.Hasscip-go gomod github.com/golang/go/src . `net/url`/Values#Has().(tt.wantKeyParam), "expected %s to be present", tt.wantKeyParam)
339 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantKey, query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().(tt.wantKeyParam), tt.wantKeyParam+" mismatch")
340 }
341
342 if tt.wantPass != "" {
343 pass, hasPass := parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Passwordscip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Password().()
344 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/True().(t, hasPass, "password should be set")
345 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantPass, pass, "userinfo token mismatch")
346 }
347
348 if tt.wantTok == "" && tt.wantUser == "" && tt.wantKey == "" && tt.wantPass == "" {
349 // Verify other params are unchanged
350 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "value", query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().("other"), "other param should be unchanged")
351 }
352 })
353 }
354 }
355
356 // Test_maskGotifyQuery tests the maskGotifyQuery function.
357 func Test_maskGotifyQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskGotifyQuery().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
358 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
359
360 tests := []struct {
361 name string
362 urlStr string
363 wantTok string
364 }{
365 {
366 name: "masks token",
367 urlStr: "gotify://?token=secret",
368 wantTok: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
369 },
370 {
371 name: "leaves other params unchanged",
372 urlStr: "gotify://?other=value",
373 wantTok: "",
374 },
375 }
376
377 for _, tt := range tests {
378 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
379 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
380
381 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.urlStr)
382 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "failed to parse URL")
383
384 maskGotifyQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskGotifyQuery().(parsedURL)
385
386 query := parsedURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().()
387 if tt.wantTok != "" {
388 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantTok, query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().("token"), "token mismatch")
389 } else {
390 // Verify other params are unchanged
391 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, "value", query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().("other"), "other param should be unchanged")
392 }
393 })
394 }
395 }
396
397 // Test_maskGeneric tests the maskGeneric function.
398 func Test_maskGenericscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/Test_maskGeneric().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
399 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
400
401 tests := []struct {
402 name string
403 urlStr string
404 wantUser string
405 wantParams map[string]string
406 wantQueryLen int
407 }{
408 {
409 name: "masks user and all query params",
410 urlStr: "https://user:pass@host?a=1&b=2",
411 wantUser: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
412 wantParams: map[string]string{
413 "a": redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
414 "b": redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
415 },
416 wantQueryLen: 2,
417 },
418 {
419 name: "masks only user when no query params",
420 urlStr: "https://user:pass@host",
421 wantUser: redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.,
422 },
423 {
424 name: "nil user with query params",
425 urlStr: "https://host?a=1",
426 wantUser: "",
427 wantParams: map[string]string{"a": redactedStrscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/redactedStr.},
428 wantQueryLen: 1,
429 },
430 }
431
432 for _, tt := range tests {
433 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
434 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
435
436 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.urlStr)
437 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "failed to parse URL")
438
439 maskGenericscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/shoutrrr/cmd/generate`/maskGeneric().(parsedURL)
440
441 if tt.wantUser != "" {
442 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, tt.wantUser, parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User..Usernamescip-go gomod github.com/golang/go/src . `net/url`/Userinfo#Username().(), "user mismatch")
443 } else if parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User. != nil {
444 t.Errorfscip-go gomod github.com/golang/go/src . testing/common#Errorf().("expected nil user, got %v", parsedURL.Userscip-go gomod github.com/golang/go/src . `net/url`/URL#User.)
445 }
446
447 query := parsedURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().()
448 if tt.wantParams != nil {
449 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Len().(t, query, tt.wantQueryLen, "query param count mismatch")
450
451 for key, wantVal := range tt.wantParams {
452 assertscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/assert`/Equal().(t, wantVal, query.Getscip-go gomod github.com/golang/go/src . `net/url`/Values#Get().(key), "param %s mismatch", key)
453 }
454 }
455 })
456 }
457 }