2023-07-07 08:15:05 +00:00
|
|
|
//go:build integration
|
|
|
|
|
|
|
|
package management_test
|
|
|
|
|
|
|
|
import (
|
2023-08-04 16:17:16 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2023-07-07 08:15:05 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-08-04 16:17:16 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/text/language"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
|
2023-07-07 08:15:05 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration"
|
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/management"
|
2023-08-04 16:17:16 +00:00
|
|
|
"github.com/zitadel/zitadel/pkg/grpc/user"
|
2023-07-07 08:15:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestImport_and_Get reproduces https://github.com/zitadel/zitadel/issues/5808
|
|
|
|
// which led to consistency issues due the call timestamp not being
|
|
|
|
// updated after a bulk Trigger.
|
|
|
|
// This test Imports a user and directly tries to Get it, 100 times in a loop.
|
|
|
|
// When the bug still existed, some (between 1 to 7 out of 100)
|
|
|
|
// Get calls would return a Not Found error.
|
|
|
|
func TestImport_and_Get(t *testing.T) {
|
|
|
|
const N = 100
|
|
|
|
|
|
|
|
for i := 0; i < N; i++ {
|
|
|
|
firstName := strconv.Itoa(i)
|
|
|
|
t.Run(firstName, func(t *testing.T) {
|
|
|
|
// create unique names.
|
|
|
|
lastName := strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
|
userName := strings.Join([]string{firstName, lastName}, "_")
|
2023-12-05 11:12:01 +00:00
|
|
|
email := strings.Join([]string{userName, "example.com"}, "@")
|
2023-07-07 08:15:05 +00:00
|
|
|
|
2024-02-28 10:21:11 +00:00
|
|
|
res, err := Client.ImportHumanUser(OrgCTX, &management.ImportHumanUserRequest{
|
2023-07-07 08:15:05 +00:00
|
|
|
UserName: userName,
|
|
|
|
Profile: &management.ImportHumanUserRequest_Profile{
|
|
|
|
FirstName: firstName,
|
|
|
|
LastName: lastName,
|
2023-12-05 11:12:01 +00:00
|
|
|
PreferredLanguage: language.Japanese.String(),
|
2023-07-07 08:15:05 +00:00
|
|
|
Gender: user.Gender_GENDER_DIVERSE,
|
|
|
|
},
|
|
|
|
Email: &management.ImportHumanUserRequest_Email{
|
|
|
|
Email: email,
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-02-28 10:21:11 +00:00
|
|
|
_, err = Client.GetUserByID(OrgCTX, &management.GetUserByIDRequest{Id: res.GetUserId()})
|
2023-07-07 08:15:05 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
s, ok := status.FromError(err)
|
|
|
|
if ok && s != nil && s.Code() == codes.NotFound {
|
|
|
|
t.Errorf("iteration %d: user with id %q not found", i, res.GetUserId())
|
2023-07-07 08:15:05 +00:00
|
|
|
}
|
|
|
|
require.NoError(t, err) // catch and fail on any other error
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-12-05 11:12:01 +00:00
|
|
|
|
|
|
|
func TestImport_UnparsablePreferredLanguage(t *testing.T) {
|
|
|
|
random := integration.RandString(5)
|
2024-02-28 10:21:11 +00:00
|
|
|
_, err := Client.ImportHumanUser(OrgCTX, &management.ImportHumanUserRequest{
|
2023-12-05 11:12:01 +00:00
|
|
|
UserName: random,
|
|
|
|
Profile: &management.ImportHumanUserRequest_Profile{
|
|
|
|
FirstName: random,
|
|
|
|
LastName: random,
|
|
|
|
PreferredLanguage: "not valid",
|
|
|
|
Gender: user.Gender_GENDER_DIVERSE,
|
|
|
|
},
|
|
|
|
Email: &management.ImportHumanUserRequest_Email{
|
|
|
|
Email: random + "@example.com",
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|