Skip to content

Commit cbb3b7b

Browse files
authored
testserver: use proper test user if IsServicePrincipal is enabled (#3751)
## Why Testserver support both regular user and service principal, we need to use SP consistently. Found out when working on permissions that terraform pull incorrect user from a job.
1 parent 5ce4156 commit cbb3b7b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

libs/testserver/experiments.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,26 @@ func (s *FakeWorkspace) ExperimentCreate(req Request) Response {
2020
}
2121
}
2222

23+
testUser := s.CurrentUser()
24+
2325
// Server appends these tags automatically to experiments.
2426
// We replicate that behaviour in the test server as well.
2527
appendTags := []ml.ExperimentTag{
2628
{
2729
Key: "mlflow.ownerId",
28-
Value: TestUser.Id,
30+
Value: testUser.Id,
2931
},
3032
{
3133
Key: "mlflow.experiment.sourceName",
3234
Value: experiment.Name,
3335
},
3436
{
3537
Key: "mlflow.ownerId",
36-
Value: TestUser.Id,
38+
Value: testUser.Id,
3739
},
3840
{
3941
Key: "mlflow.ownerEmail",
40-
Value: TestUser.UserName,
42+
Value: testUser.UserName,
4143
},
4244
{
4345
Key: "mlflow.experimentType",

libs/testserver/jobs.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ func (s *FakeWorkspace) JobsCreate(req Request) Response {
3232

3333
// CreatorUserName field is used by TF to check if the resource exists or not. CreatorUserName should be non-empty for the resource to be considered as "exists"
3434
// https://github.com/databricks/terraform-provider-databricks/blob/main/permissions/permission_definitions.go#L108
35-
s.Jobs[jobId] = jobs.Job{JobId: jobId, Settings: &jobSettings, CreatorUserName: TestUser.UserName}
35+
s.Jobs[jobId] = jobs.Job{
36+
JobId: jobId,
37+
Settings: &jobSettings,
38+
CreatorUserName: s.CurrentUser().UserName,
39+
}
3640
return Response{Body: jobs.CreateResponse{JobId: jobId}}
3741
}
3842

0 commit comments

Comments
 (0)