From cd96bc298f19f05110e13b0d3be917f2aa49292b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Mon, 27 Jul 2020 09:18:49 +0200 Subject: [PATCH] (doc) adding test and updating README --- README.md | 4 +- internal/aws/client_test.go | 76 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b530d160..2d3b616b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ SSO Sync will run on any platform that Go can build for. -> :warning: There are breaking changes for versions `>= 0.02` +> :warning: there are breaking changes for versions `>= 0.02` +> :warning: `>= 1.0.0-rc.2` groups to do not get deleted in AWS SSO when deleted in the Google Directory +> 🤔 we hope to support other providers in the future ## Why? diff --git a/internal/aws/client_test.go b/internal/aws/client_test.go index e568d707..a67d08eb 100644 --- a/internal/aws/client_test.go +++ b/internal/aws/client_test.go @@ -366,6 +366,82 @@ func TestClient_FindUserByEmail(t *testing.T) { assert.NoError(t, err) } +func TestClient_FindGroupByDisplayName(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + x := mock.NewMockIHttpClient(ctrl) + + c, err := NewClient(x, &Config{ + Endpoint: "https://scim.example.com/", + Token: "bearerToken", + }) + assert.NoError(t, err) + + calledURL, _ := url.Parse("https://scim.example.com/Groups") + + filter := "displayName eq \"testGroup\"" + + q := calledURL.Query() + q.Add("filter", filter) + + calledURL.RawQuery = q.Encode() + + req := httpReqMatcher{ + httpReq: &http.Request{ + URL: calledURL, + Method: http.MethodGet, + }, + } + + // Error in response + x.EXPECT().Do(&req).MaxTimes(1).Return(&http.Response{ + Status: "OK", + StatusCode: 200, + Body: nopCloser{bytes.NewBufferString("")}, + }, nil) + + u, err := c.FindGroupByDisplayName("testGroup") + assert.Nil(t, u) + assert.Error(t, err) + + // False + r := &GroupFilterResults{ + TotalResults: 0, + } + falseResult, _ := json.Marshal(r) + + x.EXPECT().Do(&req).MaxTimes(1).Return(&http.Response{ + Status: "OK", + StatusCode: 200, + Body: nopCloser{bytes.NewBuffer(falseResult)}, + }, nil) + + u, err = c.FindGroupByDisplayName("testGroup") + assert.Nil(t, u) + assert.Error(t, err) + + // True + r = &GroupFilterResults{ + TotalResults: 1, + Resources: []Group{ + { + DisplayName: "testGroup", + }, + }, + } + trueResult, _ := json.Marshal(r) + x.EXPECT().Do(&req).MaxTimes(1).Return(&http.Response{ + Status: "OK", + StatusCode: 200, + Body: nopCloser{bytes.NewBuffer(trueResult)}, + }, nil) + + u, err = c.FindGroupByDisplayName("testGroup") + assert.NotNil(t, u) + assert.NoError(t, err) +} + func TestClient_DeleteGroup(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish()