|
|
|
|
@ -10,7 +10,6 @@ import (
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/iam"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/kms"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/server/store"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
@ -29,7 +28,7 @@ func TestRepository_UpsertController(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
controller *store.Controller
|
|
|
|
|
controller *Controller
|
|
|
|
|
wantCount int
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
@ -38,52 +37,34 @@ func TestRepository_UpsertController(t *testing.T) {
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty-id",
|
|
|
|
|
controller: &store.Controller{
|
|
|
|
|
PrivateId: "",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
name: "empty-id",
|
|
|
|
|
controller: NewController("", WithAddress("127.0.0.1")),
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty-address",
|
|
|
|
|
controller: &store.Controller{
|
|
|
|
|
PrivateId: "test-controller",
|
|
|
|
|
Address: "",
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
name: "empty-address",
|
|
|
|
|
controller: NewController("test-controller"),
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-ipv4-controller",
|
|
|
|
|
controller: &store.Controller{
|
|
|
|
|
PrivateId: "test-ipv4-controller",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-ipv4-controller",
|
|
|
|
|
controller: NewController("ipv4-controller", WithAddress("127.0.0.1")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-ipv6-controller",
|
|
|
|
|
controller: &store.Controller{
|
|
|
|
|
PrivateId: "test-ipv6-controller",
|
|
|
|
|
Address: "[2001:4860:4860:0:0:0:0:8888]",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-ipv6-controller",
|
|
|
|
|
controller: NewController("test-ipv6-controller", WithAddress("[2001:4860:4860:0:0:0:0:8888]")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-abbreviated-ipv6-controller",
|
|
|
|
|
controller: &store.Controller{
|
|
|
|
|
PrivateId: "test-abbreviated-ipv6-controller",
|
|
|
|
|
Address: "[2001:4860:4860::8888]",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-abbreviated-ipv6-controller",
|
|
|
|
|
controller: NewController("test-abbreviated-ipv6-controller", WithAddress("[2001:4860:4860::8888]")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-controller-short-name",
|
|
|
|
|
controller: &store.Controller{
|
|
|
|
|
PrivateId: "test",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-controller-short-name",
|
|
|
|
|
controller: NewController("test", WithAddress("127.0.0.1")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
@ -115,8 +96,8 @@ func TestRepository_UpdateController(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
originalController *store.Controller
|
|
|
|
|
updatedController *store.Controller
|
|
|
|
|
originalController *Controller
|
|
|
|
|
updatedController *Controller
|
|
|
|
|
wantCount int
|
|
|
|
|
wantErr bool
|
|
|
|
|
}{
|
|
|
|
|
@ -125,92 +106,50 @@ func TestRepository_UpdateController(t *testing.T) {
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty-id",
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
name: "empty-id",
|
|
|
|
|
updatedController: NewController("", WithAddress("127.0.0.1")),
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty-address",
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "test-controller",
|
|
|
|
|
Address: "",
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
name: "empty-address",
|
|
|
|
|
updatedController: NewController("test-controller"),
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "controller-not-found",
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "test-new-ipv4-controller",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
Description: "new ipv4 description",
|
|
|
|
|
},
|
|
|
|
|
wantErr: true,
|
|
|
|
|
name: "controller-not-found",
|
|
|
|
|
updatedController: NewController("test-controller", WithAddress("127.0.0.1"), WithDescription("new ipv4 description")),
|
|
|
|
|
wantErr: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-ipv4-controller",
|
|
|
|
|
originalController: &store.Controller{
|
|
|
|
|
PrivateId: "ipv4-controller",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
Description: "ipv4 description",
|
|
|
|
|
},
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "ipv4-controller",
|
|
|
|
|
Address: "127.0.0.2",
|
|
|
|
|
Description: "new ipv4 description",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-ipv4-controller",
|
|
|
|
|
originalController: NewController("ipv4-controller", WithAddress("127.0.0.1"), WithDescription("ipv4 description")),
|
|
|
|
|
updatedController: NewController("ipv4-controller", WithAddress("127.0.0.2"), WithDescription("new ipv4 description")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-ipv6-controller",
|
|
|
|
|
originalController: &store.Controller{
|
|
|
|
|
PrivateId: "test-ipv6-controller",
|
|
|
|
|
Address: "[2001:4860:4860:0:0:0:0:8888]",
|
|
|
|
|
Description: "ipv6 description",
|
|
|
|
|
},
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "test-ipv6-controller",
|
|
|
|
|
Address: "[2001:4860:4860:0:0:0:0:9999]",
|
|
|
|
|
Description: "new ipv6 description",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-ipv6-controller",
|
|
|
|
|
originalController: NewController("test-ipv6-controller", WithAddress("[2001:4860:4860:0:0:0:0:8888]"), WithDescription("ipv6 description")),
|
|
|
|
|
updatedController: NewController("test-ipv6-controller", WithAddress("[2001:4860:4860:0:0:0:0:9999]"), WithDescription("new ipv6 description")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-abbreviated-ipv6-controller",
|
|
|
|
|
originalController: &store.Controller{
|
|
|
|
|
PrivateId: "test-abbreviated-ipv6-controller",
|
|
|
|
|
Address: "[2001:4860:4860::8888]",
|
|
|
|
|
Description: "abbreviated ipv6 description",
|
|
|
|
|
},
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "test-abbreviated-ipv6-controller",
|
|
|
|
|
Address: "[2001:4860:4860::9999]",
|
|
|
|
|
Description: "new abbreviated ipv6 description",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-abbreviated-ipv6-controller",
|
|
|
|
|
originalController: NewController("test-abbreviated-ipv6-controller", WithAddress("[2001:4860:4860::8888]"), WithDescription("abbreviated ipv6 description")),
|
|
|
|
|
updatedController: NewController("test-abbreviated-ipv6-controller", WithAddress("[2001:4860:4860::9999]"), WithDescription("new abbreviated ipv6 description")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "valid-controller-short-name",
|
|
|
|
|
originalController: &store.Controller{
|
|
|
|
|
PrivateId: "test",
|
|
|
|
|
Address: "127.0.0.1",
|
|
|
|
|
Description: "short name description",
|
|
|
|
|
},
|
|
|
|
|
updatedController: &store.Controller{
|
|
|
|
|
PrivateId: "test",
|
|
|
|
|
Address: "127.0.0.2",
|
|
|
|
|
Description: "new short name description",
|
|
|
|
|
},
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
name: "valid-controller-short-name",
|
|
|
|
|
originalController: NewController("test", WithAddress("127.0.0.1"), WithDescription("short name description")),
|
|
|
|
|
updatedController: NewController("test", WithAddress("127.0.0.2"), WithDescription("new short name description")),
|
|
|
|
|
wantCount: 1,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
assert, require := assert.New(t), require.New(t)
|
|
|
|
|
|
|
|
|
|
var originalControllerEntry, updatedControllerEntry *store.Controller
|
|
|
|
|
var originalControllerEntry *Controller
|
|
|
|
|
// Insert the original controller attributes if they exist
|
|
|
|
|
if tt.originalController != nil {
|
|
|
|
|
_, err := testRepo.UpsertController(ctx, tt.originalController)
|
|
|
|
|
@ -235,7 +174,7 @@ func TestRepository_UpdateController(t *testing.T) {
|
|
|
|
|
// Retrieve the updated controller in the database and assert updated successfully
|
|
|
|
|
controllerList, err := testRepo.ListControllers(ctx, []Option{}...)
|
|
|
|
|
require.NoError(err)
|
|
|
|
|
updatedControllerEntry = controllerList[len(controllerList)-1]
|
|
|
|
|
updatedControllerEntry := controllerList[len(controllerList)-1]
|
|
|
|
|
|
|
|
|
|
assert.Equal(tt.updatedController.PrivateId, updatedControllerEntry.PrivateId)
|
|
|
|
|
assert.Equal(tt.updatedController.Address, updatedControllerEntry.Address)
|
|
|
|
|
|