This adds an action to the API that allows pulling out an activation token that can be given to a worker in its config (directly or via env or file). The worker can pass this along with its normal request in place of its normal nonce and the server will automatically accept it. Co-authored-by: Irena Rindos <irenarindos@users.noreply.github.com>
69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
"github.com/hashicorp/boundary/internal/kms"
|
|
"github.com/hashicorp/boundary/internal/types/scope"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTestKmsWorker(t *testing.T) {
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
wrapper := db.TestWrapper(t)
|
|
const (
|
|
name = "test name"
|
|
description = "test description"
|
|
address = "test address"
|
|
)
|
|
tWorker := TestKmsWorker(t, conn, wrapper, WithName(name), WithDescription(description), WithAddress(address))
|
|
assert.NotNil(t, tWorker)
|
|
assert.True(t, strings.HasPrefix(tWorker.GetPublicId(), WorkerPrefix))
|
|
|
|
lkpWorker := NewWorker(scope.Global.String())
|
|
lkpWorker.PublicId = tWorker.GetPublicId()
|
|
rw := db.New(conn)
|
|
require.NoError(t, rw.LookupById(context.Background(), lkpWorker))
|
|
assert.NotNil(t, lkpWorker)
|
|
assert.NotNil(t, lkpWorker.GetLastStatusTime())
|
|
assert.Equal(t, KmsWorkerType.String(), lkpWorker.GetType())
|
|
assert.Equal(t, name, lkpWorker.GetName())
|
|
assert.Equal(t, description, lkpWorker.GetDescription())
|
|
assert.Equal(t, address, lkpWorker.GetAddress())
|
|
}
|
|
|
|
func TestTestPkiWorker(t *testing.T) {
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
wrapper := db.TestWrapper(t)
|
|
kmsCache := kms.TestKms(t, conn, wrapper)
|
|
require.NoError(t, kmsCache.CreateKeys(context.Background(), scope.Global.String(), kms.WithRandomReader(rand.Reader)))
|
|
const (
|
|
name = "test name"
|
|
description = "test description"
|
|
)
|
|
tWorker := TestPkiWorker(t, conn, wrapper, WithName(name), WithDescription(description))
|
|
assert.NotNil(t, tWorker)
|
|
assert.True(t, strings.HasPrefix(tWorker.GetPublicId(), WorkerPrefix))
|
|
|
|
lkpWorker := NewWorker(scope.Global.String())
|
|
lkpWorker.PublicId = tWorker.GetPublicId()
|
|
rw := db.New(conn)
|
|
require.NoError(t, rw.LookupById(context.Background(), lkpWorker))
|
|
assert.NotNil(t, lkpWorker)
|
|
assert.Equal(t, PkiWorkerType.String(), lkpWorker.GetType())
|
|
assert.Equal(t, name, lkpWorker.GetName())
|
|
assert.Equal(t, description, lkpWorker.GetDescription())
|
|
assert.Nil(t, lkpWorker.GetLastStatusTime())
|
|
|
|
var keyId string
|
|
authorizedWorker := TestPkiWorker(t, conn, wrapper, WithTestPkiWorkerAuthorizedKeyId(&keyId))
|
|
assert.NotNil(t, authorizedWorker)
|
|
assert.True(t, strings.HasPrefix(authorizedWorker.GetPublicId(), WorkerPrefix))
|
|
assert.NotEmpty(t, keyId)
|
|
}
|