feat(credentials): Refactor credential purposes (#2260)
* feat(credentials): Refactor credential purposes * Application credentials have been refactored to Brokered credentials * Egress credentials have been refactored to Injected Application credentials Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com>
This commit is contained in:
1 parent
271cc8f781
commit
a17e973712
49 files changed
+1516
-1051
No files matched your search
@@ -611,7 +611,9 @@ func (s Service) AddTargetCredentialSources(ctx context.Context, req *pbs.AddTar
|
||||
return nil, authResults.Error
|
||||
}
|
||||
}
|
||||
t, ts, cl, err := s.addCredentialSourcesInRepo(ctx, req.GetId(), req.GetApplicationCredentialSourceIds(), req.GetEgressCredentialSourceIds(), req.GetVersion())
|
||||
|
||||
brokeredCredentialSources := strutil.MergeSlices(req.GetApplicationCredentialSourceIds(), req.GetBrokeredCredentialSourceIds())
|
||||
t, ts, cl, err := s.addCredentialSourcesInRepo(ctx, req.GetId(), brokeredCredentialSources, req.GetInjectedApplicationCredentialSourceIds(), req.GetVersion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -654,7 +656,9 @@ func (s Service) SetTargetCredentialSources(ctx context.Context, req *pbs.SetTar
|
||||
return nil, authResults.Error
|
||||
}
|
||||
}
|
||||
t, ts, cl, err := s.setCredentialSourcesInRepo(ctx, req.GetId(), req.GetApplicationCredentialSourceIds(), req.GetEgressCredentialSourceIds(), req.GetVersion())
|
||||
|
||||
brokeredCredentialSources := strutil.MergeSlices(req.GetApplicationCredentialSourceIds(), req.GetBrokeredCredentialSourceIds())
|
||||
t, ts, cl, err := s.setCredentialSourcesInRepo(ctx, req.GetId(), brokeredCredentialSources, req.GetInjectedApplicationCredentialSourceIds(), req.GetVersion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -697,7 +701,9 @@ func (s Service) RemoveTargetCredentialSources(ctx context.Context, req *pbs.Rem
|
||||
return nil, authResults.Error
|
||||
}
|
||||
}
|
||||
t, ts, cl, err := s.removeCredentialSourcesInRepo(ctx, req.GetId(), req.GetApplicationCredentialSourceIds(), req.GetEgressCredentialSourceIds(), req.GetVersion())
|
||||
|
||||
brokeredCredentialSources := strutil.MergeSlices(req.GetApplicationCredentialSourceIds(), req.GetBrokeredCredentialSourceIds())
|
||||
t, ts, cl, err := s.removeCredentialSourcesInRepo(ctx, req.GetId(), brokeredCredentialSources, req.GetInjectedApplicationCredentialSourceIds(), req.GetVersion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -982,14 +988,14 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
var workerCreds []session.Credential
|
||||
for _, cred := range dynamic {
|
||||
switch cred.Purpose() {
|
||||
case credential.EgressPurpose:
|
||||
case credential.InjectedApplicationPurpose:
|
||||
c, err := dynamicToWorkerCredential(ctx, cred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
workerCreds = append(workerCreds, c)
|
||||
|
||||
case credential.ApplicationPurpose:
|
||||
case credential.BrokeredPurpose:
|
||||
c, err := dynamicToSessionCredential(ctx, cred)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
@@ -1003,14 +1009,14 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
|
||||
for _, sc := range staticCreds {
|
||||
switch sc.CredentialPurpose {
|
||||
case string(credential.EgressPurpose):
|
||||
case string(credential.InjectedApplicationPurpose):
|
||||
c, err := staticToWorkerCredential(ctx, staticCredsById[sc.CredentialStaticId])
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
workerCreds = append(workerCreds, c)
|
||||
|
||||
case string(credential.ApplicationPurpose):
|
||||
case string(credential.BrokeredPurpose):
|
||||
c, err := staticToSessionCredential(ctx, staticCredsById[sc.CredentialStaticId])
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
@@ -1270,18 +1276,18 @@ func (s Service) removeHostSourcesInRepo(ctx context.Context, targetId string, h
|
||||
return out, hs, cl, nil
|
||||
}
|
||||
|
||||
func (s Service) addCredentialSourcesInRepo(ctx context.Context, targetId string, applicationIds []string, egressIds []string, version uint32) (target.Target, []target.HostSource, []target.CredentialSource, error) {
|
||||
func (s Service) addCredentialSourcesInRepo(ctx context.Context, targetId string, brokeredIds []string, injectedAppIds []string, version uint32) (target.Target, []target.HostSource, []target.CredentialSource, error) {
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
var creds target.CredentialSources
|
||||
if len(applicationIds) > 0 {
|
||||
creds.ApplicationCredentialIds = strutil.RemoveDuplicates(applicationIds, false)
|
||||
if len(brokeredIds) > 0 {
|
||||
creds.BrokeredCredentialIds = strutil.RemoveDuplicates(brokeredIds, false)
|
||||
}
|
||||
if len(egressIds) > 0 {
|
||||
creds.EgressCredentialIds = strutil.RemoveDuplicates(egressIds, false)
|
||||
if len(injectedAppIds) > 0 {
|
||||
creds.InjectedApplicationCredentialIds = strutil.RemoveDuplicates(injectedAppIds, false)
|
||||
}
|
||||
|
||||
out, hs, credSources, err := repo.AddTargetCredentialSources(ctx, targetId, version, creds)
|
||||
@@ -1295,7 +1301,7 @@ func (s Service) addCredentialSourcesInRepo(ctx context.Context, targetId string
|
||||
return out, hs, credSources, nil
|
||||
}
|
||||
|
||||
func (s Service) setCredentialSourcesInRepo(ctx context.Context, targetId string, applicationIds []string, egressIds []string, version uint32) (target.Target, []target.HostSource, []target.CredentialSource, error) {
|
||||
func (s Service) setCredentialSourcesInRepo(ctx context.Context, targetId string, brokeredIds []string, injectedAppIds []string, version uint32) (target.Target, []target.HostSource, []target.CredentialSource, error) {
|
||||
const op = "targets.(Service).setCredentialSourcesInRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
@@ -1303,11 +1309,11 @@ func (s Service) setCredentialSourcesInRepo(ctx context.Context, targetId string
|
||||
}
|
||||
|
||||
var ids target.CredentialSources
|
||||
if len(applicationIds) > 0 {
|
||||
ids.ApplicationCredentialIds = strutil.RemoveDuplicates(applicationIds, false)
|
||||
if len(brokeredIds) > 0 {
|
||||
ids.BrokeredCredentialIds = strutil.RemoveDuplicates(brokeredIds, false)
|
||||
}
|
||||
if len(egressIds) > 0 {
|
||||
ids.EgressCredentialIds = strutil.RemoveDuplicates(egressIds, false)
|
||||
if len(injectedAppIds) > 0 {
|
||||
ids.InjectedApplicationCredentialIds = strutil.RemoveDuplicates(injectedAppIds, false)
|
||||
}
|
||||
|
||||
_, _, _, err = repo.SetTargetCredentialSources(ctx, targetId, version, ids)
|
||||
@@ -1326,7 +1332,7 @@ func (s Service) setCredentialSourcesInRepo(ctx context.Context, targetId string
|
||||
return out, hs, credSources, nil
|
||||
}
|
||||
|
||||
func (s Service) removeCredentialSourcesInRepo(ctx context.Context, targetId string, applicationIds []string, egressIds []string, version uint32) (target.Target, []target.HostSource, []target.CredentialSource, error) {
|
||||
func (s Service) removeCredentialSourcesInRepo(ctx context.Context, targetId string, brokeredIds []string, injectedAppIds []string, version uint32) (target.Target, []target.HostSource, []target.CredentialSource, error) {
|
||||
const op = "targets.(Service).removeCredentialSourcesInRepo"
|
||||
repo, err := s.repoFn()
|
||||
if err != nil {
|
||||
@@ -1334,11 +1340,11 @@ func (s Service) removeCredentialSourcesInRepo(ctx context.Context, targetId str
|
||||
}
|
||||
|
||||
var ids target.CredentialSources
|
||||
if len(applicationIds) > 0 {
|
||||
ids.ApplicationCredentialIds = strutil.RemoveDuplicates(applicationIds, false)
|
||||
if len(brokeredIds) > 0 {
|
||||
ids.BrokeredCredentialIds = strutil.RemoveDuplicates(brokeredIds, false)
|
||||
}
|
||||
if len(egressIds) > 0 {
|
||||
ids.EgressCredentialIds = strutil.RemoveDuplicates(egressIds, false)
|
||||
if len(injectedAppIds) > 0 {
|
||||
ids.InjectedApplicationCredentialIds = strutil.RemoveDuplicates(injectedAppIds, false)
|
||||
}
|
||||
_, err = repo.DeleteTargetCredentialSources(ctx, targetId, version, ids)
|
||||
if err != nil {
|
||||
@@ -1483,41 +1489,48 @@ func toProto(ctx context.Context, in target.Target, hostSources []target.HostSou
|
||||
}
|
||||
}
|
||||
|
||||
var appCredSources, egressCredSources []*pb.CredentialSource
|
||||
var appCredSourceIds, egressCredSourceIds []string
|
||||
var brokeredSources, injectedAppSources []*pb.CredentialSource
|
||||
var brokeredSourceIds, injectedAppSourceIds []string
|
||||
|
||||
for _, cs := range credSources {
|
||||
switch cs.CredentialPurpose() {
|
||||
case credential.ApplicationPurpose:
|
||||
appCredSourceIds = append(appCredSourceIds, cs.Id())
|
||||
appCredSources = append(appCredSources, &pb.CredentialSource{
|
||||
case credential.BrokeredPurpose:
|
||||
brokeredSourceIds = append(brokeredSourceIds, cs.Id())
|
||||
brokeredSources = append(brokeredSources, &pb.CredentialSource{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
|
||||
case credential.EgressPurpose:
|
||||
egressCredSources = append(egressCredSources, &pb.CredentialSource{
|
||||
case credential.InjectedApplicationPurpose:
|
||||
injectedAppSources = append(injectedAppSources, &pb.CredentialSource{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
egressCredSourceIds = append(egressCredSourceIds, cs.Id())
|
||||
injectedAppSourceIds = append(injectedAppSourceIds, cs.Id())
|
||||
|
||||
default:
|
||||
return nil, errors.New(ctx, errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Application Credentials are deprecated, remove when field removed.
|
||||
if outputFields.Has(globals.ApplicationCredentialSourceIdsField) {
|
||||
out.ApplicationCredentialSourceIds = appCredSourceIds
|
||||
out.ApplicationCredentialSourceIds = brokeredSourceIds
|
||||
}
|
||||
if outputFields.Has(globals.ApplicationCredentialSourcesField) {
|
||||
out.ApplicationCredentialSources = appCredSources
|
||||
out.ApplicationCredentialSources = brokeredSources
|
||||
}
|
||||
if outputFields.Has(globals.EgressCredentialSourceIdsField) {
|
||||
out.EgressCredentialSourceIds = egressCredSourceIds
|
||||
if outputFields.Has(globals.BrokeredCredentialSourceIdsField) {
|
||||
out.BrokeredCredentialSourceIds = brokeredSourceIds
|
||||
}
|
||||
if outputFields.Has(globals.EgressCredentialSourcesField) {
|
||||
out.EgressCredentialSources = egressCredSources
|
||||
if outputFields.Has(globals.BrokeredCredentialSourcesField) {
|
||||
out.BrokeredCredentialSources = brokeredSources
|
||||
}
|
||||
if outputFields.Has(globals.InjectedApplicationCredentialSourceIdsField) {
|
||||
out.InjectedApplicationCredentialSourceIds = injectedAppSourceIds
|
||||
}
|
||||
if outputFields.Has(globals.InjectedApplicationCredentialSourcesField) {
|
||||
out.InjectedApplicationCredentialSources = injectedAppSources
|
||||
}
|
||||
if outputFields.Has(globals.AttributesField) {
|
||||
if err := subtypeRegistry.setAttributes(in.GetType(), in, &out); err != nil {
|
||||
@@ -1791,10 +1804,11 @@ func validateAddCredentialSourcesRequest(req *pbs.AddTargetCredentialSourcesRequ
|
||||
if req.GetVersion() == 0 {
|
||||
badFields[globals.VersionField] = "Required field."
|
||||
}
|
||||
if len(req.GetApplicationCredentialSourceIds())+len(req.GetEgressCredentialSourceIds()) == 0 {
|
||||
badFields[globals.ApplicationCredentialSourceIdsField] = "Application or Egress Credential Source IDs must be provided."
|
||||
badFields[globals.EgressCredentialSourceIdsField] = "Application or Egress Credential Source IDs must be provided."
|
||||
if len(req.GetApplicationCredentialSourceIds())+len(req.GetBrokeredCredentialSourceIds())+len(req.GetInjectedApplicationCredentialSourceIds()) == 0 {
|
||||
badFields[globals.BrokeredCredentialSourceIdsField] = "Brokered or Injected Application Credential Source IDs must be provided."
|
||||
badFields[globals.InjectedApplicationCredentialSourceIdsField] = "Brokered or Injected Application Credential Source IDs must be provided."
|
||||
}
|
||||
// TODO: Application Credentials are deprecated, remove when field removed.
|
||||
for _, cl := range req.GetApplicationCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
@@ -1805,13 +1819,23 @@ func validateAddCredentialSourcesRequest(req *pbs.AddTargetCredentialSourcesRequ
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, cl := range req.GetEgressCredentialSourceIds() {
|
||||
for _, cl := range req.GetBrokeredCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
credential.UsernamePasswordCredentialPrefix,
|
||||
credential.PreviousUsernamePasswordCredentialPrefix,
|
||||
credential.SshPrivateKeyCredentialPrefix) {
|
||||
badFields[globals.EgressCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
badFields[globals.BrokeredCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, cl := range req.GetInjectedApplicationCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
credential.UsernamePasswordCredentialPrefix,
|
||||
credential.PreviousUsernamePasswordCredentialPrefix,
|
||||
credential.SshPrivateKeyCredentialPrefix) {
|
||||
badFields[globals.InjectedApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1829,6 +1853,7 @@ func validateSetCredentialSourcesRequest(req *pbs.SetTargetCredentialSourcesRequ
|
||||
if req.GetVersion() == 0 {
|
||||
badFields[globals.VersionField] = "Required field."
|
||||
}
|
||||
// TODO: Application Credentials are deprecated, remove when field removed.
|
||||
for _, cl := range req.GetApplicationCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
@@ -1839,13 +1864,23 @@ func validateSetCredentialSourcesRequest(req *pbs.SetTargetCredentialSourcesRequ
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, cl := range req.GetEgressCredentialSourceIds() {
|
||||
for _, cl := range req.GetBrokeredCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
credential.UsernamePasswordCredentialPrefix,
|
||||
credential.PreviousUsernamePasswordCredentialPrefix,
|
||||
credential.SshPrivateKeyCredentialPrefix) {
|
||||
badFields[globals.EgressCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
badFields[globals.BrokeredCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, cl := range req.GetInjectedApplicationCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
credential.UsernamePasswordCredentialPrefix,
|
||||
credential.PreviousUsernamePasswordCredentialPrefix,
|
||||
credential.SshPrivateKeyCredentialPrefix) {
|
||||
badFields[globals.InjectedApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1863,10 +1898,11 @@ func validateRemoveCredentialSourcesRequest(req *pbs.RemoveTargetCredentialSourc
|
||||
if req.GetVersion() == 0 {
|
||||
badFields[globals.VersionField] = "Required field."
|
||||
}
|
||||
if len(req.GetApplicationCredentialSourceIds())+len(req.GetEgressCredentialSourceIds()) == 0 {
|
||||
badFields[globals.ApplicationCredentialSourceIdsField] = "Application or Egress Credential Source IDs must be provided."
|
||||
badFields[globals.EgressCredentialSourceIdsField] = "Application or Egress Credential Source IDs must be provided."
|
||||
if len(req.GetApplicationCredentialSourceIds())+len(req.GetBrokeredCredentialSourceIds())+len(req.GetInjectedApplicationCredentialSourceIds()) == 0 {
|
||||
badFields[globals.BrokeredCredentialSourceIdsField] = "Brokered or Injected Application Credential Source IDs must be provided."
|
||||
badFields[globals.InjectedApplicationCredentialSourceIdsField] = "Brokered or Injected Application Credential Source IDs must be provided."
|
||||
}
|
||||
// TODO: Application Credentials are deprecated, remove when field removed.
|
||||
for _, cl := range req.GetApplicationCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
@@ -1877,13 +1913,23 @@ func validateRemoveCredentialSourcesRequest(req *pbs.RemoveTargetCredentialSourc
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, cl := range req.GetEgressCredentialSourceIds() {
|
||||
for _, cl := range req.GetBrokeredCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
credential.UsernamePasswordCredentialPrefix,
|
||||
credential.PreviousUsernamePasswordCredentialPrefix,
|
||||
credential.SshPrivateKeyCredentialPrefix) {
|
||||
badFields[globals.EgressCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
badFields[globals.BrokeredCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, cl := range req.GetInjectedApplicationCredentialSourceIds() {
|
||||
if !handlers.ValidId(handlers.Id(cl),
|
||||
vault.CredentialLibraryPrefix,
|
||||
credential.UsernamePasswordCredentialPrefix,
|
||||
credential.PreviousUsernamePasswordCredentialPrefix,
|
||||
credential.SshPrivateKeyCredentialPrefix) {
|
||||
badFields[globals.InjectedApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1882,37 +1882,37 @@ func TestAddTargetCredentialSources(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Add library on library populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for lib-lib sources", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for lib-lib sources", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
addSources: []string{cls[1].GetPublicId()},
|
||||
resultSourceIds: []string{cls[0].GetPublicId(), cls[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Add library on static cred populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for lib-static sources", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for lib-static sources", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
addSources: []string{cls[1].GetPublicId()},
|
||||
resultSourceIds: []string{creds[0].GetPublicId(), cls[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Add static cred on library populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for static-lib sources", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for static-lib sources", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
addSources: []string{creds[1].GetPublicId()},
|
||||
resultSourceIds: []string{cls[0].GetPublicId(), creds[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Add static cred on static cred populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for static-static sources", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated for static-static sources", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
addSources: []string{creds[1].GetPublicId()},
|
||||
resultSourceIds: []string{creds[0].GetPublicId(), creds[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Add duplicated sources on library populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicated for lib sources", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicated for lib sources", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
addSources: []string{cls[1].GetPublicId(), cls[1].GetPublicId(), creds[1].GetPublicId(), creds[1].GetPublicId()},
|
||||
resultSourceIds: []string{cls[0].GetPublicId(), cls[1].GetPublicId(), creds[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Add duplicated sources on static cred populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicated for static sources", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicated for static sources", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
addSources: []string{cls[1].GetPublicId(), cls[1].GetPublicId(), creds[1].GetPublicId(), creds[1].GetPublicId()},
|
||||
resultSourceIds: []string{creds[0].GetPublicId(), cls[1].GetPublicId(), creds[1].GetPublicId()},
|
||||
},
|
||||
@@ -1921,14 +1921,17 @@ func TestAddTargetCredentialSources(t *testing.T) {
|
||||
for _, tc := range addCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := &pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tc.tar.GetPublicId(),
|
||||
Version: tc.tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: tc.addSources,
|
||||
Id: tc.tar.GetPublicId(),
|
||||
Version: tc.tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: tc.addSources,
|
||||
}
|
||||
|
||||
got, err := s.AddTargetCredentialSources(auth.DisabledAuthTestContext(iamRepoFn, proj.GetPublicId()), req)
|
||||
require.NoError(t, err, "Got error: %v", s)
|
||||
|
||||
assert.ElementsMatch(t, tc.resultSourceIds, got.GetItem().GetBrokeredCredentialSourceIds())
|
||||
assert.Equal(t, len(tc.resultSourceIds), len(got.GetItem().GetBrokeredCredentialSources()))
|
||||
|
||||
assert.ElementsMatch(t, tc.resultSourceIds, got.GetItem().GetApplicationCredentialSourceIds())
|
||||
assert.Equal(t, len(tc.resultSourceIds), len(got.GetItem().GetApplicationCredentialSources()))
|
||||
})
|
||||
@@ -1946,7 +1949,7 @@ func TestAddTargetCredentialSources(t *testing.T) {
|
||||
req: &pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: "bad id",
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{
|
||||
BrokeredCredentialSourceIds: []string{
|
||||
cls[0].GetPublicId(),
|
||||
},
|
||||
},
|
||||
@@ -1957,7 +1960,7 @@ func TestAddTargetCredentialSources(t *testing.T) {
|
||||
req: &pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion() + 2,
|
||||
ApplicationCredentialSourceIds: []string{
|
||||
BrokeredCredentialSourceIds: []string{
|
||||
cls[0].GetPublicId(),
|
||||
},
|
||||
},
|
||||
@@ -1974,9 +1977,9 @@ func TestAddTargetCredentialSources(t *testing.T) {
|
||||
{
|
||||
name: "Incorrect source id",
|
||||
req: &pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{"incorrect"},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{"incorrect"},
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
@@ -2035,45 +2038,45 @@ func TestSetTargetCredentialSources(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Set library on library populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated library-library", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated library-library", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{cls[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{cls[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Set static on library populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated static-library", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated static-library", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{creds[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{creds[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Set library on static populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated library-static", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated library-static", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{cls[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{cls[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Set static on static populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated static-static", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "populated static-static", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{creds[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{creds[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Set duplicate library on populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicate library", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicate library", target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{cls[1].GetPublicId(), cls[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{cls[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Set duplicate static on populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicate static", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "duplicate static", target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{creds[1].GetPublicId(), creds[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{creds[1].GetPublicId()},
|
||||
},
|
||||
{
|
||||
name: "Set empty on populated target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "another populated",
|
||||
target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose)}),
|
||||
target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose)})),
|
||||
target.WithCredentialLibraries([]*target.CredentialLibrary{target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose)}),
|
||||
target.WithStaticCredentials([]*target.StaticCredential{target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose)})),
|
||||
setCredentialSources: []string{},
|
||||
resultCredentialSourceIds: nil,
|
||||
},
|
||||
@@ -2081,13 +2084,16 @@ func TestSetTargetCredentialSources(t *testing.T) {
|
||||
for _, tc := range setCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := &pbs.SetTargetCredentialSourcesRequest{
|
||||
Id: tc.tar.GetPublicId(),
|
||||
Version: tc.tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: tc.setCredentialSources,
|
||||
Id: tc.tar.GetPublicId(),
|
||||
Version: tc.tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: tc.setCredentialSources,
|
||||
}
|
||||
|
||||
got, err := s.SetTargetCredentialSources(auth.DisabledAuthTestContext(iamRepoFn, proj.GetPublicId()), req)
|
||||
require.NoError(t, err, "Got error: %v", s)
|
||||
assert.ElementsMatch(t, tc.resultCredentialSourceIds, got.GetItem().GetBrokeredCredentialSourceIds())
|
||||
assert.Equal(t, len(tc.resultCredentialSourceIds), len(got.GetItem().GetBrokeredCredentialSources()))
|
||||
|
||||
assert.ElementsMatch(t, tc.resultCredentialSourceIds, got.GetItem().GetApplicationCredentialSourceIds())
|
||||
assert.Equal(t, len(tc.resultCredentialSourceIds), len(got.GetItem().GetApplicationCredentialSources()))
|
||||
})
|
||||
@@ -2103,27 +2109,27 @@ func TestSetTargetCredentialSources(t *testing.T) {
|
||||
{
|
||||
name: "Bad target Id",
|
||||
req: &pbs.SetTargetCredentialSourcesRequest{
|
||||
Id: "bad id",
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{cls[0].GetPublicId()},
|
||||
Id: "bad id",
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{cls[0].GetPublicId()},
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Bad version",
|
||||
req: &pbs.SetTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion() + 3,
|
||||
ApplicationCredentialSourceIds: []string{cls[0].GetPublicId()},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion() + 3,
|
||||
BrokeredCredentialSourceIds: []string{cls[0].GetPublicId()},
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.Internal),
|
||||
},
|
||||
{
|
||||
name: "Bad source id",
|
||||
req: &pbs.SetTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{"invalid"},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{"invalid"},
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
@@ -2185,8 +2191,8 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
name: "Remove 1 of 2 libraries",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "remove partial lib",
|
||||
target.WithCredentialLibraries([]*target.CredentialLibrary{
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
})),
|
||||
removeCredentialSources: []string{cls[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{cls[0].GetPublicId()},
|
||||
@@ -2195,8 +2201,8 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
name: "Remove 1 of 2 static credentials",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "remove partial static",
|
||||
target.WithStaticCredentials([]*target.StaticCredential{
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
})),
|
||||
removeCredentialSources: []string{creds[1].GetPublicId()},
|
||||
resultCredentialSourceIds: []string{creds[0].GetPublicId()},
|
||||
@@ -2205,8 +2211,8 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
name: "Remove 1 duplicate set of 2 libraries",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "remove duplicate lib",
|
||||
target.WithCredentialLibraries([]*target.CredentialLibrary{
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
})),
|
||||
removeCredentialSources: []string{
|
||||
cls[1].GetPublicId(), cls[1].GetPublicId(),
|
||||
@@ -2217,8 +2223,8 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
name: "Remove 1 duplicate set of 2 static credentials",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "remove duplicate static",
|
||||
target.WithStaticCredentials([]*target.StaticCredential{
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
})),
|
||||
removeCredentialSources: []string{
|
||||
creds[1].GetPublicId(), creds[1].GetPublicId(),
|
||||
@@ -2229,12 +2235,12 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
name: "Remove mixed sources from target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "remove mixed",
|
||||
target.WithCredentialLibraries([]*target.CredentialLibrary{
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
}),
|
||||
target.WithStaticCredentials([]*target.StaticCredential{
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
})),
|
||||
removeCredentialSources: []string{
|
||||
cls[1].GetPublicId(), creds[0].GetPublicId(),
|
||||
@@ -2247,12 +2253,12 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
name: "Remove all sources from target",
|
||||
tar: tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), "remove all",
|
||||
target.WithCredentialLibraries([]*target.CredentialLibrary{
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewCredentialLibrary("", cls[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
}),
|
||||
target.WithStaticCredentials([]*target.StaticCredential{
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", creds[0].GetPublicId(), credential.BrokeredPurpose),
|
||||
target.TestNewStaticCredential("", creds[1].GetPublicId(), credential.BrokeredPurpose),
|
||||
})),
|
||||
removeCredentialSources: []string{
|
||||
cls[0].GetPublicId(), cls[1].GetPublicId(),
|
||||
@@ -2265,9 +2271,9 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
for _, tc := range removeCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := &pbs.RemoveTargetCredentialSourcesRequest{
|
||||
Id: tc.tar.GetPublicId(),
|
||||
Version: tc.tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: tc.removeCredentialSources,
|
||||
Id: tc.tar.GetPublicId(),
|
||||
Version: tc.tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: tc.removeCredentialSources,
|
||||
}
|
||||
|
||||
got, err := s.RemoveTargetCredentialSources(auth.DisabledAuthTestContext(iamRepoFn, proj.GetPublicId()), req)
|
||||
@@ -2277,6 +2283,9 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, err, "Got error: %v", s)
|
||||
|
||||
assert.ElementsMatch(t, tc.resultCredentialSourceIds, got.GetItem().GetBrokeredCredentialSourceIds())
|
||||
assert.Equal(t, len(tc.resultCredentialSourceIds), len(got.GetItem().GetBrokeredCredentialSources()))
|
||||
|
||||
assert.ElementsMatch(t, tc.resultCredentialSourceIds, got.GetItem().GetApplicationCredentialSourceIds())
|
||||
assert.Equal(t, len(tc.resultCredentialSourceIds), len(got.GetItem().GetApplicationCredentialSources()))
|
||||
})
|
||||
@@ -2294,7 +2303,7 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
req: &pbs.RemoveTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion() + 3,
|
||||
ApplicationCredentialSourceIds: []string{
|
||||
BrokeredCredentialSourceIds: []string{
|
||||
cls[0].GetPublicId(),
|
||||
},
|
||||
},
|
||||
@@ -2305,7 +2314,7 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
req: &pbs.RemoveTargetCredentialSourcesRequest{
|
||||
Id: "bad id",
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{
|
||||
BrokeredCredentialSourceIds: []string{
|
||||
cls[0].GetPublicId(),
|
||||
},
|
||||
},
|
||||
@@ -2314,9 +2323,9 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
{
|
||||
name: "Empty sources",
|
||||
req: &pbs.RemoveTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{},
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
@@ -2325,7 +2334,7 @@ func TestRemoveTargetCredentialSources(t *testing.T) {
|
||||
req: &pbs.RemoveTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{
|
||||
BrokeredCredentialSourceIds: []string{
|
||||
"invalid",
|
||||
},
|
||||
},
|
||||
@@ -2519,9 +2528,9 @@ func TestAuthorizeSession(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
_, err = s.AddTargetCredentialSources(ctx,
|
||||
&pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
ApplicationCredentialSourceIds: []string{clsResp.GetItem().GetId()},
|
||||
Version: apiTar.GetItem().GetVersion(),
|
||||
Id: tar.GetPublicId(),
|
||||
BrokeredCredentialSourceIds: []string{clsResp.GetItem().GetId()},
|
||||
Version: apiTar.GetItem().GetVersion(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -2997,9 +3006,9 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
_, err = s.AddTargetCredentialSources(ctx,
|
||||
&pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
ApplicationCredentialSourceIds: []string{tc.credSourceId},
|
||||
Version: apiTar.GetItem().GetVersion(),
|
||||
Id: tar.GetPublicId(),
|
||||
BrokeredCredentialSourceIds: []string{tc.credSourceId},
|
||||
Version: apiTar.GetItem().GetVersion(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -3175,9 +3184,9 @@ func TestAuthorizeSession_Errors(t *testing.T) {
|
||||
|
||||
tr, err := s.AddTargetCredentialSources(ctx,
|
||||
&pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
ApplicationCredentialSourceIds: []string{clsResp.GetItem().GetId()},
|
||||
Version: tar.GetVersion(),
|
||||
Id: tar.GetPublicId(),
|
||||
BrokeredCredentialSourceIds: []string{clsResp.GetItem().GetId()},
|
||||
Version: tar.GetVersion(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return tr.GetItem().GetVersion()
|
||||
@@ -3199,9 +3208,9 @@ func TestAuthorizeSession_Errors(t *testing.T) {
|
||||
|
||||
tr, err := s.AddTargetCredentialSources(ctx,
|
||||
&pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
ApplicationCredentialSourceIds: []string{clsResp.GetItem().GetId()},
|
||||
Version: tar.GetVersion(),
|
||||
Id: tar.GetPublicId(),
|
||||
BrokeredCredentialSourceIds: []string{clsResp.GetItem().GetId()},
|
||||
Version: tar.GetVersion(),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
return tr.GetItem().GetVersion()
|
||||
@@ -3336,9 +3345,9 @@ func TestAddTargetCredentialLibraryPerms(t *testing.T) {
|
||||
|
||||
tar := tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), tc.name)
|
||||
req := &pbs.AddTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{cred.GetPublicId()},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{cred.GetPublicId()},
|
||||
}
|
||||
|
||||
got, err := s.AddTargetCredentialSources(ctx, req)
|
||||
@@ -3422,9 +3431,9 @@ func TestSetTargetCredentialLibraryPerms(t *testing.T) {
|
||||
|
||||
tar := tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), tc.name)
|
||||
req := &pbs.SetTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{cred.GetPublicId()},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{cred.GetPublicId()},
|
||||
}
|
||||
|
||||
got, err := s.SetTargetCredentialSources(ctx, req)
|
||||
@@ -3507,13 +3516,13 @@ func TestRemoveTargetCredentialLibraryPerms(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
tar := tcp.TestTarget(ctx, t, conn, proj.GetPublicId(), tc.name, target.WithStaticCredentials([]*target.StaticCredential{
|
||||
target.TestNewStaticCredential("", cred.GetPublicId(), credential.ApplicationPurpose),
|
||||
target.TestNewStaticCredential("", cred.GetPublicId(), credential.BrokeredPurpose),
|
||||
}))
|
||||
|
||||
req := &pbs.RemoveTargetCredentialSourcesRequest{
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
ApplicationCredentialSourceIds: []string{cred.GetPublicId()},
|
||||
Id: tar.GetPublicId(),
|
||||
Version: tar.GetVersion(),
|
||||
BrokeredCredentialSourceIds: []string{cred.GetPublicId()},
|
||||
}
|
||||
|
||||
got, err := s.RemoveTargetCredentialSources(ctx, req)
|
||||
|
||||
Reference in new issue
Block a user