* Fix down migrations * Udpates due to merge * Sentinel values only have to be greater than 0 * Create credential related sdk structs and methods. * Post merge interface updating. * Removing scratch code that was not cleaned up. * updates * Convert client certificate and client certificate keys into pem blocks and validate. * Add newline at end of file. * Faster check for "s" at the end of a resource name when generating from templates. * make fmt * updates * Add dynamic credentials to a session * Refactor: move contents of file * updates * Updates * Add InvalidDynamicCredential error * Assign credentials * Allow updating client certificates seperate from the client certificate key. * Replace application purpose string with enum value * PR feedback / fix go test . * Delete dead code * Use common view * Refactor: extract interface and rename method * Refactor: move code to eliminate privPurpLibrary * Add comment to requestMap * Refactor: do not export methods on an unexported struct * Update internal/db/schema/migrations/postgres/10/03_vault_credential.up.sql Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Add comments to credential Purpose constants * Reorder switch statements to handle errors first * PR feedback * update * fix merge * Organizing the scheduler code and extract the individual store creation test helper function. * Run 'make fmt' * Create certificate when creating store. Allow vault address to be passed in as option * Refactor: rename database views and associated structs This change renames two database views and associated go structs to use a consistent naming pattern. Views ending in 'private' contain encrypted credentials needed for connecting to Vault. Views ending in 'public' mirror the 'private' views but do not include any encrypted values. This change does not include any changes to functionality or behavior. * Adding SAD target operations for credential libraries to the SDK. * Add status field and enumeration table for credential status * Refactor: rename Status to TokenStatus * Add status to vault credentials * Creating the template for the CLI and helper functions. * Add private database view for vault credentials * Add scope_id to view and cleanup TODO comment * Reformat embedded sql queries * Add vault client helpers * updates * white space * Add LookupLease test * CLI commands for Store work. Renamed fields in proto w/ vault prefix. * Test issue credentials with client TLS * Add additional checks to vault ping * Add an error for vault token capabilities and create a VaultToken error kind * Add support for working with Vault policies * Use Vault 1.7.2 for testing * Add testing helper for creating a vault client with a non-root token * Fix Vault renew lease test The Vault renew lease endpoint accepts an optional duration parameter for requesting the number of seconds to extend the lease by. However, Vault is not required to honor this request. * Add a var for the required capabilities of a boundary Vault token * Enhance the test helper for adding a policy to Vault * Allow the test role in postgresql to revoke credentials * Remove out of date comments * Enhance Vault test helpers for the database secrets engine * Reformat comments * Add a method for getting the capabilities of the current Vault token * Add revoke lease to internal Vault client * Reformat: combine err return line with check for nil line * Remove redundant checks in test code Remove checks in test code that are redundant with checks in the test harness. * Refactor CreateToken test helper to return the secret and the token * Fix build failures caused by signature change in vault.CreateToken * Fix Vault version and Vault API link in comments * ran `make gen` after merging from mgaffney-vault. * Remove Vault prefix from attribute fields in API, create a base CLI option for adding field prefixes. format now uses that prefix for error reporting. * Template now allows attaching attribute field prefixes. * Credential store uses PrefixAttributeFieldErrorsWithSubactionPrefix. * Fixing naming of vault flags and helper flags. * Updating more references to generated api methods. * Make the capabilities String method more readable * Add comment outlining PrintApiError usage of Options. * Refactor test to move declarations closer to first use * Fix comment * Implement revoke method on vault repository * Tests now verify certs, CA, and tokens, addresses can be updated in a store. * Added test for creating store with pk/cert in same field. * Allo updating certificates seperate from private key. Only contact backing vault service when updating token. * Fixing bad tests and removing unused code. * Adding tests for various ways of updating tokens. * Add private credential * Add token revocation job and cred renewal/revocation job * Regen after merge. * Fixing field mask related merge error. * Create Library CLI. Removes vault prefix from path. Adds a WithoutCleanup testOption for vault. * Set all credentials to revoked when a token is revoked * Fixing missed renaming update. * fix copy/paste error. * Fixing code generation errors after merge. * make gen after merge. * Update internal/cmd/commands/credentialstorescmd/vault_funcs.go Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Update internal/cmd/commands/credentialstorescmd/vault_funcs.go Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Update internal/cmd/commands/credentialstorescmd/vault_funcs.go Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> * Refactor: move migrations from 10 to 12 * Removing logic from transaction. * wrapping client errors in the calling op for CredentialStore's client() method. * Redact token * redact client key * updates * Add trigger to revoke credentials when session is canceled or terminated * Fixing some help text for some flags. * Add ability to load values from files (file://) or environment variables (env://). * Updating comments * fix bad merge * feedback * Adding issued credentials to sessions. * Error on capabilities * updates * Expose NewVaulTestServer * Add godoc * Adding generated SessionCredential struct for API. * Progress on building handler test for Authorize Session. * feedback * Update policies * Add 'revoke' as a status for Vault Tokens * Add delete_time to vault credential store * Create dynamic credentials at session creation time. * Tests pass with credentials attached to AuthorizedSession result. * Only call issue if there are credentials to issue. * Fixing output only issues. Adding type to credential library. * Fix test to clear un/pw generated. confirm generated un/pw changes from 1 authorize session call to another. * Update lookupTokenError * Add delete_time to private credential store * Refactor: move private store to separate file * Fixing tests for AuthorizeSession and verifying error cases. * Only create the credential repo if there are credentials to issue. * Rename Library field to CredentialLibrary. * Fixing missing change of Library to CredentialLibrary. * Removing Default SDK functions for fields which are required and update CLI to match. * Replace resource specific id variables with "id" and the input parmater for paths to be just a single string and the resource name as it should show up in the path. * Soft delete vault credential stores * Prevent new SQL functions from silently overwriting existing functions * Rename "Hmac" to "HMAC" in the human readable cli response table. * Fix tests * Add vault database cleanup jobs * Add ability to set the token period in the vault test harness * updates * Add not_null_columns func test * remove unused struct * Up no output timeout * Validate current vault token on addr update * Fix client cert change test * add cert test * Update revocation job where * Fix comment * Use Vault's default port in CLI help strings * Remove down migrations * Increase migration file numbers by 1 * Run make migrations * Move migrations from 12 to 10 * Increase Circle CI timeout for acceptance tests * Fix spelling mistake in error messages * ASD cmds for Target and returning credentials to AuthSession request (#1338) * Add Add/Set/Remove commands for libraries on Targets. Return credentials on AuthorizeSession request. Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com> Co-authored-by: Louis Ruch <louisruch@gmail.com> Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com> Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
1642 lines
47 KiB
Go
1642 lines
47 KiB
Go
package vault
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/hashicorp/boundary/internal/credential/vault/store"
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
dbassert "github.com/hashicorp/boundary/internal/db/assert"
|
|
"github.com/hashicorp/boundary/internal/db/timestamp"
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
"github.com/hashicorp/boundary/internal/iam"
|
|
"github.com/hashicorp/boundary/internal/kms"
|
|
"github.com/hashicorp/boundary/internal/oplog"
|
|
"github.com/hashicorp/boundary/internal/scheduler"
|
|
wrapping "github.com/hashicorp/go-kms-wrapping"
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/testing/protocmp"
|
|
)
|
|
|
|
func TestRepository_CreateCredentialStoreResource(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
t.Run("invalid-duplicate-names", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
require.NoError(err)
|
|
require.NotNil(repo)
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
|
|
v := NewTestVaultServer(t)
|
|
_, token := v.CreateToken(t)
|
|
|
|
in, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte(token), WithName("gary"), WithDescription("46"))
|
|
assert.NoError(err)
|
|
require.NotNil(in)
|
|
assert.NotEmpty(in.Name)
|
|
got, err := repo.CreateCredentialStore(ctx, in)
|
|
|
|
require.NoError(err)
|
|
require.NotNil(got)
|
|
assertPublicId(t, CredentialStorePrefix, got.PublicId)
|
|
|
|
assert.NotSame(in, got)
|
|
assert.Equal(in.Name, got.Name)
|
|
assert.Equal(in.Description, got.Description)
|
|
assert.Equal(got.CreateTime, got.UpdateTime)
|
|
|
|
got2, err := repo.CreateCredentialStore(ctx, in)
|
|
assert.Truef(errors.Match(errors.T(errors.NotUnique), err), "want err code: %v got err: %v", errors.NotUnique, err)
|
|
assert.Nil(got2)
|
|
})
|
|
|
|
t.Run("valid-duplicate-names-diff-scopes", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
require.NoError(err)
|
|
require.NotNil(repo)
|
|
org, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
|
|
v := NewTestVaultServer(t)
|
|
|
|
_, token1 := v.CreateToken(t)
|
|
in1, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte(token1), WithName("gary"), WithDescription("46"))
|
|
assert.NoError(err)
|
|
require.NotNil(in1)
|
|
assert.NotEmpty(in1.Name)
|
|
got1, err := repo.CreateCredentialStore(ctx, in1)
|
|
require.NoError(err)
|
|
require.NotNil(got1)
|
|
assertPublicId(t, CredentialStorePrefix, got1.PublicId)
|
|
assert.NotSame(in1, got1)
|
|
assert.Equal(in1.Name, got1.Name)
|
|
assert.Equal(in1.Description, got1.Description)
|
|
assert.Equal(got1.CreateTime, got1.UpdateTime)
|
|
|
|
_, token2 := v.CreateToken(t)
|
|
in2, err := NewCredentialStore(org.GetPublicId(), v.Addr, []byte(token2), WithName("gary"), WithDescription("46"))
|
|
assert.NoError(err)
|
|
require.NotNil(in2)
|
|
assert.NotEmpty(in2.Name)
|
|
in2.ScopeId = org.GetPublicId()
|
|
got2, err := repo.CreateCredentialStore(ctx, in2)
|
|
require.NoError(err)
|
|
require.NotNil(got2)
|
|
assertPublicId(t, CredentialStorePrefix, got2.PublicId)
|
|
assert.NotSame(in2, got2)
|
|
assert.Equal(in2.Name, got2.Name)
|
|
assert.Equal(in2.Description, got2.Description)
|
|
assert.Equal(got2.CreateTime, got2.UpdateTime)
|
|
|
|
assert.Equal(in1.Name, in2.Name)
|
|
assert.Equal(got1.Name, got2.Name)
|
|
})
|
|
}
|
|
|
|
func assertPublicId(t *testing.T, prefix, actual string) {
|
|
t.Helper()
|
|
assert.NotEmpty(t, actual)
|
|
parts := strings.Split(actual, "_")
|
|
assert.Equalf(t, 2, len(parts), "want one '_' in PublicId, got multiple in %q", actual)
|
|
assert.Equalf(t, prefix, parts[0], "PublicId want prefix: %q, got: %q in %q", prefix, parts[0], actual)
|
|
}
|
|
|
|
func TestRepository_CreateCredentialStoreNonResource(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
tests := []struct {
|
|
name string
|
|
tls TestVaultTLS
|
|
tokenOpts []TestOption
|
|
wantErr errors.Code
|
|
}{
|
|
{
|
|
name: "no-tls-valid-token",
|
|
},
|
|
{
|
|
name: "server-tls-valid-token",
|
|
tls: TestServerTLS,
|
|
},
|
|
{
|
|
name: "client-tls-valid-token",
|
|
tls: TestClientTLS,
|
|
},
|
|
{
|
|
name: "token-missing-capabilities",
|
|
tokenOpts: []TestOption{WithPolicies([]string{"default"})},
|
|
wantErr: errors.VaultTokenMissingCapabilities,
|
|
},
|
|
{
|
|
name: "no-tls-token-not-renewable",
|
|
tokenOpts: []TestOption{TestRenewableToken(false)},
|
|
wantErr: errors.VaultTokenNotRenewable,
|
|
},
|
|
{
|
|
name: "no-tls-token-not-orphan",
|
|
tokenOpts: []TestOption{TestOrphanToken(false)},
|
|
wantErr: errors.VaultTokenNotOrphan,
|
|
},
|
|
{
|
|
name: "no-tls-token-not-periodic",
|
|
tokenOpts: []TestOption{TestPeriodicToken(false)},
|
|
wantErr: errors.VaultTokenNotPeriodic,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
require.NoError(err)
|
|
require.NotNil(repo)
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
|
|
v := NewTestVaultServer(t, WithTestVaultTLS(tt.tls))
|
|
_, token := v.CreateToken(t, tt.tokenOpts...)
|
|
|
|
var opts []Option
|
|
if tt.tls == TestServerTLS {
|
|
opts = append(opts, WithCACert(v.CaCert))
|
|
}
|
|
if tt.tls == TestClientTLS {
|
|
opts = append(opts, WithCACert(v.CaCert))
|
|
clientCert, err := NewClientCertificate(v.ClientCert, v.ClientKey)
|
|
require.NoError(err)
|
|
opts = append(opts, WithClientCert(clientCert))
|
|
}
|
|
|
|
credStoreIn, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte(token), opts...)
|
|
assert.NoError(err)
|
|
require.NotNil(credStoreIn)
|
|
got, err := repo.CreateCredentialStore(ctx, credStoreIn)
|
|
|
|
if tt.wantErr != 0 {
|
|
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
|
assert.Nil(got)
|
|
if got != nil {
|
|
err := db.TestVerifyOplog(t, rw, got.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_CREATE), db.WithCreateNotBefore(10*time.Second))
|
|
require.Errorf(err, "should not have found oplog entry for %s", got.PublicId)
|
|
}
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
assert.Empty(credStoreIn.PublicId)
|
|
require.NotNil(got)
|
|
assertPublicId(t, CredentialStorePrefix, got.PublicId)
|
|
assert.NotSame(credStoreIn, got)
|
|
assert.Equal(got.CreateTime, got.UpdateTime)
|
|
assert.NoError(db.TestVerifyOplog(t, rw, got.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_CREATE), db.WithCreateNotBefore(10*time.Second)))
|
|
|
|
outToken := allocToken()
|
|
assert.NoError(rw.LookupWhere(ctx, &outToken, "store_id = ?", got.PublicId))
|
|
|
|
if tt.tls == TestClientTLS {
|
|
outClientCert := allocClientCertificate()
|
|
assert.NoError(rw.LookupWhere(ctx, &outClientCert, "store_id = ?", got.PublicId))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRepository_LookupCredentialStore(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
stores := TestCredentialStores(t, conn, wrapper, prj.PublicId, 2)
|
|
csWithClientCert := stores[0]
|
|
csWithoutClientCert := stores[1]
|
|
|
|
ccert := allocClientCertificate()
|
|
rows, err := rw.Delete(context.Background(), ccert, db.WithWhere("store_id = ?", csWithoutClientCert.GetPublicId()))
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, rows)
|
|
|
|
badId, err := newCredentialStoreId()
|
|
assert.NoError(t, err)
|
|
require.NotNil(t, badId)
|
|
|
|
tests := []struct {
|
|
name string
|
|
id string
|
|
want *CredentialStore
|
|
wantClientCert bool
|
|
wantErr errors.Code
|
|
}{
|
|
{
|
|
name: "valid-with-client-cert",
|
|
id: csWithClientCert.GetPublicId(),
|
|
want: csWithClientCert,
|
|
wantClientCert: true,
|
|
},
|
|
{
|
|
name: "valid-without-client-cert",
|
|
id: csWithoutClientCert.GetPublicId(),
|
|
want: csWithoutClientCert,
|
|
wantClientCert: false,
|
|
},
|
|
{
|
|
name: "empty-public-id",
|
|
id: "",
|
|
wantErr: errors.InvalidParameter,
|
|
},
|
|
{
|
|
name: "not-found",
|
|
id: badId,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
got, err := repo.LookupCredentialStore(ctx, tt.id)
|
|
if tt.wantErr != 0 {
|
|
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
|
assert.Nil(got)
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
|
|
if tt.want == nil {
|
|
assert.Nil(got)
|
|
return
|
|
}
|
|
|
|
assert.NotNil(got)
|
|
assert.NotSame(got, tt.want)
|
|
assert.NotNil(got.Token(), "token")
|
|
|
|
if tt.wantClientCert {
|
|
assert.NotNil(got.ClientCertificate(), "client certificate")
|
|
} else {
|
|
assert.Nil(got.ClientCertificate(), "client certificate")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRepository_UpdateCredentialStore_Attributes(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
changeNamespace := func(n string) func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.Namespace = n
|
|
return cs
|
|
}
|
|
}
|
|
|
|
changeTlsServerName := func(n string) func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.TlsServerName = n
|
|
return cs
|
|
}
|
|
}
|
|
|
|
changeTlsSkipVerify := func(t bool) func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.TlsSkipVerify = t
|
|
return cs
|
|
}
|
|
}
|
|
|
|
changeName := func(n string) func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.Name = n
|
|
return cs
|
|
}
|
|
}
|
|
|
|
changeDescription := func(d string) func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.Description = d
|
|
return cs
|
|
}
|
|
}
|
|
|
|
makeNil := func() func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
makeEmbeddedNil := func() func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
return &CredentialStore{}
|
|
}
|
|
}
|
|
|
|
deletePublicId := func() func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.PublicId = ""
|
|
return cs
|
|
}
|
|
}
|
|
|
|
nonExistentPublicId := func() func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
cs.PublicId = "abcd_OOOOOOOOOO"
|
|
return cs
|
|
}
|
|
}
|
|
|
|
combine := func(fns ...func(cs *CredentialStore) *CredentialStore) func(*CredentialStore) *CredentialStore {
|
|
return func(cs *CredentialStore) *CredentialStore {
|
|
for _, fn := range fns {
|
|
cs = fn(cs)
|
|
}
|
|
return cs
|
|
}
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
orig *CredentialStore
|
|
chgFn func(*CredentialStore) *CredentialStore
|
|
masks []string
|
|
want *CredentialStore
|
|
wantCount int
|
|
wantErr errors.Code
|
|
}{
|
|
{
|
|
name: "nil-credential-store",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{},
|
|
},
|
|
chgFn: makeNil(),
|
|
masks: []string{"Name", "Description"},
|
|
wantErr: errors.InvalidParameter,
|
|
},
|
|
{
|
|
name: "nil-embedded-credential-store",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{},
|
|
},
|
|
chgFn: makeEmbeddedNil(),
|
|
masks: []string{"Name", "Description"},
|
|
wantErr: errors.InvalidParameter,
|
|
},
|
|
{
|
|
name: "no-public-id",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{},
|
|
},
|
|
chgFn: deletePublicId(),
|
|
masks: []string{"Name", "Description"},
|
|
wantErr: errors.InvalidPublicId,
|
|
},
|
|
{
|
|
name: "updating-non-existent-credential-store",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
},
|
|
},
|
|
chgFn: combine(nonExistentPublicId(), changeName("test-update-name-repo")),
|
|
masks: []string{"Name"},
|
|
wantErr: errors.RecordNotFound,
|
|
},
|
|
{
|
|
name: "empty-field-mask",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
},
|
|
},
|
|
chgFn: changeName("test-update-name-repo"),
|
|
wantErr: errors.EmptyFieldMask,
|
|
},
|
|
{
|
|
name: "read-only-fields-in-field-mask",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
},
|
|
},
|
|
chgFn: changeName("test-update-name-repo"),
|
|
masks: []string{"PublicId", "CreateTime", "UpdateTime", "ScopeId"},
|
|
wantErr: errors.InvalidFieldMask,
|
|
},
|
|
{
|
|
name: "unknown-field-in-field-mask",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
},
|
|
},
|
|
chgFn: changeName("test-update-name-repo"),
|
|
masks: []string{"Bilbo"},
|
|
wantErr: errors.InvalidFieldMask,
|
|
},
|
|
{
|
|
name: "change-name",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
},
|
|
},
|
|
chgFn: changeName("test-update-name-repo"),
|
|
masks: []string{"Name"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-update-name-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "change-description",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
chgFn: changeDescription("test-update-description-repo"),
|
|
masks: []string{"Description"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Description: "test-update-description-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "change-name-and-description",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
chgFn: combine(changeDescription("test-update-description-repo"), changeName("test-update-name-repo")),
|
|
masks: []string{"Name", "Description"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-update-name-repo",
|
|
Description: "test-update-description-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "delete-name",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
masks: []string{"Name"},
|
|
chgFn: combine(changeDescription("test-update-description-repo"), changeName("")),
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "delete-description",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
masks: []string{"Description"},
|
|
chgFn: combine(changeDescription(""), changeName("test-update-name-repo")),
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "do-not-delete-name",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
masks: []string{"Description"},
|
|
chgFn: combine(changeDescription("test-update-description-repo"), changeName("")),
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
Description: "test-update-description-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "do-not-delete-description",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
masks: []string{"Name"},
|
|
chgFn: combine(changeDescription(""), changeName("test-update-name-repo")),
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-update-name-repo",
|
|
Description: "test-description-repo",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "change-namespace",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Namespace: "test-namespace",
|
|
},
|
|
},
|
|
chgFn: changeNamespace("test-update-namespace"),
|
|
masks: []string{"Namespace"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Namespace: "test-update-namespace",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "delete-namespace",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
Namespace: "test-namespace",
|
|
},
|
|
},
|
|
chgFn: changeNamespace(""),
|
|
masks: []string{"Namespace"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "change-tls-server-name",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsServerName: "tls-server-name",
|
|
},
|
|
},
|
|
chgFn: changeTlsServerName("tls-server-name-update"),
|
|
masks: []string{"TlsServerName"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsServerName: "tls-server-name-update",
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "delete-tls-server-name",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsServerName: "tls-server-name",
|
|
},
|
|
},
|
|
chgFn: changeTlsServerName(""),
|
|
masks: []string{"TlsServerName"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "tls-skip-verify-false2true",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: false,
|
|
},
|
|
},
|
|
chgFn: changeTlsSkipVerify(true),
|
|
masks: []string{"TlsSkipVerify"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: true,
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "tls-skip-verify-true2false",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: true,
|
|
},
|
|
},
|
|
chgFn: changeTlsSkipVerify(false),
|
|
masks: []string{"TlsSkipVerify"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: false,
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "tls-skip-verify-false2false",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: false,
|
|
},
|
|
},
|
|
chgFn: changeTlsSkipVerify(false),
|
|
masks: []string{"TlsSkipVerify"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: false,
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "tls-skip-verify-true2true",
|
|
orig: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: true,
|
|
},
|
|
},
|
|
chgFn: changeTlsSkipVerify(true),
|
|
masks: []string{"TlsSkipVerify"},
|
|
want: &CredentialStore{
|
|
CredentialStore: &store.CredentialStore{
|
|
TlsSkipVerify: true,
|
|
},
|
|
},
|
|
wantCount: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
tt.orig.ScopeId = prj.GetPublicId()
|
|
|
|
vs := NewTestVaultServer(t)
|
|
|
|
tt.orig.VaultAddress = vs.Addr
|
|
if tt.want != nil && tt.want.VaultAddress == "" {
|
|
tt.want.VaultAddress = vs.Addr
|
|
}
|
|
|
|
_, token := vs.CreateToken(t)
|
|
tt.orig.inputToken = []byte(token)
|
|
|
|
orig, err := repo.CreateCredentialStore(ctx, tt.orig)
|
|
assert.NoError(err)
|
|
require.NotNil(orig)
|
|
|
|
if tt.chgFn != nil {
|
|
orig = tt.chgFn(orig)
|
|
}
|
|
got, gotCount, err := repo.UpdateCredentialStore(ctx, orig, 1, tt.masks)
|
|
if tt.wantErr != 0 {
|
|
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
|
assert.Equal(tt.wantCount, gotCount, "row count")
|
|
assert.Nil(got)
|
|
return
|
|
}
|
|
assert.NoError(err)
|
|
assert.Empty(tt.orig.PublicId)
|
|
require.NotNil(got)
|
|
assertPublicId(t, CredentialStorePrefix, got.PublicId)
|
|
assert.Equal(tt.wantCount, gotCount, "row count")
|
|
assert.NotSame(tt.orig, got)
|
|
assert.Equal(tt.orig.ScopeId, got.ScopeId)
|
|
dbassert := dbassert.New(t, conn.DB())
|
|
if tt.want.Name == "" {
|
|
dbassert.IsNull(got, "name")
|
|
} else {
|
|
assert.Equal(tt.want.Name, got.Name)
|
|
}
|
|
|
|
if tt.want.Description == "" {
|
|
dbassert.IsNull(got, "description")
|
|
} else {
|
|
assert.Equal(tt.want.Description, got.Description)
|
|
}
|
|
|
|
if tt.want.Namespace == "" {
|
|
dbassert.IsNull(got, "namespace")
|
|
} else {
|
|
assert.Equal(tt.want.Namespace, got.Namespace)
|
|
}
|
|
|
|
if tt.want.TlsServerName == "" {
|
|
dbassert.IsNull(got, "TlsServerName")
|
|
} else {
|
|
assert.Equal(tt.want.TlsServerName, got.TlsServerName)
|
|
}
|
|
|
|
assert.Equal(tt.want.TlsSkipVerify, got.TlsSkipVerify)
|
|
|
|
assert.Equal(tt.want.VaultAddress, got.VaultAddress)
|
|
|
|
if tt.wantCount > 0 {
|
|
assert.NoError(db.TestVerifyOplog(t, rw, got.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_UPDATE), db.WithCreateNotBefore(10*time.Second)))
|
|
}
|
|
})
|
|
}
|
|
|
|
t.Run("change-vault-address", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
vs := NewTestVaultServer(t)
|
|
_, token := vs.CreateToken(t)
|
|
|
|
u, err := url.Parse(vs.Addr)
|
|
require.NoError(err)
|
|
_, port, err := net.SplitHostPort(u.Host)
|
|
require.NoError(err)
|
|
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
in := &CredentialStore{
|
|
inputToken: []byte(token),
|
|
CredentialStore: &store.CredentialStore{
|
|
ScopeId: prj.GetPublicId(),
|
|
VaultAddress: fmt.Sprintf("%v://127.0.0.1:%s", u.Scheme, port),
|
|
},
|
|
}
|
|
|
|
orig, err := repo.CreateCredentialStore(ctx, in)
|
|
assert.NoError(err)
|
|
require.NotNil(orig)
|
|
|
|
// Change Address 127.0.0.1:port -> localhost:port should work
|
|
orig.VaultAddress = fmt.Sprintf("%v://localhost:%s", u.Scheme, port)
|
|
got, gotCount, err := repo.UpdateCredentialStore(ctx, orig, 1, []string{vaultAddressField})
|
|
assert.NoError(err)
|
|
assert.Equal(1, gotCount, "count of updated records")
|
|
require.NotNil(got)
|
|
assert.Equal(orig.VaultAddress, got.VaultAddress)
|
|
|
|
// Update to new address should fail because current token not valid on new address
|
|
origAddr := orig.VaultAddress
|
|
orig.VaultAddress = "https://vault2.nowhere.com"
|
|
got, gotCount, err = repo.UpdateCredentialStore(ctx, orig, 2, []string{vaultAddressField})
|
|
assert.Error(err)
|
|
require.Nil(got)
|
|
require.Equal(0, gotCount)
|
|
|
|
cs, err := repo.LookupCredentialStore(ctx, orig.PublicId)
|
|
require.NoError(err)
|
|
assert.Equal(origAddr, cs.VaultAddress)
|
|
})
|
|
|
|
t.Run("change-ca-cert", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
vs := NewTestVaultServer(t, WithTestVaultTLS(TestServerTLS))
|
|
|
|
_, token := vs.CreateToken(t)
|
|
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
in := &CredentialStore{
|
|
inputToken: []byte(token),
|
|
CredentialStore: &store.CredentialStore{
|
|
ScopeId: prj.GetPublicId(),
|
|
VaultAddress: vs.Addr,
|
|
CaCert: vs.CaCert,
|
|
},
|
|
}
|
|
|
|
orig, err := repo.CreateCredentialStore(ctx, in)
|
|
assert.NoError(err)
|
|
require.NotNil(orig)
|
|
assert.Equal(vs.CaCert, orig.CaCert)
|
|
|
|
// Change CA Cert
|
|
orig.CaCert = vs.ServerCert
|
|
got1, gotCount1, err := repo.UpdateCredentialStore(ctx, orig, 1, []string{"CaCert"})
|
|
assert.NoError(err)
|
|
assert.Equal(1, gotCount1, "count of updated records")
|
|
require.NotNil(got1)
|
|
assert.Equal(vs.ServerCert, got1.CaCert)
|
|
|
|
// Delete CA Cert
|
|
orig.CaCert = nil
|
|
got2, gotCount2, err := repo.UpdateCredentialStore(ctx, orig, 2, []string{"CaCert"})
|
|
assert.NoError(err)
|
|
assert.Equal(1, gotCount2, "count of updated records")
|
|
require.NotNil(got2)
|
|
assert.Nil(got2.CaCert)
|
|
|
|
dbassert := dbassert.New(t, conn.DB())
|
|
dbassert.IsNull(got2, "CaCert")
|
|
})
|
|
|
|
t.Run("invalid-duplicate-names", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
name := "test-dup-name"
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
css := TestCredentialStores(t, conn, wrapper, prj.PublicId, 2)
|
|
|
|
csA, csB := css[0], css[1]
|
|
|
|
csA.Name = name
|
|
got1, gotCount1, err := repo.UpdateCredentialStore(ctx, csA, 1, []string{"Name"})
|
|
assert.NoError(err)
|
|
require.NotNil(got1)
|
|
assert.Equal(name, got1.Name)
|
|
assert.Equal(1, gotCount1, "row count")
|
|
assert.NoError(db.TestVerifyOplog(t, rw, csA.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_UPDATE), db.WithCreateNotBefore(10*time.Second)))
|
|
|
|
csB.Name = name
|
|
got2, gotCount2, err := repo.UpdateCredentialStore(ctx, csB, 1, []string{"Name"})
|
|
assert.Truef(errors.Match(errors.T(errors.NotUnique), err), "want err code: %v got err: %v", errors.NotUnique, err)
|
|
assert.Nil(got2)
|
|
assert.Equal(db.NoRowsAffected, gotCount2, "row count")
|
|
})
|
|
|
|
t.Run("valid-duplicate-names-diff-scopes", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
vs := NewTestVaultServer(t)
|
|
|
|
_, token1 := vs.CreateToken(t)
|
|
_, token2 := vs.CreateToken(t)
|
|
|
|
org, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
in := &CredentialStore{
|
|
inputToken: []byte(token1),
|
|
CredentialStore: &store.CredentialStore{
|
|
Name: "test-name-repo",
|
|
VaultAddress: vs.Addr,
|
|
},
|
|
}
|
|
in2 := in.clone()
|
|
in2.inputToken = []byte(token2)
|
|
|
|
in.ScopeId = prj.GetPublicId()
|
|
got, err := repo.CreateCredentialStore(ctx, in)
|
|
assert.NoError(err)
|
|
require.NotNil(got)
|
|
assertPublicId(t, CredentialStorePrefix, got.PublicId)
|
|
assert.NotSame(in, got)
|
|
assert.Equal(in.Name, got.Name)
|
|
assert.Equal(in.Description, got.Description)
|
|
|
|
in2.ScopeId = org.GetPublicId()
|
|
in2.Name = "first-name"
|
|
got2, err := repo.CreateCredentialStore(ctx, in2)
|
|
assert.NoError(err)
|
|
require.NotNil(got2)
|
|
got2.Name = got.Name
|
|
got3, gotCount3, err := repo.UpdateCredentialStore(ctx, got2, 1, []string{"Name"})
|
|
assert.NoError(err)
|
|
require.NotNil(got3)
|
|
assert.NotSame(got2, got3)
|
|
assert.Equal(got.Name, got3.Name)
|
|
assert.Equal(got2.Description, got3.Description)
|
|
assert.Equal(1, gotCount3, "row count")
|
|
})
|
|
|
|
t.Run("change-scope-id", func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
iamRepo := iam.TestRepo(t, conn, wrapper)
|
|
_, prj1 := iam.TestScopes(t, iamRepo)
|
|
_, prj2 := iam.TestScopes(t, iamRepo)
|
|
csA, csB := TestCredentialStores(t, conn, wrapper, prj1.PublicId, 1)[0], TestCredentialStores(t, conn, wrapper, prj2.PublicId, 1)[0]
|
|
assert.NotEqual(csA.ScopeId, csB.ScopeId)
|
|
orig := csA.clone()
|
|
|
|
csA.ScopeId = csB.ScopeId
|
|
assert.Equal(csA.ScopeId, csB.ScopeId)
|
|
|
|
got1, gotCount1, err := repo.UpdateCredentialStore(ctx, csA, 1, []string{"Name"})
|
|
|
|
assert.NoError(err)
|
|
require.NotNil(got1)
|
|
assert.Equal(orig.ScopeId, got1.ScopeId)
|
|
assert.Equal(1, gotCount1, "row count")
|
|
})
|
|
}
|
|
|
|
func TestRepository_UpdateCredentialStore_VaultToken(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
tests := []struct {
|
|
name string
|
|
newTokenOpts []TestOption
|
|
wantOldTokenStatus TokenStatus
|
|
wantCount int
|
|
wantErr errors.Code
|
|
}{
|
|
{
|
|
name: "valid",
|
|
wantOldTokenStatus: MaintainingToken,
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "token-missing-capabilities",
|
|
newTokenOpts: []TestOption{WithPolicies([]string{"default"})},
|
|
wantErr: errors.VaultTokenMissingCapabilities,
|
|
},
|
|
{
|
|
name: "token-not-renewable",
|
|
newTokenOpts: []TestOption{TestRenewableToken(false)},
|
|
wantErr: errors.VaultTokenNotRenewable,
|
|
},
|
|
{
|
|
name: "token-not-orphan",
|
|
newTokenOpts: []TestOption{TestOrphanToken(false)},
|
|
wantErr: errors.VaultTokenNotOrphan,
|
|
},
|
|
{
|
|
name: "token-not-periodic",
|
|
newTokenOpts: []TestOption{TestPeriodicToken(false)},
|
|
wantErr: errors.VaultTokenNotPeriodic,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
require.NoError(err)
|
|
require.NotNil(repo)
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
|
|
v := NewTestVaultServer(t)
|
|
_, origToken := v.CreateToken(t)
|
|
|
|
// create
|
|
origIn, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte(origToken))
|
|
assert.NoError(err)
|
|
require.NotNil(origIn)
|
|
|
|
orig, err := repo.CreateCredentialStore(ctx, origIn)
|
|
assert.NoError(err)
|
|
require.NotNil(orig)
|
|
|
|
// update
|
|
_, updateToken := v.CreateToken(t, tt.newTokenOpts...)
|
|
|
|
updateIn, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte(updateToken))
|
|
assert.NoError(err)
|
|
require.NotNil(updateIn)
|
|
updateIn.PublicId = orig.GetPublicId()
|
|
got, gotCount, err := repo.UpdateCredentialStore(ctx, updateIn, 1, []string{"Token"})
|
|
if tt.wantErr != 0 {
|
|
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
|
assert.Equal(tt.wantCount, gotCount, "row count")
|
|
assert.Nil(got)
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
assert.Equal(tt.wantCount, gotCount)
|
|
assert.NotNil(got)
|
|
|
|
var tokens []*Token
|
|
require.NoError(rw.SearchWhere(ctx, &tokens, "store_id = ?", []interface{}{orig.GetPublicId()}))
|
|
assert.Len(tokens, 2)
|
|
assert.Equal(string(tt.wantOldTokenStatus), tokens[0].Status)
|
|
|
|
lookup, err := repo.LookupCredentialStore(ctx, orig.GetPublicId())
|
|
assert.NoError(err)
|
|
require.NotNil(lookup)
|
|
require.NotNil(orig.outputToken)
|
|
require.NotNil(got.outputToken)
|
|
assert.NotEqual(orig.outputToken.TokenHmac, got.outputToken.TokenHmac)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRepository_UpdateCredentialStore_ClientCert(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
|
|
existingClientCert := func(t *testing.T, v *TestVaultServer) *ClientCertificate {
|
|
clientCert, err := NewClientCertificate(v.ClientCert, v.ClientKey)
|
|
require.NoError(t, err)
|
|
return clientCert
|
|
}
|
|
|
|
newClientCert := func(t *testing.T, v *TestVaultServer) *ClientCertificate {
|
|
cb := testClientCert(t, v.clientCertBundle.CA)
|
|
return cb.Cert.ClientCertificate(t)
|
|
}
|
|
|
|
// newClientCertFromServerCA is useful for when v is configured with
|
|
// TestServerTLS. It uses the server CA to create a new client
|
|
// certificate since the v will not have a clientCertBundle.
|
|
newClientCertFromServerCA := func(t *testing.T, v *TestVaultServer) *ClientCertificate {
|
|
cb := testClientCert(t, v.serverCertBundle.CA)
|
|
return cb.Cert.ClientCertificate(t)
|
|
}
|
|
|
|
nilClientCert := func(t *testing.T, v *TestVaultServer) *ClientCertificate {
|
|
return nil
|
|
}
|
|
|
|
assertUpdated := func(t *testing.T, org, updated *ClientCertificate, ps *privateStore) {
|
|
assert.Equal(t, updated.Certificate, ps.ClientCert, "updated certificate")
|
|
assert.Equal(t, updated.CertificateKey, []byte(ps.ClientKey), "updated certificate key")
|
|
}
|
|
|
|
assertDeleted := func(t *testing.T, org, updated *ClientCertificate, ps *privateStore) {
|
|
assert.Nil(t, updated, "updated certificate")
|
|
assert.Nil(t, ps.ClientCert, "ps ClientCert")
|
|
assert.Nil(t, ps.ClientKey, "ps ClientKey")
|
|
assert.Nil(t, ps.CtClientKey, "ps CtClientKey")
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
tls TestVaultTLS
|
|
origFn func(t *testing.T, v *TestVaultServer) *ClientCertificate
|
|
updateFn func(t *testing.T, v *TestVaultServer) *ClientCertificate
|
|
wantFn func(t *testing.T, org, updated *ClientCertificate, ps *privateStore)
|
|
wantCount int
|
|
wantErr errors.Code
|
|
}{
|
|
{
|
|
name: "ClientCert-to-ClientCert",
|
|
tls: TestClientTLS,
|
|
origFn: existingClientCert,
|
|
updateFn: newClientCert,
|
|
wantFn: assertUpdated,
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "ClientCert-to-null",
|
|
tls: TestClientTLS,
|
|
origFn: existingClientCert,
|
|
updateFn: nilClientCert,
|
|
wantFn: assertDeleted,
|
|
wantCount: 1,
|
|
},
|
|
{
|
|
name: "null-to-ClientCert",
|
|
tls: TestServerTLS,
|
|
origFn: nilClientCert,
|
|
updateFn: newClientCertFromServerCA,
|
|
wantFn: assertUpdated,
|
|
wantCount: 1,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert, require := assert.New(t), require.New(t)
|
|
ctx := context.Background()
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
require.NoError(err)
|
|
require.NotNil(repo)
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
|
|
v := NewTestVaultServer(t, WithTestVaultTLS(tt.tls))
|
|
|
|
var opts []Option
|
|
if tt.tls == TestServerTLS {
|
|
opts = append(opts, WithCACert(v.CaCert))
|
|
}
|
|
if tt.tls == TestClientTLS {
|
|
opts = append(opts, WithCACert(v.CaCert))
|
|
clientCert, err := NewClientCertificate(v.ClientCert, v.ClientKey)
|
|
require.NoError(err)
|
|
opts = append(opts, WithClientCert(clientCert))
|
|
}
|
|
|
|
_, origToken := v.CreateToken(t)
|
|
origClientCert := tt.origFn(t, v)
|
|
opts = append(opts, WithClientCert(origClientCert))
|
|
|
|
// create
|
|
origIn, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte(origToken), opts...)
|
|
assert.NoError(err)
|
|
require.NotNil(origIn)
|
|
|
|
orig, err := repo.CreateCredentialStore(ctx, origIn)
|
|
assert.NoError(err)
|
|
require.NotNil(orig)
|
|
|
|
// update
|
|
updateClientCert := tt.updateFn(t, v)
|
|
|
|
updateIn, err := NewCredentialStore(prj.GetPublicId(), v.Addr, []byte("ignore"), WithClientCert(updateClientCert))
|
|
assert.NoError(err)
|
|
require.NotNil(updateIn)
|
|
updateIn.PublicId = orig.GetPublicId()
|
|
got, gotCount, err := repo.UpdateCredentialStore(ctx, updateIn, 1, []string{"Certificate", "CertificateKey"})
|
|
assert.Equal(tt.wantCount, gotCount, "row count")
|
|
if tt.wantErr != 0 {
|
|
assert.Truef(errors.Match(errors.T(tt.wantErr), err), "want err: %q got: %q", tt.wantErr, err)
|
|
assert.Nil(got)
|
|
return
|
|
}
|
|
require.NoError(err)
|
|
assert.NotNil(got)
|
|
|
|
ps, err := repo.lookupPrivateStore(ctx, orig.GetPublicId())
|
|
require.NoError(err)
|
|
tt.wantFn(t, origClientCert, updateClientCert, ps)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRepository_ListCredentialStores_Multiple_Scopes(t *testing.T) {
|
|
t.Parallel()
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
rw := db.New(conn)
|
|
wrapper := db.TestWrapper(t)
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
|
|
assert, require := assert.New(t), require.New(t)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
assert.NoError(err)
|
|
require.NotNil(repo)
|
|
|
|
const numPerScope = 10
|
|
var prjs []string
|
|
var total int
|
|
for i := 0; i < numPerScope; i++ {
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
prjs = append(prjs, prj.GetPublicId())
|
|
TestCredentialStores(t, conn, wrapper, prj.GetPublicId(), numPerScope)
|
|
total += numPerScope
|
|
}
|
|
|
|
got, err := repo.ListCredentialStores(context.Background(), prjs)
|
|
require.NoError(err)
|
|
assert.Equal(total, len(got))
|
|
}
|
|
|
|
func TestRepository_DeleteCredentialStore(t *testing.T) {
|
|
type tokenCount struct {
|
|
current, maintaining int
|
|
revoke int
|
|
revoked, expired int
|
|
}
|
|
|
|
type tokenMap map[string]*tokenCount
|
|
|
|
type setupFn func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository)
|
|
|
|
baseSetup := func(t *testing.T, conn *gorm.DB) (wrapper wrapping.Wrapper, repo *Repository, scopeId string) {
|
|
wrapper = db.TestWrapper(t)
|
|
kms := kms.TestKms(t, conn, wrapper)
|
|
sche := scheduler.TestScheduler(t, conn, wrapper)
|
|
rw := db.New(conn)
|
|
repo, err := NewRepository(rw, rw, kms, sche)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, repo)
|
|
|
|
_, prj := iam.TestScopes(t, iam.TestRepo(t, conn, wrapper))
|
|
scopeId = prj.GetPublicId()
|
|
return
|
|
}
|
|
|
|
testStores := func(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, tokens tokenMap, scopeId string, count int) ([]*CredentialStore, tokenMap) {
|
|
if tokens == nil {
|
|
tokens = make(tokenMap)
|
|
}
|
|
css := TestCredentialStores(t, conn, wrapper, scopeId, count)
|
|
for _, cs := range css {
|
|
storeId := cs.GetPublicId()
|
|
tokens[storeId] = new(tokenCount)
|
|
tokens[storeId].current = 1
|
|
}
|
|
return css, tokens
|
|
}
|
|
|
|
makeMaintainingTokens := func(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, tokens tokenMap, scopeId, storeId string, count int) tokenMap {
|
|
testTokens(t, conn, wrapper, scopeId, storeId, count)
|
|
tokens[storeId].maintaining = count
|
|
return tokens
|
|
}
|
|
|
|
makeRevokedTokens := func(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, tokens tokenMap, scopeId, storeId string, count int) tokenMap {
|
|
require.NotNil(t, tokens)
|
|
const query = `
|
|
update credential_vault_token
|
|
set status = 'revoked'
|
|
where store_id = $1
|
|
and status = 'current';
|
|
`
|
|
t.Helper()
|
|
rw := db.New(conn)
|
|
ctx := context.Background()
|
|
|
|
for i := 0; i < count; i++ {
|
|
rows, err := rw.Exec(ctx, query, []interface{}{storeId})
|
|
require.Equal(t, 1, rows)
|
|
require.NoError(t, err)
|
|
tokens[storeId].revoked++
|
|
testTokens(t, conn, wrapper, scopeId, storeId, 1)
|
|
}
|
|
return tokens
|
|
}
|
|
|
|
makeExpiredTokens := func(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, tokens tokenMap, scopeId, storeId string, count int) tokenMap {
|
|
require.NotNil(t, tokens)
|
|
const query = `
|
|
update credential_vault_token
|
|
set status = 'expired'
|
|
where store_id = $1
|
|
and status = 'current';
|
|
`
|
|
t.Helper()
|
|
rw := db.New(conn)
|
|
ctx := context.Background()
|
|
|
|
for i := 0; i < count; i++ {
|
|
rows, err := rw.Exec(ctx, query, []interface{}{storeId})
|
|
require.Equal(t, 1, rows)
|
|
require.NoError(t, err)
|
|
tokens[storeId].expired++
|
|
testTokens(t, conn, wrapper, scopeId, storeId, 1)
|
|
}
|
|
return tokens
|
|
}
|
|
|
|
assertTokens := func(t *testing.T, conn *gorm.DB, want tokenMap) {
|
|
const query = `
|
|
select store_id, status, count(token_hmac)
|
|
from credential_vault_token
|
|
group by store_id, status;
|
|
`
|
|
|
|
rw := db.New(conn)
|
|
got := make(tokenMap, len(want))
|
|
for id := range want {
|
|
got[id] = new(tokenCount)
|
|
}
|
|
|
|
var (
|
|
id string
|
|
status string
|
|
count int
|
|
)
|
|
|
|
ctx := context.Background()
|
|
rows, err := rw.Query(ctx, query, nil)
|
|
require.NoError(t, err)
|
|
defer rows.Close()
|
|
for rows.Next() {
|
|
require.NoError(t, rows.Scan(&id, &status, &count))
|
|
switch status {
|
|
case "current":
|
|
got[id].current = count
|
|
case "maintaining":
|
|
got[id].maintaining = count
|
|
case "revoke":
|
|
got[id].revoke = count
|
|
case "revoked":
|
|
got[id].revoked = count
|
|
case "expired":
|
|
got[id].expired = count
|
|
default:
|
|
assert.Failf(t, "Unexpected status: %s", status)
|
|
}
|
|
}
|
|
require.NoError(t, rows.Err())
|
|
assert.Equal(t, want, got)
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
setup setupFn
|
|
}{
|
|
{
|
|
name: "simple",
|
|
setup: func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository) {
|
|
wrapper, repo, scopeId := baseSetup(t, conn)
|
|
css, tokens := testStores(t, conn, wrapper, nil, scopeId, 1)
|
|
cs := css[0]
|
|
storeId = cs.GetPublicId()
|
|
return
|
|
},
|
|
},
|
|
{
|
|
name: "with-libraries",
|
|
setup: func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository) {
|
|
wrapper, repo, scopeId := baseSetup(t, conn)
|
|
css, tokens := testStores(t, conn, wrapper, nil, scopeId, 1)
|
|
cs := css[0]
|
|
storeId = cs.GetPublicId()
|
|
|
|
libs = TestCredentialLibraries(t, conn, wrapper, storeId, 4)
|
|
return
|
|
},
|
|
},
|
|
{
|
|
name: "with-maintaining-tokens",
|
|
setup: func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository) {
|
|
wrapper, repo, scopeId := baseSetup(t, conn)
|
|
css, tokens := testStores(t, conn, wrapper, nil, scopeId, 1)
|
|
cs := css[0]
|
|
storeId = cs.GetPublicId()
|
|
|
|
libs = TestCredentialLibraries(t, conn, wrapper, storeId, 4)
|
|
tokens = makeMaintainingTokens(t, conn, wrapper, tokens, scopeId, storeId, 4)
|
|
return
|
|
},
|
|
},
|
|
{
|
|
name: "with-revoked-tokens",
|
|
setup: func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository) {
|
|
wrapper, repo, scopeId := baseSetup(t, conn)
|
|
css, tokens := testStores(t, conn, wrapper, nil, scopeId, 1)
|
|
cs := css[0]
|
|
storeId = cs.GetPublicId()
|
|
|
|
libs = TestCredentialLibraries(t, conn, wrapper, storeId, 4)
|
|
tokens = makeRevokedTokens(t, conn, wrapper, tokens, scopeId, storeId, 4)
|
|
return
|
|
},
|
|
},
|
|
{
|
|
name: "with-expired-tokens",
|
|
setup: func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository) {
|
|
wrapper, repo, scopeId := baseSetup(t, conn)
|
|
css, tokens := testStores(t, conn, wrapper, nil, scopeId, 1)
|
|
cs := css[0]
|
|
storeId = cs.GetPublicId()
|
|
|
|
libs = TestCredentialLibraries(t, conn, wrapper, storeId, 4)
|
|
tokens = makeExpiredTokens(t, conn, wrapper, tokens, scopeId, storeId, 4)
|
|
return
|
|
},
|
|
},
|
|
{
|
|
name: "with-all-token-statuses",
|
|
setup: func(t *testing.T, conn *gorm.DB) (storeId string, libs []*CredentialLibrary, tokens tokenMap, repo *Repository) {
|
|
wrapper, repo, scopeId := baseSetup(t, conn)
|
|
css, tokens := testStores(t, conn, wrapper, nil, scopeId, 1)
|
|
cs := css[0]
|
|
storeId = cs.GetPublicId()
|
|
|
|
libs = TestCredentialLibraries(t, conn, wrapper, storeId, 4)
|
|
tokens = makeMaintainingTokens(t, conn, wrapper, tokens, scopeId, storeId, 2)
|
|
tokens = makeRevokedTokens(t, conn, wrapper, tokens, scopeId, storeId, 3)
|
|
tokens = makeExpiredTokens(t, conn, wrapper, tokens, scopeId, storeId, 5)
|
|
return
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
assert, require := assert.New(t), require.New(t)
|
|
conn, _ := db.TestSetup(t, "postgres")
|
|
ctx := context.Background()
|
|
|
|
storeId, actualLibs, tokens, repo := tt.setup(t, conn)
|
|
|
|
var credStore *CredentialStore
|
|
var scopeId string
|
|
|
|
assertTokens(t, conn, tokens)
|
|
{
|
|
lookup, err := repo.LookupCredentialStore(ctx, storeId)
|
|
assert.NoError(err)
|
|
require.NotNil(lookup)
|
|
assert.Nil(lookup.DeleteTime)
|
|
scopeId = lookup.GetScopeId()
|
|
credStore = lookup
|
|
}
|
|
|
|
{
|
|
stores, err := repo.ListCredentialStores(ctx, []string{scopeId})
|
|
assert.NoError(err)
|
|
assert.NotEmpty(stores)
|
|
var storeIds []string
|
|
for _, v := range stores {
|
|
storeIds = append(storeIds, v.GetPublicId())
|
|
}
|
|
assert.Contains(storeIds, storeId)
|
|
}
|
|
|
|
{
|
|
libs, err := repo.ListCredentialLibraries(ctx, storeId)
|
|
assert.NoError(err)
|
|
assert.Len(libs, len(actualLibs))
|
|
}
|
|
|
|
{
|
|
privStores, err := repo.listRevokePrivateStores(ctx)
|
|
assert.NoError(err)
|
|
assert.Empty(privStores)
|
|
}
|
|
|
|
// verify updating the credential store works
|
|
{
|
|
masks := []string{"Name"}
|
|
credStore.Name = "test name"
|
|
updatedStore, updatedCount, err := repo.UpdateCredentialStore(ctx, credStore, credStore.Version, masks)
|
|
assert.NoError(err)
|
|
assert.Equal(1, updatedCount)
|
|
assert.NotNil(updatedStore)
|
|
credStore = updatedStore
|
|
}
|
|
|
|
// delete
|
|
{
|
|
deletedCount, err := repo.DeleteCredentialStore(ctx, storeId)
|
|
assert.NoError(err)
|
|
assert.Equal(1, deletedCount)
|
|
}
|
|
|
|
// All current and maintaining tokens should now be in the
|
|
// 'revoke' status. The status of any other tokens should be
|
|
// unchanged.
|
|
tokens[storeId].revoke = tokens[storeId].current + tokens[storeId].maintaining
|
|
tokens[storeId].current, tokens[storeId].maintaining = 0, 0
|
|
assertTokens(t, conn, tokens)
|
|
|
|
// should not be in lookup
|
|
{
|
|
lookup, err := repo.LookupCredentialStore(ctx, storeId)
|
|
assert.NoError(err)
|
|
assert.Nil(lookup)
|
|
}
|
|
|
|
// should not be in list
|
|
{
|
|
stores, err := repo.ListCredentialStores(ctx, []string{scopeId})
|
|
assert.NoError(err)
|
|
var storeIds []string
|
|
for _, v := range stores {
|
|
storeIds = append(storeIds, v.GetPublicId())
|
|
}
|
|
assert.NotContains(storeIds, storeId)
|
|
}
|
|
|
|
// libraries should be empty
|
|
{
|
|
libs, err := repo.ListCredentialLibraries(ctx, storeId)
|
|
assert.NoError(err)
|
|
assert.Empty(libs)
|
|
}
|
|
|
|
// creating a library should fail
|
|
{
|
|
newLib := &CredentialLibrary{
|
|
CredentialLibrary: &store.CredentialLibrary{
|
|
StoreId: storeId,
|
|
HttpMethod: "GET",
|
|
VaultPath: "/some/path",
|
|
},
|
|
}
|
|
lib, err := repo.CreateCredentialLibrary(ctx, scopeId, newLib)
|
|
assert.Error(err)
|
|
assert.Nil(lib)
|
|
}
|
|
|
|
var deleteTime *timestamp.Timestamp
|
|
// still in privateStore delete time set
|
|
{
|
|
privStores, err := repo.listRevokePrivateStores(ctx)
|
|
assert.NoError(err)
|
|
var privateStore *privateStore
|
|
var storeIds []string
|
|
for _, v := range privStores {
|
|
id := v.GetPublicId()
|
|
storeIds = append(storeIds, id)
|
|
if id == storeId {
|
|
privateStore = v
|
|
}
|
|
}
|
|
assert.Contains(storeIds, storeId)
|
|
require.NotNil(privateStore)
|
|
if assert.NotNil(privateStore.DeleteTime) {
|
|
deleteTime = privateStore.DeleteTime
|
|
}
|
|
}
|
|
|
|
// updating a soft deleted credential store should not work
|
|
{
|
|
masks := []string{"Name"}
|
|
credStore.Name = "second test name"
|
|
updatedStore, updatedCount, err := repo.UpdateCredentialStore(ctx, credStore, credStore.Version, masks)
|
|
assert.Error(err)
|
|
assert.Equal(0, updatedCount)
|
|
assert.Nil(updatedStore)
|
|
}
|
|
|
|
// calling delete again should not change anything
|
|
{
|
|
deleteCount, err := repo.DeleteCredentialStore(ctx, storeId)
|
|
assert.NoError(err)
|
|
assert.Equal(0, deleteCount)
|
|
}
|
|
|
|
// still in privateStore delete time should not change
|
|
{
|
|
privStores, err := repo.listRevokePrivateStores(ctx)
|
|
assert.NoError(err)
|
|
var privateStore *privateStore
|
|
var storeIds []string
|
|
for _, v := range privStores {
|
|
id := v.GetPublicId()
|
|
storeIds = append(storeIds, id)
|
|
if id == storeId {
|
|
privateStore = v
|
|
}
|
|
}
|
|
assert.Contains(storeIds, storeId)
|
|
require.NotNil(privateStore)
|
|
assert.Empty(cmp.Diff(deleteTime, privateStore.DeleteTime, protocmp.Transform()))
|
|
}
|
|
})
|
|
}
|
|
}
|