From bd03c99f8913332c34f8e9c726c6097b9ee1b3dd Mon Sep 17 00:00:00 2001 From: Damian Debkowski Date: Thu, 5 Sep 2024 10:30:30 -0700 Subject: [PATCH] test(target): validate ipv6 address for tcp targets (#5076) --- .../target/tcp/repository_tcp_target_test.go | 66 +++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/internal/target/tcp/repository_tcp_target_test.go b/internal/target/tcp/repository_tcp_target_test.go index 5f944351b..6341c86db 100644 --- a/internal/target/tcp/repository_tcp_target_test.go +++ b/internal/target/tcp/repository_tcp_target_test.go @@ -71,12 +71,12 @@ func TestRepository_CreateTarget(t *testing.T) { wantErr: false, }, { - name: "with-address", + name: "with-ipv4-address", args: args{ target: func() target.Target { target, err := target.New(ctx, tcp.Subtype, proj.PublicId, - target.WithName("with-address"), - target.WithDescription("with-address"), + target.WithName("with-ipv4-address"), + target.WithDescription("with-ipv4-address"), target.WithDefaultPort(80), target.WithAddress("8.8.8.8")) require.NoError(t, err) @@ -85,6 +85,36 @@ func TestRepository_CreateTarget(t *testing.T) { }, wantErr: false, }, + { + name: "with-abbreviated-ipv6-address", + args: args{ + target: func() target.Target { + target, err := target.New(ctx, tcp.Subtype, proj.PublicId, + target.WithName("with-abbreviated-ipv6-address"), + target.WithDescription("with-abbreviated-ipv6-address"), + target.WithDefaultPort(80), + target.WithAddress("2001:4860:4860::8888")) + require.NoError(t, err) + return target + }(), + }, + wantErr: false, + }, + { + name: "with-ipv6-address", + args: args{ + target: func() target.Target { + target, err := target.New(ctx, tcp.Subtype, proj.PublicId, + target.WithName("with-ipv6-address"), + target.WithDescription("with-ipv6-address"), + target.WithDefaultPort(80), + target.WithAddress("2001:4860:4860:0:0:0:0:8888")) + require.NoError(t, err) + return target + }(), + }, + wantErr: false, + }, { name: "with-address-whitespace", args: args{ @@ -360,9 +390,9 @@ func TestRepository_UpdateTcpTarget(t *testing.T) { }, { - name: "valid-address", + name: "valid-ipv4-address", args: args{ - name: "valid-address" + id, + name: "valid-ipv4-address" + id, fieldMaskPaths: []string{"Name", "Address"}, ProjectId: proj.PublicId, address: "8.8.8.8", @@ -372,6 +402,32 @@ func TestRepository_UpdateTcpTarget(t *testing.T) { wantRowsUpdate: 1, wantHostSources: false, }, + { + name: "valid-abbreviated-ipv6-address", + args: args{ + name: "valid-abbreviated-ipv6-address" + id, + fieldMaskPaths: []string{"Name", "Address"}, + ProjectId: proj.PublicId, + address: "2001:4860:4860::8888", + }, + newProjectId: proj.PublicId, + wantErr: false, + wantRowsUpdate: 1, + wantHostSources: false, + }, + { + name: "valid-ipv6-address", + args: args{ + name: "valid-ipv6-address" + id, + fieldMaskPaths: []string{"Name", "Address"}, + ProjectId: proj.PublicId, + address: "2001:4860:4860:0:0:0:0:8888", + }, + newProjectId: proj.PublicId, + wantErr: false, + wantRowsUpdate: 1, + wantHostSources: false, + }, { name: "null-address", args: args{