fix auth model

This commit is contained in:
ayurishchev committed 2026-08-21 09:58:08 +03:00
1 parent f81285b151
commit 5e3800e9cb
10 files changed
+901 -70

No files matched your search

+28 -11
View File
@@ -12,9 +12,15 @@ import (
// vars are set, so the default `go test ./...` run needs no cloud access.
// It only exercises GetFloatingIPByAddress (read-only) against
// OS_TEST_FLOATING_IP, to avoid mutating real infrastructure in CI.
//
// OS_AUTH_METHOD selects which credential shape to test: "token" (default)
// reads OS_TOKEN and exercises the passthrough path; "password" reads
// OS_USERNAME/OS_PASSWORD/OS_USER_DOMAIN_NAME and exercises the
// auto-obtain/auto-reauth path. Run once per method to validate both
// against the real deployment.
func TestClientLive(t *testing.T) {
if os.Getenv("OPENSTACK_LIVE_TEST") != "1" {
t.Skip("set OPENSTACK_LIVE_TEST=1 (and OS_AUTH_URL, OS_TOKEN, OS_TEST_FLOATING_IP) to run")
t.Skip("set OPENSTACK_LIVE_TEST=1 (and OS_AUTH_URL, OS_PROJECT_ID, OS_TEST_FLOATING_IP, plus either OS_TOKEN or OS_USERNAME/OS_PASSWORD/OS_USER_DOMAIN_NAME) to run")
}
testIP := os.Getenv("OS_TEST_FLOATING_IP")
@@ -22,19 +28,30 @@ func TestClientLive(t *testing.T) {
t.Fatal("OS_TEST_FLOATING_IP must name a floating IP address that exists in the target project")
}
cfg := ClientConfig{
AuthURL: os.Getenv("OS_AUTH_URL"),
ProjectID: os.Getenv("OS_PROJECT_ID"),
Region: os.Getenv("OS_REGION_NAME"),
Interface: os.Getenv("OS_INTERFACE"),
}
switch os.Getenv("OS_AUTH_METHOD") {
case "password":
cfg.Method = AuthMethodPassword
cfg.Username = os.Getenv("OS_USERNAME")
cfg.Password = os.Getenv("OS_PASSWORD")
cfg.UserDomainName = os.Getenv("OS_USER_DOMAIN_NAME")
default:
cfg.Method = AuthMethodToken
cfg.Token = os.Getenv("OS_TOKEN")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
client, err := NewClient(ctx, ClientConfig{
AuthURL: os.Getenv("OS_AUTH_URL"),
Token: os.Getenv("OS_TOKEN"),
ProjectID: os.Getenv("OS_PROJECT_ID"),
ProjectName: os.Getenv("OS_PROJECT_NAME"),
DomainName: os.Getenv("OS_PROJECT_DOMAIN_NAME"),
Region: os.Getenv("OS_REGION_NAME"),
})
client, err := NewClient(ctx, cfg)
if err != nil {
t.Fatalf("new client: %v", err)
t.Fatalf("new client (method=%s): %v", cfg.Method, err)
}
fip, err := client.GetFloatingIPByAddress(ctx, testIP)
@@ -44,5 +61,5 @@ func TestClientLive(t *testing.T) {
if fip.Address != testIP {
t.Fatalf("expected address %s, got %s", testIP, fip.Address)
}
t.Logf("found floating ip %s: id=%s port_id=%q", fip.Address, fip.ID, fip.PortID)
t.Logf("found floating ip %s: id=%s port_id=%q (auth method=%s)", fip.Address, fip.ID, fip.PortID, cfg.Method)
}