fix: protect local HTTP boundary and saved setup credentials (#2)
This commit is contained in:
1 parent
134685d482
commit
c0c7804494
7 files changed
+184
-34
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"git.mchus.pro/mchus/quoteforge/internal/localdb"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetupPassword(t *testing.T) {
|
||||
saved := &localdb.ConnectionSettings{Host: "db.example", Port: 3306, User: "example", PasswordEncrypted: "example"}
|
||||
for _, tt := range []struct {
|
||||
name, host, user, password string
|
||||
port int
|
||||
wantError bool
|
||||
}{
|
||||
{"same destination", "db.example", "example", "", 3306, false},
|
||||
{"changed host", "other.example", "example", "", 3306, true},
|
||||
{"changed port", "db.example", "example", "", 3307, true},
|
||||
{"changed user", "db.example", "other", "", 3306, true},
|
||||
{"explicit password", "other.example", "other", "example", 3307, false},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := setupPassword(saved, tt.host, tt.port, tt.user, tt.password)
|
||||
if (err != nil) != tt.wantError {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !tt.wantError && got != "example" {
|
||||
t.Fatal("credential not preserved")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user