MCPcopy Create free account
hub / github.com/Driver-C/tryssh / TestServerListConfig_String

Function TestServerListConfig_String

pkg/config/loader_test.go:329–364  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

327
328
329func TestServerListConfig_String(t *testing.T) {
330 tests := []struct {
331 name string
332 config ServerListConfig
333 expected string
334 }{
335 {
336 name: "all fields populated",
337 config: ServerListConfig{IP: "192.168.1.1", Port: "22", User: "root", Password: "secret123", Key: "/home/user/.ssh/id_rsa", Alias: "myserver"},
338 expected: "root@192.168.1.1:22",
339 },
340 {
341 name: "empty password and key",
342 config: ServerListConfig{IP: "10.0.0.1", Port: "22", User: "admin", Password: "", Key: "", Alias: ""},
343 expected: "<empty>",
344 },
345 {
346 name: "short password",
347 config: ServerListConfig{IP: "10.0.0.2", Port: "2222", User: "root", Password: "ab", Key: ""},
348 expected: "****",
349 },
350 }
351 for _, tt := range tests {
352 t.Run(tt.name, func(t *testing.T) {
353 result := tt.config.String()
354 assert.Contains(t, result, tt.expected)
355 // Password should never appear in plaintext
356 if tt.config.Password != "" {
357 assert.NotContains(t, result, tt.config.Password)
358 }
359 if tt.config.Key != "" {
360 assert.NotContains(t, result, tt.config.Key)
361 }
362 })
363 }
364}
365
366func TestEncryptConfigForSave_WithPasswords(t *testing.T) {
367 // Test that encryptConfigForSave encrypts passwords when a master key is available

Callers

nothing calls this directly

Calls 1

StringMethod · 0.80

Tested by

no test coverage detected