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"
|
|
|
|
|
2023-09-29 09:26:14 +00:00
|
|
|
crewjam_saml "github.com/crewjam/saml"
|
2023-11-23 14:17:50 +00:00
|
|
|
"github.com/muhlemmer/gu"
|
2023-12-07 08:43:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
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"
|
2023-10-17 15:19:51 +00:00
|
|
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
2023-06-21 14:06:18 +00:00
|
|
|
"golang.org/x/oauth2"
|
2023-08-16 11:29:57 +00:00
|
|
|
"golang.org/x/text/language"
|
2023-06-07 15:28:42 +00:00
|
|
|
"google.golang.org/grpc"
|
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-06-21 14:06:18 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
2023-12-21 09:03:37 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-08-16 11:29:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/idp/providers/ldap"
|
2023-06-21 14:06:18 +00:00
|
|
|
openid "github.com/zitadel/zitadel/internal/idp/providers/oidc"
|
2023-09-29 09:26:14 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/idp/providers/saml"
|
2023-06-21 14:06:18 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/idp"
|
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"
|
2023-06-20 16:23:28 +00:00
|
|
|
mgmt "github.com/zitadel/zitadel/pkg/grpc/management"
|
2024-07-31 12:42:12 +00:00
|
|
|
object "github.com/zitadel/zitadel/pkg/grpc/object/v2"
|
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-07-31 12:42:12 +00:00
|
|
|
org "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"
|
|
|
|
session "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-07-31 12:42:12 +00:00
|
|
|
settings "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-07-06 06:38:13 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/system"
|
2023-12-21 09:03:37 +00:00
|
|
|
user_pb "github.com/zitadel/zitadel/pkg/grpc/user"
|
2024-03-12 13:50:13 +00:00
|
|
|
schema "github.com/zitadel/zitadel/pkg/grpc/user/schema/v3alpha"
|
2024-07-26 20:39:55 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
|
|
|
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
|
|
|
|
UserV2 user.UserServiceClient
|
|
|
|
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-07-26 20:39:55 +00:00
|
|
|
System system.SystemServiceClient
|
2024-07-31 12:42:12 +00:00
|
|
|
ActionV3 action.ZITADELActionsClient
|
2024-07-26 20:39:55 +00:00
|
|
|
FeatureV2beta feature_v2beta.FeatureServiceClient
|
|
|
|
FeatureV2 feature.FeatureServiceClient
|
|
|
|
UserSchemaV3 schema.UserSchemaServiceClient
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newClient(cc *grpc.ClientConn) Client {
|
|
|
|
return 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),
|
|
|
|
UserV2: user.NewUserServiceClient(cc),
|
|
|
|
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-07-26 20:39:55 +00:00
|
|
|
System: system.NewSystemServiceClient(cc),
|
2024-07-31 12:42:12 +00:00
|
|
|
ActionV3: action.NewZITADELActionsClient(cc),
|
2024-07-26 20:39:55 +00:00
|
|
|
FeatureV2beta: feature_v2beta.NewFeatureServiceClient(cc),
|
|
|
|
FeatureV2: feature.NewFeatureServiceClient(cc),
|
|
|
|
UserSchemaV3: schema.NewUserSchemaServiceClient(cc),
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-12 04:49:14 +00:00
|
|
|
func (t *Tester) UseIsolatedInstance(tt *testing.T, iamOwnerCtx, systemCtx context.Context) (primaryDomain, instanceId, adminID string, authenticatedIamOwnerCtx context.Context) {
|
2023-12-05 11:12:01 +00:00
|
|
|
primaryDomain = RandString(5) + ".integration.localhost"
|
2023-07-06 06:38:13 +00:00
|
|
|
instance, err := t.Client.System.CreateInstance(systemCtx, &system.CreateInstanceRequest{
|
|
|
|
InstanceName: "testinstance",
|
|
|
|
CustomDomain: primaryDomain,
|
|
|
|
Owner: &system.CreateInstanceRequest_Machine_{
|
|
|
|
Machine: &system.CreateInstanceRequest_Machine{
|
|
|
|
UserName: "owner",
|
|
|
|
Name: "owner",
|
|
|
|
PersonalAccessToken: &system.CreateInstanceRequest_PersonalAccessToken{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2024-06-12 04:49:14 +00:00
|
|
|
require.NoError(tt, err)
|
2023-11-22 09:29:38 +00:00
|
|
|
t.createClientConn(iamOwnerCtx, fmt.Sprintf("%s:%d", primaryDomain, t.Config.Port))
|
2023-07-06 06:38:13 +00:00
|
|
|
instanceId = instance.GetInstanceId()
|
2024-06-12 04:49:14 +00:00
|
|
|
owner, err := t.Queries.GetUserByLoginName(authz.WithInstanceID(iamOwnerCtx, instanceId), true, "owner@"+primaryDomain)
|
|
|
|
require.NoError(tt, err)
|
2023-07-10 13:27:00 +00:00
|
|
|
t.Users.Set(instanceId, IAMOwner, &User{
|
2024-06-12 04:49:14 +00:00
|
|
|
User: owner,
|
2023-07-10 13:27:00 +00:00
|
|
|
Token: instance.GetPat(),
|
|
|
|
})
|
2023-12-07 08:43:23 +00:00
|
|
|
newCtx := t.WithInstanceAuthorization(iamOwnerCtx, IAMOwner, instanceId)
|
2024-06-12 04:49:14 +00:00
|
|
|
var adminUser *mgmt.ImportHumanUserResponse
|
2023-12-07 08:43:23 +00:00
|
|
|
// the following serves two purposes:
|
|
|
|
// 1. it ensures that the instance is ready to be used
|
|
|
|
// 2. it enables a normal login with the default admin user credentials
|
|
|
|
require.EventuallyWithT(tt, func(collectT *assert.CollectT) {
|
2024-06-12 04:49:14 +00:00
|
|
|
var importErr error
|
|
|
|
adminUser, importErr = t.Client.Mgmt.ImportHumanUser(newCtx, &mgmt.ImportHumanUserRequest{
|
2023-12-07 08:43:23 +00:00
|
|
|
UserName: "zitadel-admin@zitadel.localhost",
|
|
|
|
Email: &mgmt.ImportHumanUserRequest_Email{
|
|
|
|
Email: "zitadel-admin@zitadel.localhost",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
Password: "Password1!",
|
|
|
|
Profile: &mgmt.ImportHumanUserRequest_Profile{
|
|
|
|
FirstName: "hodor",
|
|
|
|
LastName: "hodor",
|
|
|
|
NickName: "hodor",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(collectT, importErr)
|
|
|
|
}, 2*time.Minute, 100*time.Millisecond, "instance not ready")
|
2024-06-12 04:49:14 +00:00
|
|
|
return primaryDomain, instanceId, adminUser.GetUserId(), newCtx
|
2023-07-06 06:38:13 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 15:28:42 +00:00
|
|
|
func (s *Tester) CreateHumanUser(ctx context.Context) *user.AddHumanUserResponse {
|
|
|
|
resp, err := s.Client.UserV2.AddHumanUser(ctx, &user.AddHumanUserRequest{
|
2023-12-05 11:12:01 +00:00
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
2023-06-07 15:28:42 +00:00
|
|
|
OrgId: s.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
2023-11-23 14:17:50 +00:00
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: gu.Ptr(user.Gender_GENDER_MALE),
|
2023-06-07 15:28:42 +00:00
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
|
|
|
Verification: &user.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnEmailVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
2023-08-03 04:42:59 +00:00
|
|
|
Phone: &user.SetHumanPhone{
|
|
|
|
Phone: "+41791234567",
|
|
|
|
Verification: &user.SetHumanPhone_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnPhoneVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
2023-06-07 15:28:42 +00:00
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create human user")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-07-24 13:46:07 +00:00
|
|
|
func (s *Tester) CreateHumanUserNoPhone(ctx context.Context) *user.AddHumanUserResponse {
|
|
|
|
resp, err := s.Client.UserV2.AddHumanUser(ctx, &user.AddHumanUserRequest{
|
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
|
|
|
OrgId: s.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: gu.Ptr(user.Gender_GENDER_MALE),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
|
|
|
Verification: &user.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnEmailVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create human user")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-05-14 07:20:31 +00:00
|
|
|
func (s *Tester) CreateHumanUserWithTOTP(ctx context.Context, secret string) *user.AddHumanUserResponse {
|
|
|
|
resp, err := s.Client.UserV2.AddHumanUser(ctx, &user.AddHumanUserRequest{
|
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
|
|
|
OrgId: s.Organisation.ID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: gu.Ptr(user.Gender_GENDER_MALE),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
|
|
|
Verification: &user.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnEmailVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Phone: &user.SetHumanPhone{
|
|
|
|
Phone: "+41791234567",
|
|
|
|
Verification: &user.SetHumanPhone_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnPhoneVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TotpSecret: gu.Ptr(secret),
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create human user")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-01-17 09:00:10 +00:00
|
|
|
func (s *Tester) CreateOrganization(ctx context.Context, name, adminEmail string) *org.AddOrganizationResponse {
|
|
|
|
resp, err := s.Client.OrgV2.AddOrganization(ctx, &org.AddOrganizationRequest{
|
|
|
|
Name: name,
|
|
|
|
Admins: []*org.AddOrganizationRequest_Admin{
|
|
|
|
{
|
|
|
|
UserType: &org.AddOrganizationRequest_Admin_Human{
|
|
|
|
Human: &user.AddHumanUserRequest{
|
|
|
|
Profile: &user.SetHumanProfile{
|
|
|
|
GivenName: "firstname",
|
|
|
|
FamilyName: "lastname",
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: adminEmail,
|
|
|
|
Verification: &user.SetHumanEmail_ReturnCode{
|
|
|
|
ReturnCode: &user.ReturnEmailVerificationCode{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create org")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Tester) CreateHumanUserVerified(ctx context.Context, org, email string) *user.AddHumanUserResponse {
|
|
|
|
resp, err := s.Client.UserV2.AddHumanUser(ctx, &user.AddHumanUserRequest{
|
|
|
|
Organization: &object.Organization{
|
|
|
|
Org: &object.Organization_OrgId{
|
|
|
|
OrgId: org,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Profile: &user.SetHumanProfile{
|
|
|
|
GivenName: "Mickey",
|
|
|
|
FamilyName: "Mouse",
|
|
|
|
NickName: gu.Ptr("Mickey"),
|
|
|
|
PreferredLanguage: gu.Ptr("nl"),
|
|
|
|
Gender: gu.Ptr(user.Gender_GENDER_MALE),
|
|
|
|
},
|
|
|
|
Email: &user.SetHumanEmail{
|
|
|
|
Email: email,
|
|
|
|
Verification: &user.SetHumanEmail_IsVerified{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Phone: &user.SetHumanPhone{
|
|
|
|
Phone: "+41791234567",
|
|
|
|
Verification: &user.SetHumanPhone_IsVerified{
|
|
|
|
IsVerified: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create human user")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2023-12-21 09:03:37 +00:00
|
|
|
func (s *Tester) CreateMachineUser(ctx context.Context) *mgmt.AddMachineUserResponse {
|
|
|
|
resp, err := s.Client.Mgmt.AddMachineUser(ctx, &mgmt.AddMachineUserRequest{
|
|
|
|
UserName: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
|
|
|
Name: "Mickey",
|
|
|
|
Description: "Mickey Mouse",
|
|
|
|
AccessTokenType: user_pb.AccessTokenType_ACCESS_TOKEN_TYPE_BEARER,
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create human user")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2023-06-21 14:06:18 +00:00
|
|
|
func (s *Tester) CreateUserIDPlink(ctx context.Context, userID, externalID, idpID, username string) *user.AddIDPLinkResponse {
|
|
|
|
resp, err := s.Client.UserV2.AddIDPLink(
|
|
|
|
ctx,
|
|
|
|
&user.AddIDPLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
IdpLink: &user.IDPLink{
|
|
|
|
IdpId: idpID,
|
|
|
|
UserId: externalID,
|
|
|
|
UserName: username,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
logging.OnError(err).Fatal("create human user link")
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:28:42 +00:00
|
|
|
func (s *Tester) RegisterUserPasskey(ctx context.Context, userID string) {
|
|
|
|
reg, err := s.Client.UserV2.CreatePasskeyRegistrationLink(ctx, &user.CreatePasskeyRegistrationLinkRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Medium: &user.CreatePasskeyRegistrationLinkRequest_ReturnCode{},
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user passkey")
|
|
|
|
|
|
|
|
pkr, err := s.Client.UserV2.RegisterPasskey(ctx, &user.RegisterPasskeyRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Code: reg.GetCode(),
|
2023-06-27 12:36:07 +00:00
|
|
|
Domain: s.Config.ExternalDomain,
|
2023-06-07 15:28:42 +00:00
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user passkey")
|
|
|
|
attestationResponse, err := s.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions())
|
|
|
|
logging.OnError(err).Fatal("create user passkey")
|
|
|
|
|
|
|
|
_, err = s.Client.UserV2.VerifyPasskeyRegistration(ctx, &user.VerifyPasskeyRegistrationRequest{
|
|
|
|
UserId: userID,
|
|
|
|
PasskeyId: pkr.GetPasskeyId(),
|
|
|
|
PublicKeyCredential: attestationResponse,
|
|
|
|
PasskeyName: "nice name",
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user passkey")
|
|
|
|
}
|
2023-06-21 14:06:18 +00:00
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
func (s *Tester) RegisterUserU2F(ctx context.Context, userID string) {
|
|
|
|
pkr, err := s.Client.UserV2.RegisterU2F(ctx, &user.RegisterU2FRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Domain: s.Config.ExternalDomain,
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user u2f")
|
|
|
|
attestationResponse, err := s.WebAuthN.CreateAttestationResponse(pkr.GetPublicKeyCredentialCreationOptions())
|
|
|
|
logging.OnError(err).Fatal("create user u2f")
|
|
|
|
|
|
|
|
_, err = s.Client.UserV2.VerifyU2FRegistration(ctx, &user.VerifyU2FRegistrationRequest{
|
|
|
|
UserId: userID,
|
|
|
|
U2FId: pkr.GetU2FId(),
|
|
|
|
PublicKeyCredential: attestationResponse,
|
|
|
|
TokenName: "nice name",
|
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("create user u2f")
|
|
|
|
}
|
|
|
|
|
2024-07-10 15:49:35 +00:00
|
|
|
func (s *Tester) SetUserPassword(ctx context.Context, userID, password string, changeRequired bool) *object.Details {
|
2024-06-18 11:27:44 +00:00
|
|
|
resp, err := s.Client.UserV2.SetPassword(ctx, &user.SetPasswordRequest{
|
2024-03-28 06:21:21 +00:00
|
|
|
UserId: userID,
|
|
|
|
NewPassword: &user.Password{
|
|
|
|
Password: password,
|
|
|
|
ChangeRequired: changeRequired,
|
|
|
|
},
|
2023-07-14 11:16:16 +00:00
|
|
|
})
|
|
|
|
logging.OnError(err).Fatal("set user password")
|
2024-07-10 15:49:35 +00:00
|
|
|
return resp.GetDetails()
|
2023-07-14 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) AddGenericOAuthProvider(t *testing.T, ctx context.Context) string {
|
|
|
|
ctx = authz.WithInstance(ctx, s.Instance)
|
2023-08-11 14:19:14 +00:00
|
|
|
id, _, err := s.Commands.AddInstanceGenericOAuthProvider(ctx, command.GenericOAuthProvider{
|
2023-06-21 14:06:18 +00:00
|
|
|
Name: "idp",
|
|
|
|
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",
|
|
|
|
IDPOptions: idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2024-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) AddOrgGenericOAuthProvider(t *testing.T, ctx context.Context, orgID string) string {
|
|
|
|
ctx = authz.WithInstance(ctx, s.Instance)
|
|
|
|
id, _, err := s.Commands.AddOrgGenericOAuthProvider(ctx, orgID,
|
|
|
|
command.GenericOAuthProvider{
|
|
|
|
Name: "idp",
|
|
|
|
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",
|
|
|
|
IDPOptions: idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Tester) AddSAMLProvider(t *testing.T, ctx context.Context) string {
|
|
|
|
ctx = authz.WithInstance(ctx, s.Instance)
|
2023-09-29 09:26:14 +00:00
|
|
|
id, _, err := s.Server.Commands.AddInstanceSAMLProvider(ctx, command.SAMLProvider{
|
|
|
|
Name: "saml-idp",
|
|
|
|
Metadata: []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>"),
|
|
|
|
IDPOptions: idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2024-05-23 05:04:07 +00:00
|
|
|
func (s *Tester) AddSAMLRedirectProvider(t *testing.T, ctx context.Context, transientMappingAttributeName string) string {
|
2024-05-07 06:11:20 +00:00
|
|
|
ctx = authz.WithInstance(ctx, s.Instance)
|
2023-09-29 09:26:14 +00:00
|
|
|
id, _, err := s.Server.Commands.AddInstanceSAMLProvider(ctx, command.SAMLProvider{
|
2024-05-23 05:04:07 +00:00
|
|
|
Name: "saml-idp-redirect",
|
|
|
|
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
|
|
|
|
Metadata: []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,
|
2023-09-29 09:26:14 +00:00
|
|
|
IDPOptions: idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2024-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) AddSAMLPostProvider(t *testing.T, ctx context.Context) string {
|
|
|
|
ctx = authz.WithInstance(ctx, s.Instance)
|
2023-09-29 09:26:14 +00:00
|
|
|
id, _, err := s.Server.Commands.AddInstanceSAMLProvider(ctx, command.SAMLProvider{
|
|
|
|
Name: "saml-idp-post",
|
2024-02-19 06:50:37 +00:00
|
|
|
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
|
2023-09-29 09:26:14 +00:00
|
|
|
Metadata: []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>"),
|
|
|
|
IDPOptions: idp.Options{
|
|
|
|
IsLinkingAllowed: true,
|
|
|
|
IsCreationAllowed: true,
|
|
|
|
IsAutoCreation: true,
|
|
|
|
IsAutoUpdate: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2024-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) CreateIntent(t *testing.T, ctx context.Context, idpID string) string {
|
|
|
|
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-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) CreateSuccessfulOAuthIntent(t *testing.T, ctx context.Context, idpID, userID, idpUserID string) (string, string, time.Time, uint64) {
|
|
|
|
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-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) CreateSuccessfulLDAPIntent(t *testing.T, ctx context.Context, idpID, userID, idpUserID string) (string, string, time.Time, uint64) {
|
|
|
|
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-05-07 06:11:20 +00:00
|
|
|
func (s *Tester) CreateSuccessfulSAMLIntent(t *testing.T, ctx context.Context, idpID, userID, idpUserID string) (string, string, time.Time, uint64) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-11-06 09:48:28 +00:00
|
|
|
func (s *Tester) CreateVerifiedWebAuthNSession(t *testing.T, ctx context.Context, userID string) (id, token string, start, change time.Time) {
|
|
|
|
return s.CreateVerifiedWebAuthNSessionWithLifetime(t, ctx, userID, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Tester) CreateVerifiedWebAuthNSessionWithLifetime(t *testing.T, ctx context.Context, userID string, lifetime time.Duration) (id, token string, start, change time.Time) {
|
|
|
|
var sessionLifetime *durationpb.Duration
|
|
|
|
if lifetime > 0 {
|
|
|
|
sessionLifetime = durationpb.New(lifetime)
|
|
|
|
}
|
2023-07-10 13:27:00 +00:00
|
|
|
createResp, err := s.Client.SessionV2.CreateSession(ctx, &session.CreateSessionRequest{
|
|
|
|
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{
|
|
|
|
Domain: s.Config.ExternalDomain,
|
|
|
|
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)
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
assertion, err := s.WebAuthN.CreateAssertionResponse(createResp.GetChallenges().GetWebAuthN().GetPublicKeyCredentialRequestOptions(), true)
|
2023-07-10 13:27:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
updateResp, err := s.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
|
|
|
|
|
|
|
func (s *Tester) CreatePasswordSession(t *testing.T, ctx context.Context, userID, password string) (id, token string, start, change time.Time) {
|
|
|
|
createResp, err := s.Client.SessionV2.CreateSession(ctx, &session.CreateSessionRequest{
|
|
|
|
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
|
|
|
|
|
|
|
func (s *Tester) CreateProjectUserGrant(t *testing.T, ctx context.Context, projectID, userID string) string {
|
|
|
|
resp, err := s.Client.Mgmt.AddUserGrant(ctx, &mgmt.AddUserGrantRequest{
|
|
|
|
UserId: userID,
|
|
|
|
ProjectId: projectID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return resp.GetUserGrantId()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Tester) CreateOrgMembership(t *testing.T, ctx context.Context, userID string) {
|
|
|
|
_, err := s.Client.Mgmt.AddOrgMember(ctx, &mgmt.AddOrgMemberRequest{
|
|
|
|
UserId: userID,
|
|
|
|
Roles: []string{domain.RoleOrgOwner},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Tester) CreateProjectMembership(t *testing.T, ctx context.Context, projectID, userID string) {
|
|
|
|
_, err := s.Client.Mgmt.AddProjectMember(ctx, &mgmt.AddProjectMemberRequest{
|
|
|
|
ProjectId: projectID,
|
|
|
|
UserId: userID,
|
|
|
|
Roles: []string{domain.RoleProjectOwner},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2024-02-15 05:39:10 +00:00
|
|
|
|
2024-05-04 09:55:57 +00:00
|
|
|
func (s *Tester) CreateTarget(ctx context.Context, t *testing.T, name, endpoint string, ty domain.TargetType, interrupt bool) *action.CreateTargetResponse {
|
|
|
|
nameSet := fmt.Sprint(time.Now().UnixNano() + 1)
|
|
|
|
if name != "" {
|
|
|
|
nameSet = name
|
2024-03-14 09:56:23 +00:00
|
|
|
}
|
2024-07-31 12:42:12 +00:00
|
|
|
reqTarget := &action.Target{
|
2024-05-04 09:55:57 +00:00
|
|
|
Name: nameSet,
|
|
|
|
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-07-31 12:42:12 +00:00
|
|
|
target, err := s.Client.ActionV3.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-07-31 12:42:12 +00:00
|
|
|
func (s *Tester) DeleteExecution(ctx context.Context, t *testing.T, cond *action.Condition) {
|
|
|
|
_, err := s.Client.ActionV3.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-07-31 12:42:12 +00:00
|
|
|
func (s *Tester) SetExecution(ctx context.Context, t *testing.T, cond *action.Condition, targets []*action.ExecutionTargetType) *action.SetExecutionResponse {
|
|
|
|
target, err := s.Client.ActionV3.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-03-12 13:50:13 +00:00
|
|
|
func (s *Tester) CreateUserSchema(ctx context.Context, t *testing.T) *schema.CreateUserSchemaResponse {
|
2024-03-22 13:26:13 +00:00
|
|
|
return s.CreateUserSchemaWithType(ctx, t, fmt.Sprint(time.Now().UnixNano()+1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Tester) CreateUserSchemaWithType(ctx context.Context, t *testing.T, schemaType string) *schema.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": {}
|
|
|
|
}`))
|
|
|
|
require.NoError(t, err)
|
|
|
|
target, err := s.Client.UserSchemaV3.CreateUserSchema(ctx, &schema.CreateUserSchemaRequest{
|
2024-03-22 13:26:13 +00:00
|
|
|
Type: schemaType,
|
2024-03-12 13:50:13 +00:00
|
|
|
DataType: &schema.CreateUserSchemaRequest_Schema{
|
|
|
|
Schema: userSchema,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
return target
|
|
|
|
}
|