fix: check whether org exists before creating user (#11647)

# Which Problems Are Solved

It was possible to create a user with an imaginary org.

# How the Problems Are Solved

Check whether org exists before creating the user.

# Additional Changes


# Additional Context

- Closes #11532
This commit is contained in:
Wim Van Laer
2026-03-16 13:12:21 +01:00
committed by GitHub
parent 9a4530bf77
commit 965e3fa621
5 changed files with 352 additions and 42 deletions
@@ -3452,6 +3452,34 @@ func TestServer_CreateUser(t *testing.T) {
}
},
},
{
name: "org does not exist human, using IAM owner, error",
testCase: func(runId string) testCase {
username := fmt.Sprintf("donald.duck+%s", runId)
email := username + "@example.com"
return testCase{
args: args{
IamCTX,
&user.CreateUserRequest{
OrganizationId: "does not exist",
Username: &username,
UserType: &user.CreateUserRequest_Human_{
Human: &user.CreateUserRequest_Human{
Profile: &user.SetHumanProfile{
GivenName: "Donald",
FamilyName: "Duck",
},
Email: &user.SetHumanEmail{
Email: email,
},
},
},
},
},
wantErr: true,
}
},
},
{
name: "org does not exist machine, error",
testCase: func(runId string) testCase {
@@ -3473,6 +3501,27 @@ func TestServer_CreateUser(t *testing.T) {
}
},
},
{
name: "org does not exist machine, using IAM owner, error",
testCase: func(runId string) testCase {
username := fmt.Sprintf("donald.duck+%s", runId)
return testCase{
args: args{
IamCTX,
&user.CreateUserRequest{
OrganizationId: "does not exist",
Username: &username,
UserType: &user.CreateUserRequest_Machine_{
Machine: &user.CreateUserRequest_Machine{
Name: integration.Username(),
},
},
},
},
wantErr: true,
}
},
},
}
for i, tt := range tests {
t.Run(tt.name, func(t *testing.T) {