mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-06 19:36:41 +00:00
feat: Integration tests for CreateInstance v2 endpoint (#9452)
This commit is contained in:
@@ -159,7 +159,7 @@ func CreateInstancePbToSetupInstance(req *instance.CreateInstanceRequest, defaul
|
|||||||
func createInstancePbToAddHuman(req *instance.CreateInstanceRequest_Human, defaultHuman command.AddHuman, userLoginMustBeDomain bool, org, externalDomain string) *command.AddHuman {
|
func createInstancePbToAddHuman(req *instance.CreateInstanceRequest_Human, defaultHuman command.AddHuman, userLoginMustBeDomain bool, org, externalDomain string) *command.AddHuman {
|
||||||
user := defaultHuman
|
user := defaultHuman
|
||||||
if req.Email != nil {
|
if req.Email != nil {
|
||||||
user.Email.Address = domain.EmailAddress(req.Email.Email)
|
user.Email.Address = domain.EmailAddress(strings.TrimSpace(req.Email.Email))
|
||||||
user.Email.Verified = req.Email.IsEmailVerified
|
user.Email.Verified = req.Email.IsEmailVerified
|
||||||
}
|
}
|
||||||
if req.Profile != nil {
|
if req.Profile != nil {
|
||||||
|
|||||||
103
internal/api/grpc/instance/v2/integration_test/instance_test.go
Normal file
103
internal/api/grpc/instance/v2/integration_test/instance_test.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
//go:build integration
|
||||||
|
|
||||||
|
package instance_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/zitadel/zitadel/internal/integration"
|
||||||
|
instance "github.com/zitadel/zitadel/pkg/grpc/instance/v2beta"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateInstance(t *testing.T) {
|
||||||
|
tt := []struct {
|
||||||
|
testName string
|
||||||
|
inputRequest *instance.CreateInstanceRequest
|
||||||
|
inputContext context.Context
|
||||||
|
expectedErrorMsg string
|
||||||
|
expectedErrorCode codes.Code
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testName: "when invalid context should return unauthN error",
|
||||||
|
inputRequest: &instance.CreateInstanceRequest{
|
||||||
|
InstanceName: " ",
|
||||||
|
FirstOrgName: " ",
|
||||||
|
CustomDomain: " ",
|
||||||
|
Owner: &instance.CreateInstanceRequest_Machine_{
|
||||||
|
Machine: &instance.CreateInstanceRequest_Machine{
|
||||||
|
UserName: "owner",
|
||||||
|
Name: "owner",
|
||||||
|
PersonalAccessToken: &instance.CreateInstanceRequest_PersonalAccessToken{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DefaultLanguage: "",
|
||||||
|
},
|
||||||
|
inputContext: context.Background(),
|
||||||
|
expectedErrorCode: codes.Unauthenticated,
|
||||||
|
expectedErrorMsg: "auth header missing",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "when invalid input should return no admin error",
|
||||||
|
inputRequest: &instance.CreateInstanceRequest{
|
||||||
|
InstanceName: " ",
|
||||||
|
FirstOrgName: " ",
|
||||||
|
CustomDomain: " ",
|
||||||
|
DefaultLanguage: "",
|
||||||
|
Owner: &instance.CreateInstanceRequest_Human_{
|
||||||
|
Human: &instance.CreateInstanceRequest_Human{
|
||||||
|
Email: &instance.CreateInstanceRequest_Email{
|
||||||
|
Email: " user@example.com ",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
inputContext: CTXWithSysAuthZ,
|
||||||
|
expectedErrorCode: codes.InvalidArgument,
|
||||||
|
expectedErrorMsg: "Given name in profile is empty (USER-UCej2)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "when input and context are valid should return expected response and no error",
|
||||||
|
inputRequest: &instance.CreateInstanceRequest{
|
||||||
|
InstanceName: " ",
|
||||||
|
FirstOrgName: " ",
|
||||||
|
CustomDomain: " ",
|
||||||
|
Owner: &instance.CreateInstanceRequest_Machine_{
|
||||||
|
Machine: &instance.CreateInstanceRequest_Machine{
|
||||||
|
UserName: "owner",
|
||||||
|
Name: "owner",
|
||||||
|
PersonalAccessToken: &instance.CreateInstanceRequest_PersonalAccessToken{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
DefaultLanguage: "",
|
||||||
|
},
|
||||||
|
inputContext: CTXWithSysAuthZ,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tt {
|
||||||
|
t.Run(tc.testName, func(t *testing.T) {
|
||||||
|
// Given
|
||||||
|
cli, err := integration.NewDefaultClient(CTXWithSysAuthZ)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
// Test
|
||||||
|
res, err := cli.InstanceV2Beta.CreateInstance(tc.inputContext, tc.inputRequest)
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
assert.Equal(t, tc.expectedErrorCode, status.Code(err))
|
||||||
|
assert.Equal(t, tc.expectedErrorMsg, status.Convert(err).Message())
|
||||||
|
if tc.expectedErrorMsg == "" {
|
||||||
|
require.NotEmpty(t, res.GetInstanceId())
|
||||||
|
assert.NotEmpty(t, res.GetPat())
|
||||||
|
|
||||||
|
require.NotNil(t, res.GetDetails())
|
||||||
|
assert.NotEmpty(t, res.GetDetails().GetResourceOwner())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package instance_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/zitadel/zitadel/internal/integration"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
CTXWithSysAuthZ context.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Exit(func() int {
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
CTXWithSysAuthZ = integration.WithSystemAuthorization(ctx)
|
||||||
|
|
||||||
|
return m.Run()
|
||||||
|
}())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user