(t *testing.T)
| 351 | } |
| 352 | |
| 353 | func TestUpdateUserEmail(t *testing.T) { |
| 354 | a := require.New(t) |
| 355 | ctx := context.Background() |
| 356 | ctl := &controller{} |
| 357 | ctx, err := ctl.StartServerWithExternalPg(ctx) |
| 358 | a.NoError(err) |
| 359 | defer ctl.Close(ctx) |
| 360 | |
| 361 | // 1. Create a user |
| 362 | originalEmail := "original@bytebase.com" |
| 363 | newEmail := "updated@bytebase.com" |
| 364 | userResp, err := ctl.userServiceClient.CreateUser(ctx, connect.NewRequest(&v1pb.CreateUserRequest{ |
| 365 | User: &v1pb.User{ |
| 366 | Title: "temp-user", |
| 367 | Email: originalEmail, |
| 368 | Password: "1024bytebase", |
| 369 | }, |
| 370 | })) |
| 371 | a.NoError(err) |
| 372 | user := userResp.Msg |
| 373 | |
| 374 | // Add the created user to workspace IAM as member so they can login. |
| 375 | _, err = ctl.addMemberToWorkspaceIAM(ctx, user.Workspace, fmt.Sprintf("user:%v", user.Email), "roles/workspaceMember") |
| 376 | a.NoError(err) |
| 377 | |
| 378 | // 1.5 Grant user permission to create issues in the project |
| 379 | projectID := "test-project" |
| 380 | // Login as admin (StartServer returns admin token but let's be explicit or reuse ctl state if it hasn't changed) |
| 381 | // Actually StartServer sets ctl.authInterceptor.token to admin token. |
| 382 | // So we are currently admin. |
| 383 | |
| 384 | policyResp, err := ctl.projectServiceClient.GetIamPolicy(ctx, connect.NewRequest(&v1pb.GetIamPolicyRequest{ |
| 385 | Resource: "projects/" + projectID, |
| 386 | })) |
| 387 | a.NoError(err) |
| 388 | policy := policyResp.Msg |
| 389 | |
| 390 | policy.Bindings = append(policy.Bindings, &v1pb.Binding{ |
| 391 | Role: "roles/projectDeveloper", |
| 392 | Members: []string{fmt.Sprintf("user:%s", originalEmail)}, |
| 393 | }) |
| 394 | |
| 395 | _, err = ctl.projectServiceClient.SetIamPolicy(ctx, connect.NewRequest(&v1pb.SetIamPolicyRequest{ |
| 396 | Resource: "projects/" + projectID, |
| 397 | Policy: policy, |
| 398 | })) |
| 399 | a.NoError(err) |
| 400 | |
| 401 | // 1.6 Create a group and add the user to it |
| 402 | groupEmail := "test-group@bytebase.com" |
| 403 | groupResp, err := ctl.groupServiceClient.CreateGroup(ctx, connect.NewRequest(&v1pb.CreateGroupRequest{ |
| 404 | Group: &v1pb.Group{ |
| 405 | Title: "Test Group", |
| 406 | }, |
| 407 | GroupEmail: groupEmail, |
| 408 | })) |
| 409 | a.NoError(err) |
| 410 | group := groupResp.Msg |
nothing calls this directly
no test coverage detected