Skip to content

Commit c524e54

Browse files
committed
validate retrieved id/username against provided
1 parent f149934 commit c524e54

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

internal/provider/user_data_source.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func (d *UserDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
155155
resp.Diagnostics.AddError("Client Error", "User is not associated with any organizations")
156156
return
157157
}
158+
if !data.ID.IsNull() && user.ID.String() != data.ID.ValueString() {
159+
resp.Diagnostics.AddError("Client Error", "Retrieved User's ID does not match the provided ID")
160+
return
161+
} else if !data.Username.IsNull() && user.Username != data.Username.ValueString() {
162+
resp.Diagnostics.AddError("Client Error", "Retrieved User's username does not match the provided username")
163+
return
164+
}
158165

159166
data.ID = types.StringValue(user.ID.String())
160167
data.Username = types.StringValue(user.Username)

internal/provider/user_data_source_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func TestAccUserDataSource(t *testing.T) {
6767

6868
t.Run("UserByID", func(t *testing.T) {
6969
cfg := testAccUserDataSourceConfig{
70-
URL: client.URL.String(),
71-
Token: client.SessionToken(),
72-
Username: user.ID.String(),
70+
URL: client.URL.String(),
71+
Token: client.SessionToken(),
72+
ID: user.ID.String(),
7373
}
7474
resource.Test(t, resource.TestCase{
7575
PreCheck: func() { testAccPreCheck(t) },

0 commit comments

Comments
 (0)