mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-04 23:45:07 +00:00
feat: allow machine user id to be set during creation (#8265)
# Which Problems Are Solved Solves the problem described in #8264. # How the Problems Are Solved Added a UserID field which can be set during Machine User creation. # Additional Changes Added addition unit and integration tests to cover the cases where a UserID field is present. # Additional Context - Closes #8264 Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
parent
832a55a78e
commit
7d0c7e5b54
@ -133,8 +133,14 @@ func ImportHumanUserRequestToDomain(req *mgmt_pb.ImportHumanUserRequest) (human
|
||||
}
|
||||
|
||||
func AddMachineUserRequestToCommand(req *mgmt_pb.AddMachineUserRequest, resourceowner string) *command.Machine {
|
||||
userId := ""
|
||||
if req.UserId != nil {
|
||||
userId = *req.UserId
|
||||
}
|
||||
|
||||
return &command.Machine{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: userId,
|
||||
ResourceOwner: resourceowner,
|
||||
},
|
||||
Username: req.UserName,
|
||||
|
@ -78,3 +78,36 @@ func TestImport_UnparsablePreferredLanguage(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAdd_MachineUser(t *testing.T) {
|
||||
random := integration.RandString(5)
|
||||
res, err := Client.AddMachineUser(OrgCTX, &management.AddMachineUserRequest{
|
||||
UserName: random,
|
||||
Name: "testMachineName1",
|
||||
Description: "testMachineDescription1",
|
||||
AccessTokenType: 0,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = Client.GetUserByID(OrgCTX, &management.GetUserByIDRequest{Id: res.GetUserId()})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAdd_MachineUserCustomID(t *testing.T) {
|
||||
id := integration.RandString(5)
|
||||
random := integration.RandString(5)
|
||||
|
||||
res, err := Client.AddMachineUser(OrgCTX, &management.AddMachineUserRequest{
|
||||
UserId: &id,
|
||||
UserName: random,
|
||||
Name: "testMachineName1",
|
||||
Description: "testMachineDescription1",
|
||||
AccessTokenType: 0,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = Client.GetUserByID(OrgCTX, &management.GetUserByIDRequest{Id: id})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, id, res.GetUserId())
|
||||
}
|
||||
|
@ -148,6 +148,52 @@ func TestCommandSide_AddMachine(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "add machine - custom id, ok",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(),
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewDomainPolicyAddedEvent(context.Background(),
|
||||
&user.NewAggregate("optionalID1", "org1").Aggregate,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
expectPush(
|
||||
user.NewMachineAddedEvent(context.Background(),
|
||||
&user.NewAggregate("optionalID1", "org1").Aggregate,
|
||||
"username",
|
||||
"name",
|
||||
"description",
|
||||
true,
|
||||
domain.OIDCTokenTypeBearer,
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
machine: &Machine{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
AggregateID: "optionalID1",
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
Description: "description",
|
||||
Name: "name",
|
||||
Username: "username",
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
ResourceOwner: "org1",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -8182,6 +8182,15 @@ message AddMachineUserRequest {
|
||||
zitadel.user.v1.AccessTokenType access_token_type = 4 [
|
||||
(validate.rules).enum = {defined_only: true}
|
||||
];
|
||||
|
||||
// optionally set your own id unique for the user.
|
||||
optional string user_id = 5 [
|
||||
(validate.rules).string = {min_len: 1, max_len: 200},
|
||||
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
|
||||
max_length: 200;
|
||||
example: "\"316b7fa5-0535-4adb-9e93-963a91b1010c\"";
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
message AddMachineUserResponse {
|
||||
|
Loading…
Reference in New Issue
Block a user