feat: Normalize fields across various Boundary components (#5599)
Normalizes various IP/Address/Host fields across Boundary resources/components to comply with IPv6 specifications.
This commit is contained in:
37 files changed
+1028
-348
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/oplog"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -209,7 +210,11 @@ func (am *AuthMethod) convertUrls(ctx context.Context) ([]*Url, error) {
|
||||
}
|
||||
newValObjs := make([]*Url, 0, len(am.Urls))
|
||||
for priority, u := range am.Urls {
|
||||
parsed, err := url.Parse(u)
|
||||
addr, err := parseutil.NormalizeAddr(u)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
parsed, err := url.Parse(addr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ func TestAuthMethod_oplog(t *testing.T) {
|
||||
func Test_convertValueObjects(t *testing.T) {
|
||||
testCtx := context.TODO()
|
||||
testPublicId := "test-id"
|
||||
testLdapServers := []string{"ldaps://ldap1.alice.com", "ldaps://ldap2.alice.com"}
|
||||
testLdapServers := []string{"ldaps://ldap1.alice.com", "ldaps://ldap2.alice.com", "ldap://[2001:BEEF:0:0:0:1:0:0001]:80"}
|
||||
_, pem := TestGenerateCA(t, "localhost")
|
||||
testCerts := []string{pem}
|
||||
c, err := NewCertificate(testCtx, testPublicId, pem)
|
||||
@@ -499,7 +499,18 @@ func Test_convertValueObjects(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantErrMatch: errors.T(errors.Unknown),
|
||||
wantErrContains: "first path segment in URL cannot contain colon",
|
||||
wantErrContains: "failed to parse address",
|
||||
},
|
||||
{
|
||||
name: "invalid-url-has-invalid-ipv6",
|
||||
am: &AuthMethod{
|
||||
AuthMethod: &store.AuthMethod{
|
||||
PublicId: testPublicId,
|
||||
Urls: []string{"ldaps://[2001:BEEF:0:0:1:0:0001]"},
|
||||
},
|
||||
},
|
||||
wantErrMatch: errors.T(errors.Unknown),
|
||||
wantErrContains: "host contains an invalid IPv6 literal",
|
||||
},
|
||||
{
|
||||
name: "invalid-client-cert",
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -255,6 +256,9 @@ func TestConvertToUrls(t testing.TB, urls ...string) []*url.URL {
|
||||
require.NotEmpty(urls)
|
||||
var convertedUrls []*url.URL
|
||||
for _, u := range urls {
|
||||
var err error
|
||||
u, err = parseutil.NormalizeAddr(u)
|
||||
require.NoError(err)
|
||||
parsed, err := url.Parse(u)
|
||||
require.NoError(err)
|
||||
require.Contains([]string{"ldap", "ldaps"}, parsed.Scheme)
|
||||
|
||||
Reference in new issue
Block a user