mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
feat(v3alpha): read actions (#8357)
# Which Problems Are Solved The current v3alpha actions APIs don't exactly adhere to the [new resources API design](https://zitadel.com/docs/apis/v3#standard-resources). # How the Problems Are Solved - **Improved ID access**: The aggregate ID is added to the resource details object, so accessing resource IDs and constructing proto messages for resources is easier - **Explicit Instances**: Optionally, the instance can be explicitly given in each request - **Pagination**: A default search limit and a max search limit are added to the defaults.yaml. They apply to the new v3 APIs (currently only actions). The search query defaults are changed to ascending by creation date, because this makes the pagination results the most deterministic. The creation date is also added to the object details. The bug with updated creation dates is fixed for executions and targets. - **Removed Sequences**: Removed Sequence from object details and ProcessedSequence from search details # Additional Changes Object details IDs are checked in unit test only if an empty ID is expected. Centralizing the details check also makes this internal object more flexible for future evolutions. # Additional Context - Closes #8169 - Depends on https://github.com/zitadel/zitadel/pull/8225 --------- Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
resources_object "github.com/zitadel/zitadel/pkg/grpc/resources/object/v3alpha"
|
||||
settings_object "github.com/zitadel/zitadel/pkg/grpc/settings/object/v3alpha"
|
||||
)
|
||||
|
||||
// Details is the interface that covers both v1 and v2 proto generated object details.
|
||||
@@ -37,6 +36,10 @@ type ListDetailsMsg[L ListDetails] interface {
|
||||
GetDetails() L
|
||||
}
|
||||
|
||||
type ResourceListDetailsMsg interface {
|
||||
GetDetails() *resources_object.ListDetails
|
||||
}
|
||||
|
||||
// AssertDetails asserts values in a message's object Details,
|
||||
// if the object Details in expected is a non-nil value.
|
||||
// It targets API v2 messages that have the `GetDetails()` method.
|
||||
@@ -67,28 +70,21 @@ func AssertDetails[D Details, M DetailsMsg[D]](t testing.TB, expected, actual M)
|
||||
}
|
||||
|
||||
func AssertResourceDetails(t testing.TB, expected *resources_object.Details, actual *resources_object.Details) {
|
||||
assert.NotZero(t, actual.GetSequence())
|
||||
|
||||
if expected.GetChangeDate() != nil {
|
||||
if expected.GetChanged() != nil {
|
||||
wantChangeDate := time.Now()
|
||||
gotChangeDate := actual.GetChangeDate().AsTime()
|
||||
gotChangeDate := actual.GetChanged().AsTime()
|
||||
assert.WithinRange(t, gotChangeDate, wantChangeDate.Add(-time.Minute), wantChangeDate.Add(time.Minute))
|
||||
}
|
||||
|
||||
if expected.GetCreated() != nil {
|
||||
wantCreatedDate := time.Now()
|
||||
gotCreatedDate := actual.GetCreated().AsTime()
|
||||
assert.WithinRange(t, gotCreatedDate, wantCreatedDate.Add(-time.Minute), wantCreatedDate.Add(time.Minute))
|
||||
}
|
||||
assert.Equal(t, expected.GetOwner(), actual.GetOwner())
|
||||
assert.NotEmpty(t, actual.GetId())
|
||||
}
|
||||
|
||||
func AssertSettingsDetails(t testing.TB, expected *settings_object.Details, actual *settings_object.Details) {
|
||||
assert.NotZero(t, actual.GetSequence())
|
||||
|
||||
if expected.GetChangeDate() != nil {
|
||||
wantChangeDate := time.Now()
|
||||
gotChangeDate := actual.GetChangeDate().AsTime()
|
||||
assert.WithinRange(t, gotChangeDate, wantChangeDate.Add(-time.Minute), wantChangeDate.Add(time.Minute))
|
||||
if expected.GetId() != "" {
|
||||
assert.Equal(t, expected.GetId(), actual.GetId())
|
||||
}
|
||||
|
||||
assert.Equal(t, expected.GetOwner(), actual.GetOwner())
|
||||
}
|
||||
|
||||
func AssertListDetails[L ListDetails, D ListDetailsMsg[L]](t testing.TB, expected, actual D) {
|
||||
@@ -107,6 +103,23 @@ func AssertListDetails[L ListDetails, D ListDetailsMsg[L]](t testing.TB, expecte
|
||||
}
|
||||
}
|
||||
|
||||
func AssertResourceListDetails[D ResourceListDetailsMsg](t testing.TB, expected, actual D) {
|
||||
wantDetails, gotDetails := expected.GetDetails(), actual.GetDetails()
|
||||
if wantDetails == nil {
|
||||
assert.Nil(t, gotDetails)
|
||||
return
|
||||
}
|
||||
|
||||
assert.Equal(t, wantDetails.GetTotalResult(), gotDetails.GetTotalResult())
|
||||
assert.Equal(t, wantDetails.GetAppliedLimit(), gotDetails.GetAppliedLimit())
|
||||
|
||||
if wantDetails.GetTimestamp() != nil {
|
||||
gotCD := gotDetails.GetTimestamp().AsTime()
|
||||
wantCD := time.Now()
|
||||
assert.WithinRange(t, gotCD, wantCD.Add(-time.Minute), wantCD.Add(time.Minute))
|
||||
}
|
||||
}
|
||||
|
||||
// EqualProto is inspired by [assert.Equal], only that it tests equality of a proto message.
|
||||
// A message diff is printed on the error test log if the messages are not equal.
|
||||
//
|
||||
|
@@ -137,7 +137,7 @@ func (t *Tester) UseIsolatedInstance(tt *testing.T, iamOwnerCtx, systemCtx conte
|
||||
})
|
||||
assert.NoError(collectT, importErr)
|
||||
}, 2*time.Minute, 100*time.Millisecond, "instance not ready")
|
||||
return primaryDomain, instanceId, adminUser.GetUserId(), newCtx
|
||||
return primaryDomain, instanceId, adminUser.GetUserId(), t.updateInstanceAndOrg(newCtx, fmt.Sprintf("%s:%d", primaryDomain, t.Config.ExternalPort))
|
||||
}
|
||||
|
||||
func (s *Tester) CreateHumanUser(ctx context.Context) *user.AddHumanUserResponse {
|
||||
|
@@ -204,14 +204,7 @@ func (s *Tester) createLoginClient(ctx context.Context) {
|
||||
|
||||
func (s *Tester) createMachineUser(ctx context.Context, username string, userType UserType) (context.Context, *query.User) {
|
||||
var err error
|
||||
|
||||
s.Instance, err = s.Queries.InstanceByHost(ctx, s.Host(), "")
|
||||
logging.OnError(err).Fatal("query instance")
|
||||
ctx = authz.WithInstance(ctx, s.Instance)
|
||||
|
||||
s.Organisation, err = s.Queries.OrgByID(ctx, true, s.Instance.DefaultOrganisationID())
|
||||
logging.OnError(err).Fatal("query organisation")
|
||||
|
||||
ctx = s.updateInstanceAndOrg(ctx, s.Host())
|
||||
usernameQuery, err := query.NewUserUsernameSearchQuery(username, query.TextEquals)
|
||||
logging.OnError(err).Fatal("user query")
|
||||
user, err := s.Queries.GetUser(ctx, true, usernameQuery)
|
||||
@@ -427,3 +420,14 @@ func runQuotaServer(ctx context.Context, bodies chan []byte) (*httptest.Server,
|
||||
mockServer.Start()
|
||||
return mockServer, nil
|
||||
}
|
||||
|
||||
func (s *Tester) updateInstanceAndOrg(ctx context.Context, domain string) context.Context {
|
||||
var err error
|
||||
s.Instance, err = s.Queries.InstanceByHost(ctx, domain, "")
|
||||
logging.OnError(err).Fatal("query instance")
|
||||
ctx = authz.WithInstance(ctx, s.Instance)
|
||||
|
||||
s.Organisation, err = s.Queries.OrgByID(ctx, true, s.Instance.DefaultOrganisationID())
|
||||
logging.OnError(err).Fatal("query organisation")
|
||||
return ctx
|
||||
}
|
||||
|
Reference in New Issue
Block a user