-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Implement Enterprise SCIM - EnterpriseService.ListProvisionedSCIMUsers #3839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elminster-aom
wants to merge
5
commits into
google:master
Choose a base branch
from
elminster-aom:dev/SCIMUser_list
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+541
−2
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6d306e9
Create User structures
elminster-aom 5c1c1f9
Fix: Stop test when unexpected errors from tested method
elminster-aom d68a9e0
Set dedicated `Accept` header for SCIM endpoints
elminster-aom fc3259f
Implement test for ListProvisionedSCIMUsers
elminster-aom b22b4eb
Merge branch 'master' into dev/SCIMUser_list
elminster-aom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,139 @@ func TestSCIMEnterpriseGroups_Marshal(t *testing.T) { | |
| testJSONMarshal(t, u, want) | ||
| } | ||
|
|
||
| func TestSCIMEnterpriseUsers_Marshal(t *testing.T) { | ||
| t.Parallel() | ||
| testJSONMarshal(t, &SCIMEnterpriseUsers{}, "{}") | ||
|
|
||
| u := &SCIMEnterpriseUsers{ | ||
| Schemas: []string{SCIMSchemasURINamespacesListResponse}, | ||
| TotalResults: Ptr(1), | ||
| ItemsPerPage: Ptr(1), | ||
| StartIndex: Ptr(1), | ||
| Resources: []*SCIMEnterpriseUserAttributes{{ | ||
| Active: true, | ||
| Emails: []*SCIMEnterpriseUserEmail{{ | ||
| Primary: true, | ||
| Type: "work", | ||
| Value: "[email protected]", | ||
| }}, | ||
| Roles: []*SCIMEnterpriseUserRole{{ | ||
| Display: Ptr("rd1"), | ||
| Primary: Ptr(true), | ||
| Type: Ptr("rt1"), | ||
| Value: "rv1", | ||
| }}, | ||
| Schemas: []string{SCIMSchemasURINamespacesUser}, | ||
| UserName: "un1", | ||
| Groups: []*SCIMEnterpriseDisplayReference{{ | ||
| Value: "idgn1", | ||
| Ref: "https://api.github.com/scim/v2/enterprises/ee/Groups/idgn1", | ||
| Display: Ptr("gn1"), | ||
| }}, | ||
| ID: Ptr("idun1"), | ||
| ExternalID: "eidun1", | ||
| DisplayName: "dun1", | ||
| Meta: &SCIMEnterpriseMeta{ | ||
| ResourceType: "User", | ||
| Created: &Timestamp{referenceTime}, | ||
| LastModified: &Timestamp{referenceTime}, | ||
| Location: Ptr("https://api.github.com/scim/v2/enterprises/ee/User/idun1"), | ||
| }, | ||
| Name: &SCIMEnterpriseUserName{ | ||
| GivenName: "gnn1", | ||
| FamilyName: "fnn1", | ||
| Formatted: Ptr("f1"), | ||
| MiddleName: Ptr("mn1"), | ||
| }, | ||
| }}, | ||
| } | ||
|
|
||
| want := `{ | ||
| "schemas": ["` + SCIMSchemasURINamespacesListResponse + `"], | ||
| "TotalResults": 1, | ||
| "itemsPerPage": 1, | ||
| "StartIndex": 1, | ||
| "Resources": [{ | ||
| "active": true, | ||
| "emails": [{ | ||
| "primary": true, | ||
| "type": "work", | ||
| "value": "[email protected]" | ||
| }], | ||
| "roles": [{ | ||
| "display": "rd1", | ||
| "primary": true, | ||
| "type": "rt1", | ||
| "value": "rv1" | ||
| }], | ||
| "schemas": ["` + SCIMSchemasURINamespacesUser + `"], | ||
| "userName": "un1", | ||
| "groups": [{ | ||
| "value": "idgn1", | ||
| "$ref": "https://api.github.com/scim/v2/enterprises/ee/Groups/idgn1", | ||
| "display": "gn1" | ||
| }], | ||
| "id": "idun1", | ||
| "externalId": "eidun1", | ||
| "name": { | ||
| "givenName": "gnn1", | ||
| "familyName": "fnn1", | ||
| "formatted": "f1", | ||
| "middleName": "mn1" | ||
| }, | ||
| "displayName": "dun1", | ||
| "meta": { | ||
| "resourceType": "User", | ||
| "created": ` + referenceTimeStr + `, | ||
| "lastModified": ` + referenceTimeStr + `, | ||
| "location": "https://api.github.com/scim/v2/enterprises/ee/User/idun1" | ||
| } | ||
| }] | ||
| }` | ||
|
|
||
| testJSONMarshal(t, u, want) | ||
| } | ||
|
|
||
| func TestListProvisionedSCIMGroupsEnterpriseOptions_Marshal(t *testing.T) { | ||
| t.Parallel() | ||
| testJSONMarshal(t, &ListProvisionedSCIMGroupsEnterpriseOptions{}, "{}") | ||
|
|
||
| u := &ListProvisionedSCIMGroupsEnterpriseOptions{ | ||
| Filter: "f", | ||
| ExcludedAttributes: "ea", | ||
| StartIndex: 5, | ||
| Count: 9, | ||
| } | ||
|
|
||
| want := `{ | ||
| "filter": "f", | ||
| "excludedAttributes": "ea", | ||
| "startIndex": 5, | ||
| "count": 9 | ||
| }` | ||
|
|
||
| testJSONMarshal(t, u, want) | ||
| } | ||
|
|
||
| func TestListProvisionedSCIMUsersEnterpriseOptions_Marshal(t *testing.T) { | ||
| t.Parallel() | ||
| testJSONMarshal(t, &ListProvisionedSCIMUsersEnterpriseOptions{}, "{}") | ||
|
|
||
| u := &ListProvisionedSCIMUsersEnterpriseOptions{ | ||
| Filter: "f", | ||
| StartIndex: 3, | ||
| Count: 7, | ||
| } | ||
|
|
||
| want := `{ | ||
| "filter": "f", | ||
| "startIndex": 3, | ||
| "count": 7 | ||
| }` | ||
|
|
||
| testJSONMarshal(t, u, want) | ||
| } | ||
|
|
||
| func TestSCIMEnterpriseGroupAttributes_Marshal(t *testing.T) { | ||
| t.Parallel() | ||
| testJSONMarshal(t, &SCIMEnterpriseGroupAttributes{}, "{}") | ||
|
|
@@ -110,12 +243,13 @@ func TestSCIMEnterpriseGroupAttributes_Marshal(t *testing.T) { | |
| testJSONMarshal(t, u, want) | ||
| } | ||
|
|
||
| func TestEnterpriseService_ListProvisionedSCIMEnterpriseGroups(t *testing.T) { | ||
| func TestEnterpriseService_ListProvisionedSCIMGroups(t *testing.T) { | ||
| t.Parallel() | ||
| client, mux, _ := setup(t) | ||
|
|
||
| mux.HandleFunc("/scim/v2/enterprises/ee/Groups", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
| testHeader(t, r, "Accept", mediaTypeSCIM) | ||
| testFormValues(t, r, values{ | ||
| "startIndex": "1", | ||
| "excludedAttributes": "members,meta", | ||
|
|
@@ -157,7 +291,7 @@ func TestEnterpriseService_ListProvisionedSCIMEnterpriseGroups(t *testing.T) { | |
| } | ||
| groups, _, err := client.Enterprise.ListProvisionedSCIMGroups(ctx, "ee", opts) | ||
| if err != nil { | ||
| t.Errorf("Enterprise.ListProvisionedSCIMGroups returned error: %v", err) | ||
| t.Fatalf("Enterprise.ListProvisionedSCIMGroups returned unexpected error: %v", err) | ||
| } | ||
|
|
||
| want := SCIMEnterpriseGroups{ | ||
|
|
@@ -199,3 +333,108 @@ func TestEnterpriseService_ListProvisionedSCIMEnterpriseGroups(t *testing.T) { | |
| return r, err | ||
| }) | ||
| } | ||
|
|
||
| func TestEnterpriseService_ListProvisionedSCIMUsers(t *testing.T) { | ||
| t.Parallel() | ||
| client, mux, _ := setup(t) | ||
|
|
||
| mux.HandleFunc("/scim/v2/enterprises/octo-org/Users", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
| testHeader(t, r, "Accept", mediaTypeSCIM) | ||
| testFormValues(t, r, values{ | ||
| "startIndex": "1", | ||
| "count": "3", | ||
| "filter": `userName eq "[email protected]"`, | ||
| }) | ||
| w.WriteHeader(http.StatusOK) | ||
| _, _ = w.Write([]byte(`{ | ||
| "schemas": ["` + SCIMSchemasURINamespacesListResponse + `"], | ||
| "totalResults": 1, | ||
| "itemsPerPage": 1, | ||
| "startIndex": 1, | ||
| "Resources": [ | ||
| { | ||
| "schemas": ["` + SCIMSchemasURINamespacesUser + `"], | ||
| "id": "5fc0", | ||
| "externalId": "00u1", | ||
| "userName": "[email protected]", | ||
| "displayName": "Mona Octocat", | ||
| "name": { | ||
| "givenName": "Mona", | ||
| "familyName": "Octocat", | ||
| "formatted": "Mona Octocat" | ||
| }, | ||
| "emails": [ | ||
| { | ||
| "value": "[email protected]", | ||
| "primary": true | ||
| } | ||
| ], | ||
| "active": true, | ||
| "meta": { | ||
| "resourceType": "User", | ||
| "created": ` + referenceTimeStr + `, | ||
| "lastModified": ` + referenceTimeStr + `, | ||
| "location": "https://api.github.com/scim/v2/organizations/octo-org/Users/5fc0" | ||
| } | ||
| } | ||
| ] | ||
| }`)) | ||
| }) | ||
|
|
||
| ctx := t.Context() | ||
| opts := &ListProvisionedSCIMUsersEnterpriseOptions{ | ||
| StartIndex: 1, | ||
| Count: 3, | ||
| Filter: `userName eq "[email protected]"`, | ||
| } | ||
| users, _, err := client.Enterprise.ListProvisionedSCIMUsers(ctx, "octo-org", opts) | ||
| if err != nil { | ||
| t.Fatalf("Enterprise.ListProvisionedSCIMUsers returned unexpected error: %v", err) | ||
| } | ||
|
|
||
| want := SCIMEnterpriseUsers{ | ||
| Schemas: []string{SCIMSchemasURINamespacesListResponse}, | ||
| TotalResults: Ptr(1), | ||
| ItemsPerPage: Ptr(1), | ||
| StartIndex: Ptr(1), | ||
| Resources: []*SCIMEnterpriseUserAttributes{{ | ||
| Schemas: []string{SCIMSchemasURINamespacesUser}, | ||
| ID: Ptr("5fc0"), | ||
| ExternalID: "00u1", | ||
| UserName: "[email protected]", | ||
| DisplayName: "Mona Octocat", | ||
| Name: &SCIMEnterpriseUserName{ | ||
| GivenName: "Mona", | ||
| FamilyName: "Octocat", | ||
| Formatted: Ptr("Mona Octocat"), | ||
| }, | ||
| Emails: []*SCIMEnterpriseUserEmail{{ | ||
| Value: "[email protected]", | ||
| Primary: true, | ||
| }}, | ||
| Active: true, | ||
| Meta: &SCIMEnterpriseMeta{ | ||
| ResourceType: "User", | ||
| Created: &Timestamp{referenceTime}, | ||
| LastModified: &Timestamp{referenceTime}, | ||
| Location: Ptr("https://api.github.com/scim/v2/organizations/octo-org/Users/5fc0"), | ||
| }, | ||
| }}, | ||
| } | ||
|
|
||
| if diff := cmp.Diff(want, *users); diff != "" { | ||
| t.Errorf("Enterprise.ListProvisionedSCIMUsers diff mismatch (-want +got):\n%v", diff) | ||
| } | ||
|
|
||
| const methodName = "ListProvisionedSCIMUsers" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.Enterprise.ListProvisionedSCIMUsers(ctx, "\n", opts) | ||
| return err | ||
| }) | ||
|
|
||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| _, r, err := client.Enterprise.ListProvisionedSCIMUsers(ctx, "o", opts) | ||
| return r, err | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
omitemptyfields should be pointers since they are optional values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the previous PR, #discussion_r2524023305; @alexandear recommended this structure for options structures:
go-github/github/github.go
Lines 262 to 288 in 4ed75ac