mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-22 07:24:26 +00:00
# Which Problems Are Solved As part of going to a relation storage model, we need to implement the repository for handling sessions and their events. # How the Problems Are Solved - Adds a migration step to create the necessary tables and types in the database. - Adds the repository implementation for sessions. - Implements a projection handler for session events to handle the events written by the old command handlers. - Updates the `Session` type and `SessionRepository` interface: - added `CreatorID` - Adjusted `Delete` method to return amount of affected columns - Removed sub-repository clumns from the main interface - Added `CreatorIDCondition`, `ExpirationCondition`, `ExistsFactor` and `ExistsMetadata` - Removed `SetUserAgent` - Methods of `SessionFactor` and `SessionChallenge` have been made public - fixed enumer on `SessionFactorType` - Adds a `JSON` type to the repository package to easy can JSON columns, resp. jsonb object inside a property of a `JSONArray` object. - Adds a `NoChange` interface, which can be implemented to signal that a `Change` interface implementation is not writing any changes to the statement builder, e.g. `CTEChange` # Additional Changes - Fixes the operators enums. `TextOperations` had wrong comments and `NumberOperations` additionally also had from comparisons. - Fixes downgrade of migration step 008. # Additional Context - closes https://github.com/zitadel/zitadel/issues/10212
115 lines
3.3 KiB
Go
115 lines
3.3 KiB
Go
//go:build integration
|
|
|
|
package events_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
|
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres"
|
|
"github.com/zitadel/zitadel/internal/integration"
|
|
"github.com/zitadel/zitadel/pkg/grpc/admin"
|
|
"github.com/zitadel/zitadel/pkg/grpc/authorization/v2"
|
|
v2beta "github.com/zitadel/zitadel/pkg/grpc/instance/v2beta"
|
|
mgmt "github.com/zitadel/zitadel/pkg/grpc/management"
|
|
v2beta_org "github.com/zitadel/zitadel/pkg/grpc/org/v2beta"
|
|
v2beta_project "github.com/zitadel/zitadel/pkg/grpc/project/v2beta"
|
|
"github.com/zitadel/zitadel/pkg/grpc/session/v2"
|
|
"github.com/zitadel/zitadel/pkg/grpc/system"
|
|
"github.com/zitadel/zitadel/pkg/grpc/user/v2"
|
|
)
|
|
|
|
func getEnv(key, fallback string) string {
|
|
if value, exists := os.LookupEnv(key); exists {
|
|
return value
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
var ConnString = fmt.Sprintf(
|
|
"host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
|
|
getEnv("ZITADEL_DATABASE_POSTGRES_HOST", "localhost"),
|
|
getEnv("ZITADEL_DATABASE_POSTGRES_PORT", "5433"),
|
|
getEnv("ZITADEL_DATABASE_POSTGRES_USER", "zitadel"),
|
|
getEnv("ZITADEL_DATABASE_POSTGRES_PASSWORD", "zitadel"),
|
|
getEnv("ZITADEL_DATABASE_POSTGRES_DATABASE", "zitadel"),
|
|
getEnv("ZITADEL_DATABASE_POSTGRES_SSL_MODE", "disable"),
|
|
)
|
|
|
|
var (
|
|
dbPool *pgxpool.Pool
|
|
CTX context.Context
|
|
IAMCTX context.Context
|
|
Instance *integration.Instance
|
|
SystemClient system.SystemServiceClient
|
|
OrgClient v2beta_org.OrganizationServiceClient
|
|
ProjectClient v2beta_project.ProjectServiceClient
|
|
SessionClient session.SessionServiceClient
|
|
UserClient user.UserServiceClient
|
|
AdminClient admin.AdminServiceClient
|
|
MgmtClient mgmt.ManagementServiceClient
|
|
AuthorizationClient authorization.AuthorizationServiceClient
|
|
)
|
|
|
|
var pool database.Pool
|
|
|
|
func TestMain(m *testing.M) {
|
|
os.Exit(func() int {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
|
defer cancel()
|
|
|
|
CTX = integration.WithSystemAuthorization(ctx)
|
|
Instance = integration.NewInstance(CTX)
|
|
|
|
IAMCTX = Instance.WithAuthorization(ctx, integration.UserTypeIAMOwner)
|
|
SystemClient = integration.SystemClient()
|
|
OrgClient = Instance.Client.OrgV2beta
|
|
ProjectClient = Instance.Client.Projectv2Beta
|
|
SessionClient = Instance.Client.SessionV2
|
|
UserClient = Instance.Client.UserV2
|
|
AdminClient = Instance.Client.Admin
|
|
MgmtClient = Instance.Client.Mgmt
|
|
AuthorizationClient = Instance.Client.AuthorizationV2
|
|
|
|
defer func() {
|
|
_, err := Instance.Client.InstanceV2Beta.DeleteInstance(CTX, &v2beta.DeleteInstanceRequest{
|
|
InstanceId: Instance.Instance.Id,
|
|
})
|
|
if err != nil {
|
|
log.Printf("Failed to delete instance on cleanup: %v\n", err)
|
|
}
|
|
}()
|
|
|
|
var err error
|
|
dbConfig, err := pgxpool.ParseConfig(ConnString)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
dbConfig.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
|
|
orgState, err := conn.LoadType(ctx, "zitadel.organization_state")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
conn.TypeMap().RegisterType(orgState)
|
|
return nil
|
|
}
|
|
|
|
dbPool, err = pgxpool.NewWithConfig(context.Background(), dbConfig)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
pool = postgres.PGxPool(dbPool)
|
|
|
|
return m.Run()
|
|
}())
|
|
}
|