Skip to content

Commit 2c69dd3

Browse files
INTMDB-931: Add support for OIDCAuthType to database user (#512)
1 parent 3460f8c commit 2c69dd3

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

mongodbatlas/database_users.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type DatabaseUser struct {
7272
Scopes []Scope `json:"scopes"`
7373
Password string `json:"password,omitempty"`
7474
Username string `json:"username,omitempty"`
75+
OIDCAuthType string `json:"oidcAuthType,omitempty"`
7576
}
7677

7778
// GetAuthDB determines the authentication database based on the type of user.

mongodbatlas/database_users_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,60 @@ func TestDatabaseUsers_CreateWithAWSIAMType(t *testing.T) {
291291
}
292292
}
293293

294+
func TestDatabaseUsers_CreateWithOIDC(t *testing.T) {
295+
client, mux, teardown := setup()
296+
defer teardown()
297+
298+
groupID := "1"
299+
300+
createRequest := &DatabaseUser{
301+
DatabaseName: "$external",
302+
Username: "0oaqyt9fc2ySTWnA0357/test-cfn-config-name",
303+
GroupID: groupID,
304+
OIDCAuthType: "IDP_GROUP",
305+
Scopes: []Scope{},
306+
}
307+
308+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/databaseUsers", groupID), func(w http.ResponseWriter, r *http.Request) {
309+
expected := map[string]interface{}{
310+
"databaseName": "$external",
311+
"username": "0oaqyt9fc2ySTWnA0357/test-cfn-config-name",
312+
"groupId": groupID,
313+
"oidcAuthType": "IDP_GROUP",
314+
"scopes": []interface{}{},
315+
}
316+
317+
var v map[string]interface{}
318+
err := json.NewDecoder(r.Body).Decode(&v)
319+
if err != nil {
320+
t.Fatalf("decode json: %v", err)
321+
}
322+
323+
if !reflect.DeepEqual(v, expected) {
324+
t.Errorf("Request body\n got=%#v\nwant=%#v", v, expected)
325+
}
326+
327+
fmt.Fprint(w, `{
328+
"databaseName": "$external",
329+
"username": "0oaqyt9fc2ySTWnA0357/test-cfn-config-name",
330+
"groupId": "1",
331+
"oidcAuthType": "IDP_GROUP",
332+
"scopes" : []
333+
}`)
334+
})
335+
336+
dbUser, _, err := client.DatabaseUsers.Create(ctx, groupID, createRequest)
337+
if err != nil {
338+
t.Errorf("DatabaseUsers.Create returned error: %v", err)
339+
}
340+
if username := dbUser.Username; username != "0oaqyt9fc2ySTWnA0357/test-cfn-config-name" {
341+
t.Errorf("expected username '%s', received '%s'", "0oaqyt9fc2ySTWnA0357/test-cfn-config-name", username)
342+
}
343+
if id := dbUser.GroupID; id != groupID {
344+
t.Errorf("expected groupId '%s', received '%s'", groupID, id)
345+
}
346+
}
347+
294348
func TestDatabaseUsers_Create(t *testing.T) {
295349
client, mux, teardown := setup()
296350
defer teardown()

0 commit comments

Comments
 (0)