2023-06-07 15:28:42 +00:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2023-06-21 14:06:18 +00:00
|
|
|
"testing"
|
2023-06-07 15:28:42 +00:00
|
|
|
"time"
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
"github.com/brianvoe/gofakeit/v6"
|
2023-11-23 14:17:50 +00:00
|
|
|
"github.com/muhlemmer/gu"
|
2023-06-21 14:06:18 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-06-07 15:28:42 +00:00
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"google.golang.org/grpc"
|
2024-09-06 12:47:57 +00:00
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
2024-08-15 04:37:06 +00:00
|
|
|
"google.golang.org/grpc/metadata"
|
2023-11-06 09:48:28 +00:00
|
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
2024-03-12 13:50:13 +00:00
|
|
|
"google.golang.org/protobuf/types/known/structpb"
|
2023-06-07 15:28:42 +00:00
|
|
|
|
2023-12-21 09:03:37 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-06-07 15:28:42 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/admin"
|
2023-07-14 11:16:16 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/auth"
|
2024-07-26 20:39:55 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/feature/v2"
|
|
|
|
feature_v2beta "github.com/zitadel/zitadel/pkg/grpc/feature/v2beta"
|
2024-08-14 18:18:29 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/idp"
|
|
|
|
idp_pb "github.com/zitadel/zitadel/pkg/grpc/idp/v2"
|
2023-06-20 16:23:28 +00:00
|
|
|
mgmt "github.com/zitadel/zitadel/pkg/grpc/management"
|
2024-08-14 18:18:29 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
2024-08-28 19:46:45 +00:00
|
|
|
object_v3alpha "github.com/zitadel/zitadel/pkg/grpc/object/v3alpha"
|
2024-07-26 20:39:55 +00:00
|
|
|
oidc_pb "github.com/zitadel/zitadel/pkg/grpc/oidc/v2"
|
|
|
|
oidc_pb_v2beta "github.com/zitadel/zitadel/pkg/grpc/oidc/v2beta"
|
2024-09-17 08:27:48 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/org/v2"
|
2024-07-26 20:39:55 +00:00
|
|
|
org_v2beta "github.com/zitadel/zitadel/pkg/grpc/org/v2beta"
|
2024-07-31 12:42:12 +00:00
|
|
|
action "github.com/zitadel/zitadel/pkg/grpc/resources/action/v3alpha"
|
2024-08-28 19:46:45 +00:00
|
|
|
user_v3alpha "github.com/zitadel/zitadel/pkg/grpc/resources/user/v3alpha"
|
|
|
|
userschema_v3alpha "github.com/zitadel/zitadel/pkg/grpc/resources/userschema/v3alpha"
|
2024-08-14 14:18:14 +00:00
|
|
|
webkey_v3alpha "github.com/zitadel/zitadel/pkg/grpc/resources/webkey/v3alpha"
|
2024-08-14 18:18:29 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/session/v2"
|
2024-07-26 20:39:55 +00:00
|
|
|
session_v2beta "github.com/zitadel/zitadel/pkg/grpc/session/v2beta"
|
2024-08-14 18:18:29 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/settings/v2"
|
2024-07-26 20:39:55 +00:00
|
|
|
settings_v2beta "github.com/zitadel/zitadel/pkg/grpc/settings/v2beta"
|
2023-12-21 09:03:37 +00:00
|
|
|
user_pb "github.com/zitadel/zitadel/pkg/grpc/user"
|
2024-08-28 19:46:45 +00:00
|
|
|
user_v2 "github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
2024-07-26 20:39:55 +00:00
|
|
|
user_v2beta "github.com/zitadel/zitadel/pkg/grpc/user/v2beta"
|
2023-06-07 15:28:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Client struct {
|
2024-07-26 20:39:55 +00:00
|
|
|
CC *grpc.ClientConn
|
|
|
|
Admin admin.AdminServiceClient
|
|
|
|
Mgmt mgmt.ManagementServiceClient
|
|
|
|
Auth auth.AuthServiceClient
|
|
|
|
UserV2beta user_v2beta.UserServiceClient
|
2024-08-28 19:46:45 +00:00
|
|
|
UserV2 user_v2.UserServiceClient
|
2024-07-26 20:39:55 +00:00
|
|
|
SessionV2beta session_v2beta.SessionServiceClient
|
|
|
|
SessionV2 session.SessionServiceClient
|
|
|
|
SettingsV2beta settings_v2beta.SettingsServiceClient
|
|
|
|
SettingsV2 settings.SettingsServiceClient
|
|
|
|
OIDCv2beta oidc_pb_v2beta.OIDCServiceClient
|
|
|
|
OIDCv2 oidc_pb.OIDCServiceClient
|
|
|
|
OrgV2beta org_v2beta.OrganizationServiceClient
|
2024-07-31 12:42:12 +00:00
|
|
|
OrgV2 org.OrganizationServiceClient
|
2024-08-14 14:18:14 +00:00
|
|
|
ActionV3Alpha action.ZITADELActionsClient
|
2024-07-26 20:39:55 +00:00
|
|
|
FeatureV2beta feature_v2beta.FeatureServiceClient
|
|
|
|
FeatureV2 feature.FeatureServiceClient
|
2024-08-28 19:46:45 +00:00
|
|
|
UserSchemaV3 userschema_v3alpha.ZITADELUserSchemasClient
|
2024-08-14 14:18:14 +00:00
|
|
|
WebKeyV3Alpha webkey_v3alpha.ZITADELWebKeysClient
|
2024-08-14 18:18:29 +00:00
|
|
|
IDPv2 idp_pb.IdentityProviderServiceClient
|
2024-08-28 19:46:45 +00:00
|
|
|
UserV3Alpha user_v3alpha.ZITADELUsersClient
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func newClient(ctx context.Context, target string) (*Client, error) {
|
|
|
|
cc, err := grpc.NewClient(target,
|
|
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
client := &Client{
|
2024-07-26 20:39:55 +00:00
|
|
|
CC: cc,
|
|
|
|
Admin: admin.NewAdminServiceClient(cc),
|
|
|
|
Mgmt: mgmt.NewManagementServiceClient(cc),
|
|
|
|
Auth: auth.NewAuthServiceClient(cc),
|
|
|
|
UserV2beta: user_v2beta.NewUserServiceClient(cc),
|
2024-08-28 19:46:45 +00:00
|
|
|
UserV2: user_v2.NewUserServiceClient(cc),
|
2024-07-26 20:39:55 +00:00
|
|
|
SessionV2beta: session_v2beta.NewSessionServiceClient(cc),
|
|
|
|
SessionV2: session.NewSessionServiceClient(cc),
|
|
|
|
SettingsV2beta: settings_v2beta.NewSettingsServiceClient(cc),
|
|
|
|
SettingsV2: settings.NewSettingsServiceClient(cc),
|
|
|
|
OIDCv2beta: oidc_pb_v2beta.NewOIDCServiceClient(cc),
|
|
|
|
OIDCv2: oidc_pb.NewOIDCServiceClient(cc),
|
|
|
|
OrgV2beta: org_v2beta.NewOrganizationServiceClient(cc),
|
2024-07-31 12:42:12 +00:00
|
|
|
OrgV2: org.NewOrganizationServiceClient(cc),
|
2024-08-14 14:18:14 +00:00
|
|
|
ActionV3Alpha: action.NewZITADELActionsClient(cc),
|
2024-07-26 20:39:55 +00:00
|
|
|
FeatureV2beta: feature_v2beta.NewFeatureServiceClient(cc),
|
|
|
|
FeatureV2: feature.NewFeatureServiceClient(cc),
|
2024-08-28 19:46:45 +00:00
|
|
|
UserSchemaV3: userschema_v3alpha.NewZITADELUserSchemasClient(cc),
|
2024-08-14 14:18:14 +00:00
|
|
|
WebKeyV3Alpha: webkey_v3alpha.NewZITADELWebKeysClient(cc),
|
2024-08-14 18:18:29 +00:00
|
|
|
IDPv2: idp_pb.NewIdentityProviderServiceClient(cc),
|
2024-08-28 19:46:45 +00:00
|
|
|
UserV3Alpha: user_v3alpha.NewZITADELUsersClient(cc),
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
2024-09-06 12:47:57 +00:00
|
|
|
return client, client.pollHealth(ctx)
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
// pollHealth waits until a healthy status is reported.
|
|
|
|
func (c *Client) pollHealth(ctx context.Context) (err error) {
|
|
|
|
for {
|
|
|
|
err = func(ctx context.Context) error {
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
_, err := c.Admin.Healthz(ctx, &admin.HealthzRequest{})
|
|
|
|
return err
|
|
|
|
}(ctx)
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
logging.WithError(err).Debug("poll healthz")
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
case <-time.After(time.Second):
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2023-07-06 06:38:13 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateHumanUser(ctx context.Context) *user_v2.AddHumanUserResponse {
|
|
|
|
resp, err := i.Client.UserV2.AddHumanUser(ctx, &user_v2.AddHumanUserRequest{
|
2023-12-05 11:12:01 +00:00
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
2024-09-06 12:47:57 +00:00
|
|
|
OrgId: i.DefaultOrg.GetId(),
|
2023-06-07 15:28:42 +00:00
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Profile: &user_v2.SetHumanProfile{
|
2023-11-23 14:17:50 +00:00
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
2024-08-28 19:46:45 +00:00
|
|
|
Gender: gu.Ptr(user_v2.Gender_GENDER_MALE),
|
2023-06-07 15:28:42 +00:00
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Email: &user_v2.SetHumanEmail{
|
2023-06-07 15:28:42 +00:00
|
|
|
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user_v2.ReturnEmailVerificationCode{},
|
2023-06-07 15:28:42 +00:00
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Phone: &user_v2.SetHumanPhone{
|
2023-08-03 04:42:59 +00:00
|
|
|
Phone: "+41791234567",
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanPhone_ReturnCode{
|
|
|
|
ReturnCode: &user_v2.ReturnPhoneVerificationCode{},
|
2023-08-03 04:42:59 +00:00
|
|
|
},
|
|
|
|
},
|
2023-06-07 15:28:42 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create human user")
|
2023-06-07 15:28:42 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateHumanUserNoPhone(ctx context.Context) *user_v2.AddHumanUserResponse {
|
|
|
|
resp, err := i.Client.UserV2.AddHumanUser(ctx, &user_v2.AddHumanUserRequest{
|
2024-07-24 13:46:07 +00:00
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
2024-09-06 12:47:57 +00:00
|
|
|
OrgId: i.DefaultOrg.GetId(),
|
2024-07-24 13:46:07 +00:00
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Profile: &user_v2.SetHumanProfile{
|
2024-07-24 13:46:07 +00:00
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
2024-08-28 19:46:45 +00:00
|
|
|
Gender: gu.Ptr(user_v2.Gender_GENDER_MALE),
|
2024-07-24 13:46:07 +00:00
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Email: &user_v2.SetHumanEmail{
|
2024-07-24 13:46:07 +00:00
|
|
|
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user_v2.ReturnEmailVerificationCode{},
|
2024-07-24 13:46:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create human user")
|
2024-07-24 13:46:07 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateHumanUserWithTOTP(ctx context.Context, secret string) *user_v2.AddHumanUserResponse {
|
|
|
|
resp, err := i.Client.UserV2.AddHumanUser(ctx, &user_v2.AddHumanUserRequest{
|
2024-05-14 07:20:31 +00:00
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
2024-09-06 12:47:57 +00:00
|
|
|
OrgId: i.DefaultOrg.GetId(),
|
2024-05-14 07:20:31 +00:00
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Profile: &user_v2.SetHumanProfile{
|
2024-05-14 07:20:31 +00:00
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
2024-08-28 19:46:45 +00:00
|
|
|
Gender: gu.Ptr(user_v2.Gender_GENDER_MALE),
|
2024-05-14 07:20:31 +00:00
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Email: &user_v2.SetHumanEmail{
|
2024-05-14 07:20:31 +00:00
|
|
|
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user_v2.ReturnEmailVerificationCode{},
|
2024-05-14 07:20:31 +00:00
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Phone: &user_v2.SetHumanPhone{
|
2024-05-14 07:20:31 +00:00
|
|
|
Phone: "+41791234567",
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanPhone_ReturnCode{
|
|
|
|
ReturnCode: &user_v2.ReturnPhoneVerificationCode{},
|
2024-05-14 07:20:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
TotpSecret: gu.Ptr(secret),
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create human user")
|
2024-05-14 07:20:31 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateOrganization(ctx context.Context, name, adminEmail string) *org.AddOrganizationResponse {
|
|
|
|
resp, err := i.Client.OrgV2.AddOrganization(ctx, &org.AddOrganizationRequest{
|
2024-01-17 09:00:10 +00:00
|
|
|
Name: name,
|
|
|
|
Admins: []*org.AddOrganizationRequest_Admin{
|
|
|
|
{
|
|
|
|
UserType: &org.AddOrganizationRequest_Admin_Human{
|
2024-08-28 19:46:45 +00:00
|
|
|
Human: &user_v2.AddHumanUserRequest{
|
|
|
|
Profile: &user_v2.SetHumanProfile{
|
2024-01-17 09:00:10 +00:00
|
|
|
GivenName: "firstname",
|
|
|
|
FamilyName: "lastname",
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Email: &user_v2.SetHumanEmail{
|
2024-01-17 09:00:10 +00:00
|
|
|
Email: adminEmail,
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user_v2.ReturnEmailVerificationCode{},
|
2024-01-17 09:00:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create org")
|
2024-01-17 09:00:10 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) DeactivateOrganization(ctx context.Context, orgID string) *mgmt.DeactivateOrgResponse {
|
|
|
|
resp, err := i.Client.Mgmt.DeactivateOrg(
|
2024-08-15 04:37:06 +00:00
|
|
|
SetOrgID(ctx, orgID),
|
|
|
|
&mgmt.DeactivateOrgRequest{},
|
|
|
|
)
|
|
|
|
logging.OnError(err).Fatal("deactivate org")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetOrgID(ctx context.Context, orgID string) context.Context {
|
|
|
|
md, ok := metadata.FromOutgoingContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
return metadata.AppendToOutgoingContext(ctx, "x-zitadel-orgid", orgID)
|
|
|
|
}
|
|
|
|
md.Set("x-zitadel-orgid", orgID)
|
|
|
|
return metadata.NewOutgoingContext(ctx, md)
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateOrganizationWithUserID(ctx context.Context, name, userID string) *org.AddOrganizationResponse {
|
|
|
|
resp, err := i.Client.OrgV2.AddOrganization(ctx, &org.AddOrganizationRequest{
|
2024-08-15 04:37:06 +00:00
|
|
|
Name: name,
|
|
|
|
Admins: []*org.AddOrganizationRequest_Admin{
|
|
|
|
{
|
|
|
|
UserType: &org.AddOrganizationRequest_Admin_UserId{
|
|
|
|
UserId: userID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create org")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateHumanUserVerified(ctx context.Context, org, email string) *user_v2.AddHumanUserResponse {
|
|
|
|
resp, err := i.Client.UserV2.AddHumanUser(ctx, &user_v2.AddHumanUserRequest{
|
2024-01-17 09:00:10 +00:00
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
|
|
|
OrgId: org,
|
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Profile: &user_v2.SetHumanProfile{
|
2024-01-17 09:00:10 +00:00
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
2024-08-28 19:46:45 +00:00
|
|
|
Gender: gu.Ptr(user_v2.Gender_GENDER_MALE),
|
2024-01-17 09:00:10 +00:00
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Email: &user_v2.SetHumanEmail{
|
2024-01-17 09:00:10 +00:00
|
|
|
Email: email,
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanEmail_IsVerified{
|
2024-01-17 09:00:10 +00:00
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
2024-08-28 19:46:45 +00:00
|
|
|
Phone: &user_v2.SetHumanPhone{
|
2024-01-17 09:00:10 +00:00
|
|
|
Phone: "+41791234567",
|
2024-08-28 19:46:45 +00:00
|
|
|
Verification: &user_v2.SetHumanPhone_IsVerified{
|
2024-01-17 09:00:10 +00:00
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create human user")
|
2024-01-17 09:00:10 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateMachineUser(ctx context.Context) *mgmt.AddMachineUserResponse {
|
|
|
|
resp, err := i.Client.Mgmt.AddMachineUser(ctx, &mgmt.AddMachineUserRequest{
|
2023-12-21 09:03:37 +00:00
|
|
|
UserName: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
|
|
|
Name: "Mickey",
|
|
|
|
Description: "Mickey Mouse",
|
|
|
|
AccessTokenType: user_pb.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER,
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create human user")
|
2023-12-21 09:03:37 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateUserIDPlink(ctx context.Context, userID, externalID, idpID, username string) (*user_v2.AddIDPLinkResponse, error) {
|
|
|
|
return i.Client.UserV2.AddIDPLink(
|
2023-06-21 14:06:18 +00:00
|
|
|
ctx,
|
2024-08-28 19:46:45 +00:00
|
|
|
&user_v2.AddIDPLinkRequest{
|
2023-06-21 14:06:18 +00:00
|
|
|
UserId: userID,
|
2024-08-28 19:46:45 +00:00
|
|
|
IdpLink: &user_v2.IDPLink{
|
2023-06-21 14:06:18 +00:00
|
|
|
IdpId: idpID,
|
|
|
|
UserId: externalID,
|
|
|
|
UserName: username,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) RegisterUserPasskey(ctx context.Context, userID string) {
|
|
|
|
reg, err := i.Client.UserV2.CreatePasskeyRegistrationLink(ctx, &user_v2.CreatePasskeyRegistrationLinkRequest{
|
2023-06-07 15:28:42 +00:00
|
|
|
UserId: userID,
|
2024-08-28 19:46:45 +00:00
|
|
|
Medium: &user_v2.CreatePasskeyRegistrationLinkRequest_ReturnCode{},
|
2023-06-07 15:28:42 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create user passkey")
|
2023-06-07 15:28:42 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
pkr, err := i.Client.UserV2.RegisterPasskey(ctx, &user_v2.RegisterPasskeyRequest{
|
2023-06-07 15:28:42 +00:00
|
|
|
UserId: userID,
|
|
|
|
Code: reg.GetCode(),
|
2024-09-06 12:47:57 +00:00
|
|
|
Domain: i.Domain,
|
2023-06-07 15:28:42 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create user passkey")
|
|
|
|
attestationResponse, err := i.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions())
|
|
|
|
logging.OnError(err).Panic("create user passkey")
|
2023-06-07 15:28:42 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
_, err = i.Client.UserV2.VerifyPasskeyRegistration(ctx, &user_v2.VerifyPasskeyRegistrationRequest{
|
2023-06-07 15:28:42 +00:00
|
|
|
UserId: userID,
|
|
|
|
PasskeyId: pkr.GetPasskeyId(),
|
|
|
|
PublicKeyCredential: attestationResponse,
|
|
|
|
PasskeyName: "nice name",
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create user passkey")
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
2023-06-21 14:06:18 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) RegisterUserU2F(ctx context.Context, userID string) {
|
|
|
|
pkr, err := i.Client.UserV2.RegisterU2F(ctx, &user_v2.RegisterU2FRequest{
|
2023-08-11 15:36:18 +00:00
|
|
|
UserId: userID,
|
2024-09-06 12:47:57 +00:00
|
|
|
Domain: i.Domain,
|
2023-08-11 15:36:18 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create user u2f")
|
|
|
|
attestationResponse, err := i.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions())
|
|
|
|
logging.OnError(err).Panic("create user u2f")
|
2023-08-11 15:36:18 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
_, err = i.Client.UserV2.VerifyU2FRegistration(ctx, &user_v2.VerifyU2FRegistrationRequest{
|
2023-08-11 15:36:18 +00:00
|
|
|
UserId: userID,
|
|
|
|
U2FId: pkr.GetU2FId(),
|
|
|
|
PublicKeyCredential: attestationResponse,
|
|
|
|
TokenName: "nice name",
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create user u2f")
|
2023-08-11 15:36:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) SetUserPassword(ctx context.Context, userID, password string, changeRequired bool) *object.Details {
|
|
|
|
resp, err := i.Client.UserV2.SetPassword(ctx, &user_v2.SetPasswordRequest{
|
2024-03-28 06:21:21 +00:00
|
|
|
UserId: userID,
|
2024-08-28 19:46:45 +00:00
|
|
|
NewPassword: &user_v2.Password{
|
2024-03-28 06:21:21 +00:00
|
|
|
Password: password,
|
|
|
|
ChangeRequired: changeRequired,
|
|
|
|
},
|
2023-07-14 11:16:16 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("set user password")
|
2024-07-10 15:49:35 +00:00
|
|
|
return resp.GetDetails()
|
2023-07-14 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) AddGenericOAuthProvider(ctx context.Context, name string) *admin.AddGenericOAuthProviderResponse {
|
|
|
|
resp, err := i.Client.Admin.AddGenericOAuthProvider(ctx, &admin.AddGenericOAuthProviderRequest{
|
2024-08-14 18:18:29 +00:00
|
|
|
Name: name,
|
|
|
|
ClientId: "clientID",
|
|
|
|
ClientSecret: "clientSecret",
|
|
|
|
AuthorizationEndpoint: "https://example.com/oauth/v2/authorize",
|
|
|
|
TokenEndpoint: "https://example.com/oauth/v2/token",
|
|
|
|
UserEndpoint: "https://api.example.com/user",
|
|
|
|
Scopes: []string{"openid", "profile", "email"},
|
|
|
|
IdAttribute: "id",
|
|
|
|
ProviderOptions: &idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create generic OAuth idp")
|
2024-08-14 18:18:29 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
mustAwait(func() error {
|
|
|
|
_, err := i.Client.Admin.GetProviderByID(ctx, &admin.GetProviderByIDRequest{
|
|
|
|
Id: resp.GetId(),
|
|
|
|
})
|
|
|
|
return err
|
2023-06-21 14:06:18 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
|
|
|
|
return resp
|
2023-06-21 14:06:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) AddOrgGenericOAuthProvider(ctx context.Context, name string) *mgmt.AddGenericOAuthProviderResponse {
|
|
|
|
resp, err := i.Client.Mgmt.AddGenericOAuthProvider(ctx, &mgmt.AddGenericOAuthProviderRequest{
|
2024-08-14 18:18:29 +00:00
|
|
|
Name: name,
|
|
|
|
ClientId: "clientID",
|
|
|
|
ClientSecret: "clientSecret",
|
|
|
|
AuthorizationEndpoint: "https://example.com/oauth/v2/authorize",
|
|
|
|
TokenEndpoint: "https://example.com/oauth/v2/token",
|
|
|
|
UserEndpoint: "https://api.example.com/user",
|
|
|
|
Scopes: []string{"openid", "profile", "email"},
|
|
|
|
IdAttribute: "id",
|
|
|
|
ProviderOptions: &idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create generic OAuth idp")
|
|
|
|
/*
|
|
|
|
mustAwait(func() error {
|
|
|
|
_, err := i.Client.Mgmt.GetProviderByID(ctx, &mgmt.GetProviderByIDRequest{
|
|
|
|
Id: resp.GetId(),
|
|
|
|
})
|
|
|
|
return err
|
2024-05-07 06:11:20 +00:00
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
*/
|
|
|
|
return resp
|
2024-05-07 06:11:20 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) AddSAMLProvider(ctx context.Context) string {
|
|
|
|
resp, err := i.Client.Admin.AddSAMLProvider(ctx, &admin.AddSAMLProviderRequest{
|
|
|
|
Name: "saml-idp",
|
|
|
|
Metadata: &admin.AddSAMLProviderRequest_MetadataXml{
|
|
|
|
MetadataXml: []byte("<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" validUntil=\"2023-09-16T09:00:32.986Z\" cacheDuration=\"PT48H\" entityID=\"http://localhost:8000/metadata\">\n <IDPSSODescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n <KeyDescriptor use=\"signing\">\n <KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Certificate xmlns=\"http://www.w3.org/2000/09/xmldsig#\">MIIDBzCCAe+gAwIBAgIJAPr/Mrlc8EGhMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNTEyMjgxOTE5NDVaFw0yNTEyMjUxOTE5NDVaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANDoWzLos4LWxTn8Gyu2lEbl4WcelUbgLN5zYm4ron8Ahs+rvcsu2zkdD/s6jdGJI8WqJKhYK2u61ygnXgAZqC6ggtFPnBpizcDzjgND2g+aucSoUODHt67f0fQuAmupN/zp5MZysJ6IHLJnYLNpfJYk96lRz9ODnO1Mpqtr9PWxm+pz7nzq5F0vRepkgpcRxv6ufQBjlrFytccyEVdXrvFtkjXcnhVVNSR4kHuOOMS6D7pebSJ1mrCmshbD5SX1jXPBKFPAjozYX6PxqLxUx1Y4faFEf4MBBVcInyB4oURNB2s59hEEi2jq9izNE7EbEK6BY5sEhoCPl9m32zE6ljkCAwEAAaNQME4wHQYDVR0OBBYEFB9ZklC1Ork2zl56zg08ei7ss/+iMB8GA1UdIwQYMBaAFB9ZklC1Ork2zl56zg08ei7ss/+iMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAVoTSQ5pAirw8OR9FZ1bRSuTDhY9uxzl/OL7lUmsv2cMNeCB3BRZqm3mFt+cwN8GsH6f3uvNONIhgFpTGN5LEcXQz89zJEzB+qaHqmbFpHQl/sx2B8ezNgT/882H2IH00dXESEfy/+1gHg2pxjGnhRBN6el/gSaDiySIMKbilDrffuvxiCfbpPN0NRRiPJhd2ay9KuL/RxQRl1gl9cHaWiouWWba1bSBb2ZPhv2rPMUsFo98ntkGCObDX6Y1SpkqmoTbrsbGFsTG2DLxnvr4GdN1BSr0Uu/KV3adj47WkXVPeMYQti/bQmxQB8tRFhrw80qakTLUzreO96WzlBBMtY=</X509Certificate>\n </X509Data>\n </KeyInfo>\n </KeyDescriptor>\n <KeyDescriptor use=\"encryption\">\n <KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Certificate xmlns=\"http://www.w3.org/2000/09/xmldsig#\">MIIDBzCCAe+gAwIBAgIJAPr/Mrlc8EGhMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNTEyMjgxOTE5NDVaFw0yNTEyMjUxOTE5NDVaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANDoWzLos4LWxTn8Gyu2lEbl4WcelUbgLN5zYm4ron8Ahs+rvcsu2zkdD/s6jdGJI8WqJKhYK2u61ygnXgAZqC6ggtFPnBpizcDzjgND2g+aucSoUODHt67f0fQuAmupN/zp5MZysJ6IHLJnYLNpfJYk96lRz9ODnO1Mpqtr9PWxm+pz7nzq5F0vRepkgpcRxv6ufQBjlrFytccyEVdXrvFtkjXcnhVVNSR4kHuOOMS6D7pebSJ1mrCmshbD5SX1jXPBKFPAjozYX6PxqLxUx1Y4faFEf4MBBVcInyB4oURNB2s59hEEi2jq9izNE7EbEK6BY5sEhoCPl9m32zE6ljkCAwEAAaNQME4wHQYDVR0OBBYEFB9ZklC1Ork2zl56zg08ei7ss/+iMB8GA1UdIwQYMBaAFB9ZklC1Ork2zl56zg08ei7ss/+iMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAVoTSQ5pAirw8OR9FZ1bRSuTDhY9uxzl/OL7lUmsv2cMNeCB3BRZqm3mFt+cwN8GsH6f3uvNONIhgFpTGN5LEcXQz89zJEzB+qaHqmbFpHQl/sx2B8ezNgT/882H2IH00dXESEfy/+1gHg2pxjGnhRBN6el/gSaDiySIMKbilDrffuvxiCfbpPN0NRRiPJhd2ay9KuL/RxQRl1gl9cHaWiouWWba1bSBb2ZPhv2rPMUsFo98ntkGCObDX6Y1SpkqmoTbrsbGFsTG2DLxnvr4GdN1BSr0Uu/KV3adj47WkXVPeMYQti/bQmxQB8tRFhrw80qakTLUzreO96WzlBBMtY=</X509Certificate>\n </X509Data>\n </KeyInfo>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes128-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes192-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes256-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\"></EncryptionMethod>\n </KeyDescriptor>\n <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>\n <SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" Location=\"http://localhost:8000/sso\"></SingleSignOnService>\n <SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" Location=\"http://localhost:8000/sso\"></SingleSignOnService>\n </IDPSSODescriptor>\n</EntityDescriptor>"),
|
|
|
|
},
|
|
|
|
ProviderOptions: &idp.Options{
|
2023-09-29 09:26:14 +00:00
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create saml idp")
|
|
|
|
return resp.GetId()
|
2023-09-29 09:26:14 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) AddSAMLRedirectProvider(ctx context.Context, transientMappingAttributeName string) string {
|
|
|
|
resp, err := i.Client.Admin.AddSAMLProvider(ctx, &admin.AddSAMLProviderRequest{
|
|
|
|
Name: "saml-idp-redirect",
|
|
|
|
Binding: idp.SAMLBinding_SAML_BINDING_REDIRECT,
|
|
|
|
Metadata: &admin.AddSAMLProviderRequest_MetadataXml{
|
|
|
|
MetadataXml: []byte("<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" validUntil=\"2023-09-16T09:00:32.986Z\" cacheDuration=\"PT48H\" entityID=\"http://localhost:8000/metadata\">\n <IDPSSODescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n <KeyDescriptor use=\"signing\">\n <KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Certificate xmlns=\"http://www.w3.org/2000/09/xmldsig#\">MIIDBzCCAe+gAwIBAgIJAPr/Mrlc8EGhMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNTEyMjgxOTE5NDVaFw0yNTEyMjUxOTE5NDVaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANDoWzLos4LWxTn8Gyu2lEbl4WcelUbgLN5zYm4ron8Ahs+rvcsu2zkdD/s6jdGJI8WqJKhYK2u61ygnXgAZqC6ggtFPnBpizcDzjgND2g+aucSoUODHt67f0fQuAmupN/zp5MZysJ6IHLJnYLNpfJYk96lRz9ODnO1Mpqtr9PWxm+pz7nzq5F0vRepkgpcRxv6ufQBjlrFytccyEVdXrvFtkjXcnhVVNSR4kHuOOMS6D7pebSJ1mrCmshbD5SX1jXPBKFPAjozYX6PxqLxUx1Y4faFEf4MBBVcInyB4oURNB2s59hEEi2jq9izNE7EbEK6BY5sEhoCPl9m32zE6ljkCAwEAAaNQME4wHQYDVR0OBBYEFB9ZklC1Ork2zl56zg08ei7ss/+iMB8GA1UdIwQYMBaAFB9ZklC1Ork2zl56zg08ei7ss/+iMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAVoTSQ5pAirw8OR9FZ1bRSuTDhY9uxzl/OL7lUmsv2cMNeCB3BRZqm3mFt+cwN8GsH6f3uvNONIhgFpTGN5LEcXQz89zJEzB+qaHqmbFpHQl/sx2B8ezNgT/882H2IH00dXESEfy/+1gHg2pxjGnhRBN6el/gSaDiySIMKbilDrffuvxiCfbpPN0NRRiPJhd2ay9KuL/RxQRl1gl9cHaWiouWWba1bSBb2ZPhv2rPMUsFo98ntkGCObDX6Y1SpkqmoTbrsbGFsTG2DLxnvr4GdN1BSr0Uu/KV3adj47WkXVPeMYQti/bQmxQB8tRFhrw80qakTLUzreO96WzlBBMtY=</X509Certificate>\n </X509Data>\n </KeyInfo>\n </KeyDescriptor>\n <KeyDescriptor use=\"encryption\">\n <KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Certificate xmlns=\"http://www.w3.org/2000/09/xmldsig#\">MIIDBzCCAe+gAwIBAgIJAPr/Mrlc8EGhMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNTEyMjgxOTE5NDVaFw0yNTEyMjUxOTE5NDVaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANDoWzLos4LWxTn8Gyu2lEbl4WcelUbgLN5zYm4ron8Ahs+rvcsu2zkdD/s6jdGJI8WqJKhYK2u61ygnXgAZqC6ggtFPnBpizcDzjgND2g+aucSoUODHt67f0fQuAmupN/zp5MZysJ6IHLJnYLNpfJYk96lRz9ODnO1Mpqtr9PWxm+pz7nzq5F0vRepkgpcRxv6ufQBjlrFytccyEVdXrvFtkjXcnhVVNSR4kHuOOMS6D7pebSJ1mrCmshbD5SX1jXPBKFPAjozYX6PxqLxUx1Y4faFEf4MBBVcInyB4oURNB2s59hEEi2jq9izNE7EbEK6BY5sEhoCPl9m32zE6ljkCAwEAAaNQME4wHQYDVR0OBBYEFB9ZklC1Ork2zl56zg08ei7ss/+iMB8GA1UdIwQYMBaAFB9ZklC1Ork2zl56zg08ei7ss/+iMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAVoTSQ5pAirw8OR9FZ1bRSuTDhY9uxzl/OL7lUmsv2cMNeCB3BRZqm3mFt+cwN8GsH6f3uvNONIhgFpTGN5LEcXQz89zJEzB+qaHqmbFpHQl/sx2B8ezNgT/882H2IH00dXESEfy/+1gHg2pxjGnhRBN6el/gSaDiySIMKbilDrffuvxiCfbpPN0NRRiPJhd2ay9KuL/RxQRl1gl9cHaWiouWWba1bSBb2ZPhv2rPMUsFo98ntkGCObDX6Y1SpkqmoTbrsbGFsTG2DLxnvr4GdN1BSr0Uu/KV3adj47WkXVPeMYQti/bQmxQB8tRFhrw80qakTLUzreO96WzlBBMtY=</X509Certificate>\n </X509Data>\n </KeyInfo>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes128-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes192-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes256-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\"></EncryptionMethod>\n </KeyDescriptor>\n <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>\n <SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" Location=\"http://localhost:8000/sso\"></SingleSignOnService>\n </IDPSSODescriptor>\n</EntityDescriptor>"),
|
|
|
|
},
|
|
|
|
TransientMappingAttributeName: &transientMappingAttributeName,
|
|
|
|
ProviderOptions: &idp.Options{
|
2023-09-29 09:26:14 +00:00
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create saml idp")
|
|
|
|
return resp.GetId()
|
2023-09-29 09:26:14 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) AddSAMLPostProvider(ctx context.Context) string {
|
|
|
|
resp, err := i.Client.Admin.AddSAMLProvider(ctx, &admin.AddSAMLProviderRequest{
|
|
|
|
Name: "saml-idp-post",
|
|
|
|
Binding: idp.SAMLBinding_SAML_BINDING_POST,
|
|
|
|
Metadata: &admin.AddSAMLProviderRequest_MetadataXml{
|
|
|
|
MetadataXml: []byte("<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" validUntil=\"2023-09-16T09:00:32.986Z\" cacheDuration=\"PT48H\" entityID=\"http://localhost:8000/metadata\">\n <IDPSSODescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n <KeyDescriptor use=\"signing\">\n <KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Certificate xmlns=\"http://www.w3.org/2000/09/xmldsig#\">MIIDBzCCAe+gAwIBAgIJAPr/Mrlc8EGhMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNTEyMjgxOTE5NDVaFw0yNTEyMjUxOTE5NDVaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANDoWzLos4LWxTn8Gyu2lEbl4WcelUbgLN5zYm4ron8Ahs+rvcsu2zkdD/s6jdGJI8WqJKhYK2u61ygnXgAZqC6ggtFPnBpizcDzjgND2g+aucSoUODHt67f0fQuAmupN/zp5MZysJ6IHLJnYLNpfJYk96lRz9ODnO1Mpqtr9PWxm+pz7nzq5F0vRepkgpcRxv6ufQBjlrFytccyEVdXrvFtkjXcnhVVNSR4kHuOOMS6D7pebSJ1mrCmshbD5SX1jXPBKFPAjozYX6PxqLxUx1Y4faFEf4MBBVcInyB4oURNB2s59hEEi2jq9izNE7EbEK6BY5sEhoCPl9m32zE6ljkCAwEAAaNQME4wHQYDVR0OBBYEFB9ZklC1Ork2zl56zg08ei7ss/+iMB8GA1UdIwQYMBaAFB9ZklC1Ork2zl56zg08ei7ss/+iMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAVoTSQ5pAirw8OR9FZ1bRSuTDhY9uxzl/OL7lUmsv2cMNeCB3BRZqm3mFt+cwN8GsH6f3uvNONIhgFpTGN5LEcXQz89zJEzB+qaHqmbFpHQl/sx2B8ezNgT/882H2IH00dXESEfy/+1gHg2pxjGnhRBN6el/gSaDiySIMKbilDrffuvxiCfbpPN0NRRiPJhd2ay9KuL/RxQRl1gl9cHaWiouWWba1bSBb2ZPhv2rPMUsFo98ntkGCObDX6Y1SpkqmoTbrsbGFsTG2DLxnvr4GdN1BSr0Uu/KV3adj47WkXVPeMYQti/bQmxQB8tRFhrw80qakTLUzreO96WzlBBMtY=</X509Certificate>\n </X509Data>\n </KeyInfo>\n </KeyDescriptor>\n <KeyDescriptor use=\"encryption\">\n <KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Data xmlns=\"http://www.w3.org/2000/09/xmldsig#\">\n <X509Certificate xmlns=\"http://www.w3.org/2000/09/xmldsig#\">MIIDBzCCAe+gAwIBAgIJAPr/Mrlc8EGhMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNTEyMjgxOTE5NDVaFw0yNTEyMjUxOTE5NDVaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANDoWzLos4LWxTn8Gyu2lEbl4WcelUbgLN5zYm4ron8Ahs+rvcsu2zkdD/s6jdGJI8WqJKhYK2u61ygnXgAZqC6ggtFPnBpizcDzjgND2g+aucSoUODHt67f0fQuAmupN/zp5MZysJ6IHLJnYLNpfJYk96lRz9ODnO1Mpqtr9PWxm+pz7nzq5F0vRepkgpcRxv6ufQBjlrFytccyEVdXrvFtkjXcnhVVNSR4kHuOOMS6D7pebSJ1mrCmshbD5SX1jXPBKFPAjozYX6PxqLxUx1Y4faFEf4MBBVcInyB4oURNB2s59hEEi2jq9izNE7EbEK6BY5sEhoCPl9m32zE6ljkCAwEAAaNQME4wHQYDVR0OBBYEFB9ZklC1Ork2zl56zg08ei7ss/+iMB8GA1UdIwQYMBaAFB9ZklC1Ork2zl56zg08ei7ss/+iMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAVoTSQ5pAirw8OR9FZ1bRSuTDhY9uxzl/OL7lUmsv2cMNeCB3BRZqm3mFt+cwN8GsH6f3uvNONIhgFpTGN5LEcXQz89zJEzB+qaHqmbFpHQl/sx2B8ezNgT/882H2IH00dXESEfy/+1gHg2pxjGnhRBN6el/gSaDiySIMKbilDrffuvxiCfbpPN0NRRiPJhd2ay9KuL/RxQRl1gl9cHaWiouWWba1bSBb2ZPhv2rPMUsFo98ntkGCObDX6Y1SpkqmoTbrsbGFsTG2DLxnvr4GdN1BSr0Uu/KV3adj47WkXVPeMYQti/bQmxQB8tRFhrw80qakTLUzreO96WzlBBMtY=</X509Certificate>\n </X509Data>\n </KeyInfo>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes128-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes192-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes256-cbc\"></EncryptionMethod>\n <EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\"></EncryptionMethod>\n </KeyDescriptor>\n <NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</NameIDFormat>\n <SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" Location=\"http://localhost:8000/sso\"></SingleSignOnService>\n </IDPSSODescriptor>\n</EntityDescriptor>"),
|
|
|
|
},
|
|
|
|
ProviderOptions: &idp.Options{
|
2023-09-29 09:26:14 +00:00
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
2024-09-06 12:47:57 +00:00
|
|
|
logging.OnError(err).Panic("create saml idp")
|
|
|
|
return resp.GetId()
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func (s *Instance) CreateIntent(t *testing.T, ctx context.Context, idpID string) string {
|
|
|
|
resp, err := i.Client.UserV2.StartIdentityProviderIntent(ctx, &user.StartIdentityProviderIntentRequest{
|
|
|
|
IdpId: idpID,
|
|
|
|
Content: &user.StartIdentityProviderIntentRequest_Urls{
|
|
|
|
Urls: &user.RedirectURLs{
|
|
|
|
SuccessUrl: "https://example.com/success",
|
|
|
|
FailureUrl: "https://example.com/failure",
|
|
|
|
},
|
|
|
|
AutoLinking: idp.AutoLinkingOption_AUTO_LINKING_OPTION_USERNAME,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create generic OAuth idp")
|
|
|
|
return resp
|
2023-09-29 09:26:14 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateIntent(t *testing.T, ctx context.Context, idpID string) string {
|
2024-05-07 06:11:20 +00:00
|
|
|
ctx = authz.WithInstance(context.WithoutCancel(ctx), s.Instance)
|
|
|
|
writeModel, _, err := s.Commands.CreateIntent(ctx, idpID, "https://example.com/success", "https://example.com/failure", s.Instance.InstanceID())
|
2023-06-21 14:06:18 +00:00
|
|
|
require.NoError(t, err)
|
2023-08-16 11:29:57 +00:00
|
|
|
return writeModel.AggregateID
|
2023-06-21 14:06:18 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateSuccessfulOAuthIntent(t *testing.T, ctx context.Context, idpID, userID, idpUserID string) (string, string, time.Time, uint64) {
|
2024-05-07 06:11:20 +00:00
|
|
|
ctx = authz.WithInstance(context.WithoutCancel(ctx), s.Instance)
|
|
|
|
intentID := s.CreateIntent(t, ctx, idpID)
|
|
|
|
writeModel, err := s.Commands.GetIntentWriteModel(ctx, intentID, s.Instance.InstanceID())
|
2023-06-21 14:06:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
idpUser := openid.NewUser(
|
|
|
|
&oidc.UserInfo{
|
|
|
|
Subject: idpUserID,
|
|
|
|
UserInfoProfile: oidc.UserInfoProfile{
|
|
|
|
PreferredUsername: "username",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
idpSession := &openid.Session{
|
|
|
|
Tokens: &oidc.Tokens[*oidc.IDTokenClaims]{
|
|
|
|
Token: &oauth2.Token{
|
|
|
|
AccessToken: "accessToken",
|
|
|
|
},
|
|
|
|
IDToken: "idToken",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
token, err := s.Commands.SucceedIDPIntent(ctx, writeModel, idpUser, idpSession, userID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return intentID, token, writeModel.ChangeDate, writeModel.ProcessedSequence
|
|
|
|
}
|
2023-07-10 13:27:00 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (s *Instance) CreateSuccessfulLDAPIntent(t *testing.T, ctx context.Context, idpID, userID, idpUserID string) (string, string, time.Time, uint64) {
|
2024-05-07 06:11:20 +00:00
|
|
|
ctx = authz.WithInstance(context.WithoutCancel(ctx), s.Instance)
|
|
|
|
intentID := s.CreateIntent(t, ctx, idpID)
|
|
|
|
writeModel, err := s.Commands.GetIntentWriteModel(ctx, intentID, s.Instance.InstanceID())
|
2023-08-16 11:29:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
username := "username"
|
|
|
|
lang := language.Make("en")
|
|
|
|
idpUser := ldap.NewUser(
|
|
|
|
idpUserID,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
username,
|
|
|
|
"",
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
false,
|
|
|
|
lang,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
)
|
|
|
|
attributes := map[string][]string{"id": {idpUserID}, "username": {username}, "language": {lang.String()}}
|
|
|
|
token, err := s.Commands.SucceedLDAPIDPIntent(ctx, writeModel, idpUser, userID, attributes)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return intentID, token, writeModel.ChangeDate, writeModel.ProcessedSequence
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (s *Instance) CreateSuccessfulSAMLIntent(t *testing.T, ctx context.Context, idpID, userID, idpUserID string) (string, string, time.Time, uint64) {
|
2024-05-07 06:11:20 +00:00
|
|
|
ctx = authz.WithInstance(context.WithoutCancel(ctx), s.Instance)
|
|
|
|
intentID := s.CreateIntent(t, ctx, idpID)
|
|
|
|
writeModel, err := s.Server.Commands.GetIntentWriteModel(ctx, intentID, s.Instance.InstanceID())
|
2023-09-29 09:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
idpUser := &saml.UserMapper{
|
|
|
|
ID: idpUserID,
|
|
|
|
Attributes: map[string][]string{"attribute1": {"value1"}},
|
|
|
|
}
|
|
|
|
assertion := &crewjam_saml.Assertion{ID: "id"}
|
|
|
|
|
|
|
|
token, err := s.Server.Commands.SucceedSAMLIDPIntent(ctx, writeModel, idpUser, userID, assertion)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return intentID, token, writeModel.ChangeDate, writeModel.ProcessedSequence
|
|
|
|
}
|
2024-09-06 12:47:57 +00:00
|
|
|
*/
|
2023-09-29 09:26:14 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateVerifiedWebAuthNSession(t *testing.T, ctx context.Context, userID string) (id, token string, start, change time.Time) {
|
|
|
|
return i.CreateVerifiedWebAuthNSessionWithLifetime(t, ctx, userID, 0)
|
2023-11-06 09:48:28 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateVerifiedWebAuthNSessionWithLifetime(t *testing.T, ctx context.Context, userID string, lifetime time.Duration) (id, token string, start, change time.Time) {
|
2023-11-06 09:48:28 +00:00
|
|
|
var sessionLifetime *durationpb.Duration
|
|
|
|
if lifetime > 0 {
|
|
|
|
sessionLifetime = durationpb.New(lifetime)
|
|
|
|
}
|
2024-09-06 12:47:57 +00:00
|
|
|
createResp, err := i.Client.SessionV2.CreateSession(ctx, &session.CreateSessionRequest{
|
2023-07-10 13:27:00 +00:00
|
|
|
Checks: &session.Checks{
|
|
|
|
User: &session.CheckUser{
|
|
|
|
Search: &session.CheckUser_UserId{UserId: userID},
|
|
|
|
},
|
|
|
|
},
|
2023-08-11 15:36:18 +00:00
|
|
|
Challenges: &session.RequestChallenges{
|
|
|
|
WebAuthN: &session.RequestChallenges_WebAuthN{
|
2024-09-06 12:47:57 +00:00
|
|
|
Domain: i.Domain,
|
2023-08-11 15:36:18 +00:00
|
|
|
UserVerificationRequirement: session.UserVerificationRequirement_USER_VERIFICATION_REQUIREMENT_REQUIRED,
|
|
|
|
},
|
2023-07-10 13:27:00 +00:00
|
|
|
},
|
2023-11-06 09:48:28 +00:00
|
|
|
Lifetime: sessionLifetime,
|
2023-07-10 13:27:00 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
assertion, err := i.WebAuthN.CreateAssertionResponse(createResp.GetChallenges().GetWebAuthN().GetPublicKeyCredentialRequestOptions(), true)
|
2023-07-10 13:27:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
updateResp, err := i.Client.SessionV2.SetSession(ctx, &session.SetSessionRequest{
|
2024-05-22 05:56:11 +00:00
|
|
|
SessionId: createResp.GetSessionId(),
|
2023-07-10 13:27:00 +00:00
|
|
|
Checks: &session.Checks{
|
2023-08-11 15:36:18 +00:00
|
|
|
WebAuthN: &session.CheckWebAuthN{
|
2023-07-10 13:27:00 +00:00
|
|
|
CredentialAssertionData: assertion,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return createResp.GetSessionId(), updateResp.GetSessionToken(),
|
|
|
|
createResp.GetDetails().GetChangeDate().AsTime(), updateResp.GetDetails().GetChangeDate().AsTime()
|
|
|
|
}
|
2023-07-14 11:16:16 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreatePasswordSession(t *testing.T, ctx context.Context, userID, password string) (id, token string, start, change time.Time) {
|
|
|
|
createResp, err := i.Client.SessionV2.CreateSession(ctx, &session.CreateSessionRequest{
|
2023-07-14 11:16:16 +00:00
|
|
|
Checks: &session.Checks{
|
|
|
|
User: &session.CheckUser{
|
|
|
|
Search: &session.CheckUser_UserId{UserId: userID},
|
|
|
|
},
|
|
|
|
Password: &session.CheckPassword{
|
|
|
|
Password: password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return createResp.GetSessionId(), createResp.GetSessionToken(),
|
|
|
|
createResp.GetDetails().GetChangeDate().AsTime(), createResp.GetDetails().GetChangeDate().AsTime()
|
|
|
|
}
|
2023-12-21 09:03:37 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateProjectUserGrant(t *testing.T, ctx context.Context, projectID, userID string) string {
|
|
|
|
resp, err := i.Client.Mgmt.AddUserGrant(ctx, &mgmt.AddUserGrantRequest{
|
2023-12-21 09:03:37 +00:00
|
|
|
UserId: userID,
|
|
|
|
ProjectId: projectID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return resp.GetUserGrantId()
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateOrgMembership(t *testing.T, ctx context.Context, userID string) {
|
|
|
|
_, err := i.Client.Mgmt.AddOrgMember(ctx, &mgmt.AddOrgMemberRequest{
|
2023-12-21 09:03:37 +00:00
|
|
|
UserId: userID,
|
|
|
|
Roles: []string{domain.RoleOrgOwner},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateProjectMembership(t *testing.T, ctx context.Context, projectID, userID string) {
|
|
|
|
_, err := i.Client.Mgmt.AddProjectMember(ctx, &mgmt.AddProjectMemberRequest{
|
2023-12-21 09:03:37 +00:00
|
|
|
ProjectId: projectID,
|
|
|
|
UserId: userID,
|
|
|
|
Roles: []string{domain.RoleProjectOwner},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2024-02-15 05:39:10 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateTarget(ctx context.Context, t *testing.T, name, endpoint string, ty domain.TargetType, interrupt bool) *action.CreateTargetResponse {
|
|
|
|
if name == "" {
|
|
|
|
name = gofakeit.Name()
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
2024-07-31 12:42:12 +00:00
|
|
|
reqTarget := &action.Target{
|
2024-09-06 12:47:57 +00:00
|
|
|
Name: name,
|
2024-05-04 09:55:57 +00:00
|
|
|
Endpoint: endpoint,
|
|
|
|
Timeout: durationpb.New(10 * time.Second),
|
|
|
|
}
|
|
|
|
switch ty {
|
|
|
|
case domain.TargetTypeWebhook:
|
2024-07-31 12:42:12 +00:00
|
|
|
reqTarget.TargetType = &action.Target_RestWebhook{
|
2024-04-09 17:21:21 +00:00
|
|
|
RestWebhook: &action.SetRESTWebhook{
|
2024-05-04 09:55:57 +00:00
|
|
|
InterruptOnError: interrupt,
|
2024-03-14 09:56:23 +00:00
|
|
|
},
|
|
|
|
}
|
2024-05-04 09:55:57 +00:00
|
|
|
case domain.TargetTypeCall:
|
2024-07-31 12:42:12 +00:00
|
|
|
reqTarget.TargetType = &action.Target_RestCall{
|
2024-05-04 09:55:57 +00:00
|
|
|
RestCall: &action.SetRESTCall{
|
|
|
|
InterruptOnError: interrupt,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
case domain.TargetTypeAsync:
|
2024-07-31 12:42:12 +00:00
|
|
|
reqTarget.TargetType = &action.Target_RestAsync{
|
2024-05-04 09:55:57 +00:00
|
|
|
RestAsync: &action.SetRESTAsync{},
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-06 12:47:57 +00:00
|
|
|
target, err := i.Client.ActionV3Alpha.CreateTarget(ctx, &action.CreateTargetRequest{Target: reqTarget})
|
2024-02-15 05:39:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
return target
|
|
|
|
}
|
2024-02-26 10:49:43 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) DeleteExecution(ctx context.Context, t *testing.T, cond *action.Condition) {
|
|
|
|
_, err := i.Client.ActionV3Alpha.SetExecution(ctx, &action.SetExecutionRequest{
|
2024-02-26 10:49:43 +00:00
|
|
|
Condition: cond,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2024-03-12 13:50:13 +00:00
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) SetExecution(ctx context.Context, t *testing.T, cond *action.Condition, targets []*action.ExecutionTargetType) *action.SetExecutionResponse {
|
|
|
|
target, err := i.Client.ActionV3Alpha.SetExecution(ctx, &action.SetExecutionRequest{
|
2024-05-04 09:55:57 +00:00
|
|
|
Condition: cond,
|
2024-07-31 12:42:12 +00:00
|
|
|
Execution: &action.Execution{
|
|
|
|
Targets: targets,
|
|
|
|
},
|
2024-05-04 09:55:57 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2024-07-31 12:42:12 +00:00
|
|
|
return target
|
2024-05-04 09:55:57 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateUserSchemaEmpty(ctx context.Context) *userschema_v3alpha.CreateUserSchemaResponse {
|
|
|
|
return i.CreateUserSchemaEmptyWithType(ctx, fmt.Sprint(time.Now().UnixNano()+1))
|
2024-03-22 13:26:13 +00:00
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateUserSchema(ctx context.Context, schemaData []byte) *userschema_v3alpha.CreateUserSchemaResponse {
|
2024-08-28 19:46:45 +00:00
|
|
|
userSchema := new(structpb.Struct)
|
|
|
|
err := userSchema.UnmarshalJSON(schemaData)
|
|
|
|
logging.OnError(err).Fatal("create userschema unmarshal")
|
2024-09-06 12:47:57 +00:00
|
|
|
schema, err := i.Client.UserSchemaV3.CreateUserSchema(ctx, &userschema_v3alpha.CreateUserSchemaRequest{
|
2024-09-02 11:24:15 +00:00
|
|
|
UserSchema: &userschema_v3alpha.UserSchema{
|
2024-08-28 19:46:45 +00:00
|
|
|
Type: fmt.Sprint(time.Now().UnixNano() + 1),
|
2024-09-02 11:24:15 +00:00
|
|
|
DataType: &userschema_v3alpha.UserSchema_Schema{
|
2024-08-28 19:46:45 +00:00
|
|
|
Schema: userSchema,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create userschema")
|
|
|
|
return schema
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateUserSchemaEmptyWithType(ctx context.Context, schemaType string) *userschema_v3alpha.CreateUserSchemaResponse {
|
2024-03-12 13:50:13 +00:00
|
|
|
userSchema := new(structpb.Struct)
|
|
|
|
err := userSchema.UnmarshalJSON([]byte(`{
|
|
|
|
"$schema": "urn:zitadel:schema:v1",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {}
|
|
|
|
}`))
|
2024-08-28 19:46:45 +00:00
|
|
|
logging.OnError(err).Fatal("create userschema unmarshal")
|
2024-09-06 12:47:57 +00:00
|
|
|
schema, err := i.Client.UserSchemaV3.CreateUserSchema(ctx, &userschema_v3alpha.CreateUserSchemaRequest{
|
2024-09-02 11:24:15 +00:00
|
|
|
UserSchema: &userschema_v3alpha.UserSchema{
|
2024-08-28 19:46:45 +00:00
|
|
|
Type: schemaType,
|
2024-09-02 11:24:15 +00:00
|
|
|
DataType: &userschema_v3alpha.UserSchema_Schema{
|
2024-08-28 19:46:45 +00:00
|
|
|
Schema: userSchema,
|
|
|
|
},
|
2024-03-12 13:50:13 +00:00
|
|
|
},
|
|
|
|
})
|
2024-08-28 19:46:45 +00:00
|
|
|
logging.OnError(err).Fatal("create userschema")
|
|
|
|
return schema
|
|
|
|
}
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
func (i *Instance) CreateSchemaUser(ctx context.Context, orgID string, schemaID string, data []byte) *user_v3alpha.CreateUserResponse {
|
2024-08-28 19:46:45 +00:00
|
|
|
userData := new(structpb.Struct)
|
|
|
|
err := userData.UnmarshalJSON(data)
|
|
|
|
logging.OnError(err).Fatal("create user unmarshal")
|
2024-09-06 12:47:57 +00:00
|
|
|
user, err := i.Client.UserV3Alpha.CreateUser(ctx, &user_v3alpha.CreateUserRequest{
|
2024-08-28 19:46:45 +00:00
|
|
|
Organization: &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}},
|
|
|
|
User: &user_v3alpha.CreateUser{
|
|
|
|
SchemaId: schemaID,
|
|
|
|
Data: userData,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user")
|
|
|
|
return user
|
2024-03-12 13:50:13 +00:00
|
|
|
}
|
2024-09-11 10:53:55 +00:00
|
|
|
|
2024-09-25 13:31:31 +00:00
|
|
|
func (i *Instance) UpdateSchemaUserEmail(ctx context.Context, orgID string, userID string, email string) *user_v3alpha.SetContactEmailResponse {
|
|
|
|
user, err := i.Client.UserV3Alpha.SetContactEmail(ctx, &user_v3alpha.SetContactEmailRequest{
|
|
|
|
Organization: &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}},
|
|
|
|
Id: userID,
|
|
|
|
Email: &user_v3alpha.SetEmail{
|
|
|
|
Address: email,
|
|
|
|
Verification: &user_v3alpha.SetEmail_ReturnCode{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user")
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) UpdateSchemaUserPhone(ctx context.Context, orgID string, userID string, phone string) *user_v3alpha.SetContactPhoneResponse {
|
|
|
|
user, err := i.Client.UserV3Alpha.SetContactPhone(ctx, &user_v3alpha.SetContactPhoneRequest{
|
|
|
|
Organization: &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}},
|
|
|
|
Id: userID,
|
|
|
|
Phone: &user_v3alpha.SetPhone{
|
|
|
|
Number: phone,
|
|
|
|
Verification: &user_v3alpha.SetPhone_ReturnCode{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user")
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
2024-09-11 10:53:55 +00:00
|
|
|
func (i *Instance) CreateInviteCode(ctx context.Context, userID string) *user_v2.CreateInviteCodeResponse {
|
|
|
|
user, err := i.Client.UserV2.CreateInviteCode(ctx, &user_v2.CreateInviteCodeRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Verification: &user_v2.CreateInviteCodeRequest_ReturnCode{ReturnCode: &user_v2.ReturnInviteCode{}},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create invite code")
|
|
|
|
return user
|
|
|
|
}
|
2024-09-17 08:27:48 +00:00
|
|
|
|
|
|
|
func (i *Instance) LockSchemaUser(ctx context.Context, orgID string, userID string) *user_v3alpha.LockUserResponse {
|
|
|
|
var org *object_v3alpha.Organization
|
|
|
|
if orgID != "" {
|
|
|
|
org = &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}}
|
|
|
|
}
|
|
|
|
user, err := i.Client.UserV3Alpha.LockUser(ctx, &user_v3alpha.LockUserRequest{
|
|
|
|
Organization: org,
|
|
|
|
Id: userID,
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("lock user")
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) UnlockSchemaUser(ctx context.Context, orgID string, userID string) *user_v3alpha.UnlockUserResponse {
|
|
|
|
var org *object_v3alpha.Organization
|
|
|
|
if orgID != "" {
|
|
|
|
org = &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}}
|
|
|
|
}
|
|
|
|
user, err := i.Client.UserV3Alpha.UnlockUser(ctx, &user_v3alpha.UnlockUserRequest{
|
|
|
|
Organization: org,
|
|
|
|
Id: userID,
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("unlock user")
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) DeactivateSchemaUser(ctx context.Context, orgID string, userID string) *user_v3alpha.DeactivateUserResponse {
|
|
|
|
var org *object_v3alpha.Organization
|
|
|
|
if orgID != "" {
|
|
|
|
org = &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}}
|
|
|
|
}
|
|
|
|
user, err := i.Client.UserV3Alpha.DeactivateUser(ctx, &user_v3alpha.DeactivateUserRequest{
|
|
|
|
Organization: org,
|
|
|
|
Id: userID,
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("deactivate user")
|
|
|
|
return user
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Instance) ActivateSchemaUser(ctx context.Context, orgID string, userID string) *user_v3alpha.ActivateUserResponse {
|
|
|
|
var org *object_v3alpha.Organization
|
|
|
|
if orgID != "" {
|
|
|
|
org = &object_v3alpha.Organization{Property: &object_v3alpha.Organization_OrgId{OrgId: orgID}}
|
|
|
|
}
|
|
|
|
user, err := i.Client.UserV3Alpha.ActivateUser(ctx, &user_v3alpha.ActivateUserRequest{
|
|
|
|
Organization: org,
|
|
|
|
Id: userID,
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("reactivate user")
|
|
|
|
return user
|
|
|
|
}
|