continuous-integration/drone Build is failing
Migrate the workspace to React and Ant Design, improve account forms and responsive layouts, support outbound diagnostics and SSH fingerprint confirmation, and persist the management startup port. Preserve database migrations, remove S3 settings storage, and improve gateway audit handling.
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package transport
|
|
|
|
import (
|
|
"encoding/json"
|
|
"linkport/internal/model"
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestAccountRestrictions(t *testing.T) {
|
|
p := model.Proxy{Type: "mongodb", GatewayUser: "legacy", GatewayPassword: "secret", AllowCIDRs: []string{"127.0.0.0/8"}, GatewayAccounts: []model.GatewayAccount{
|
|
{ID: "one", Username: "first", Password: "first-secret"},
|
|
{ID: "two", Username: "second", Password: "second-secret", AllowCIDRs: []string{"127.0.0.1"}, AccessMode: "readonly"},
|
|
{ID: "off", Username: "disabled", Password: "secret", Disabled: true},
|
|
}}
|
|
for _, tc := range []struct {
|
|
user, ip string
|
|
want bool
|
|
}{
|
|
{"first", "127.0.0.2", true}, {"second", "127.0.0.1", true}, {"second", "127.0.0.2", false},
|
|
{"first", "192.0.2.1", false}, {"disabled", "127.0.0.1", false}, {"legacy", "127.0.0.1", false}, {"missing", "127.0.0.1", false},
|
|
} {
|
|
a, got := Account(p, tc.user, &net.TCPAddr{IP: net.ParseIP(tc.ip), Port: 1234})
|
|
if got != tc.want {
|
|
t.Errorf("%s from %s: got %v", tc.user, tc.ip, got)
|
|
}
|
|
if got && tc.user == "second" && a.Apply(p).AccessMode != "readonly" {
|
|
t.Fatal("account readonly lost")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAuthenticationEventEscapesUsername(t *testing.T) {
|
|
AuthenticationEvent(func(category, rule string) {
|
|
if category != "authentication_failed" {
|
|
t.Fatal(category)
|
|
}
|
|
var record map[string]string
|
|
if err := json.Unmarshal([]byte(rule), &record); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(record) != 1 || record["username"] != "user\nname" {
|
|
t.Fatal(record)
|
|
}
|
|
}, "user\nname", false)
|
|
}
|