Skip to content

Commit cbc68fc

Browse files
committed
fix: rest.Client.LoginByToken invalid signature
PR #2701 (ebeaa71) added IPv6 support for signing HTTP request, but was treating all IPs as v6.
1 parent 6b4e239 commit cbc68fc

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

sts/client_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/vmware/govmomi/session"
3131
"github.com/vmware/govmomi/ssoadmin"
3232
"github.com/vmware/govmomi/ssoadmin/types"
33+
"github.com/vmware/govmomi/vapi/rest"
3334
"github.com/vmware/govmomi/vim25"
3435
"github.com/vmware/govmomi/vim25/methods"
3536
"github.com/vmware/govmomi/vim25/soap"
@@ -160,6 +161,12 @@ func TestIssueHOK(t *testing.T) {
160161
}
161162

162163
log.Printf("current time=%s", now)
164+
165+
rc := rest.NewClient(c)
166+
err = rc.LoginByToken(rc.WithSigner(ctx, s))
167+
if err != nil {
168+
t.Fatal(err)
169+
}
163170
}
164171

165172
func TestIssueTokenByToken(t *testing.T) {

sts/signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,5 @@ func isIPv6(s string) bool {
351351
if ip == nil {
352352
return false
353353
}
354-
return len(ip) == net.IPv6len
354+
return ip.To4() == nil
355355
}

sts/signer_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,20 @@ func TestSigner(t *testing.T) {
140140
t.Fatal(err)
141141
}
142142
}
143+
144+
func TestIsIPv6(t *testing.T) {
145+
tests := []struct {
146+
ip string
147+
v6 bool
148+
}{
149+
{"0:0:0:0:0:0:0:1", true},
150+
{"10.0.0.42", false},
151+
}
152+
153+
for _, test := range tests {
154+
v6 := isIPv6(test.ip)
155+
if v6 != test.v6 {
156+
t.Errorf("%s: expected %t, got %t", test.ip, test.v6, v6)
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)