From cfed26b9ed7d7c201fd2b949cf2037c7de01b770 Mon Sep 17 00:00:00 2001 From: Jeremy Tellaa Date: Tue, 12 Nov 2024 11:52:49 +0100 Subject: [PATCH 1/3] feat: implement 'allowed_email_domains_list' group attribute --- groups.go | 2 ++ groups_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/groups.go b/groups.go index 0e85961d6..593883f50 100644 --- a/groups.go +++ b/groups.go @@ -87,6 +87,7 @@ type Group struct { MarkedForDeletionOn *ISOTime `json:"marked_for_deletion_on"` CreatedAt *time.Time `json:"created_at"` IPRestrictionRanges string `json:"ip_restriction_ranges"` + AllowedEmailDomainsList string `json:"allowed_email_domains_list"` WikiAccessLevel AccessControlValue `json:"wiki_access_level"` // Deprecated: Use EmailsEnabled instead @@ -532,6 +533,7 @@ type UpdateGroupOptions struct { SharedRunnersSetting *SharedRunnersSettingValue `url:"shared_runners_setting,omitempty" json:"shared_runners_setting,omitempty"` PreventSharingGroupsOutsideHierarchy *bool `url:"prevent_sharing_groups_outside_hierarchy,omitempty" json:"prevent_sharing_groups_outside_hierarchy,omitempty"` IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"` + AllowedEmailDomainsList *string `url:"allowed_email_domains_list,omitempty" json:"allowed_email_domains_list,omitempty"` WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"` // Deprecated: Use EmailsEnabled instead diff --git a/groups_test.go b/groups_test.go index 05baf8034..6f0995b64 100644 --- a/groups_test.go +++ b/groups_test.go @@ -1124,3 +1124,42 @@ func TestEditGroupPushRules(t *testing.T) { t.Errorf("Groups.EditGroupPushRule returned %+v, want %+v", rule, want) } } + +func TestUpdateGroupWithAllowedEmailDomainsList(t *testing.T) { + mux, client := setup(t) + const domain = "example.com" + + mux.HandleFunc("/api/v4/groups/1", + func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPut) + + body, err := io.ReadAll(r.Body) + if err != nil { + t.Fatalf("Failed to read the request body. Error: %v", err) + } + + var bodyJson map[string]interface{} + err = json.Unmarshal(body, &bodyJson) + if err != nil { + t.Fatalf("Failed to parse the request body into JSON. Error: %v", err) + } + + if bodyJson["allowed_email_domains_list"] != domain { + t.Fatalf("Test failed. `allowed_email_domains_list` expected to be '%v', got %v", domain, bodyJson["allowed_email_domains_list"]) + } + + fmt.Fprintf(w, `{"id": 1, "allowed_email_domains_list" : "%v"}`, domain) + }) + + group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{ + AllowedEmailDomainsList: Ptr(domain), + }) + if err != nil { + t.Errorf("Groups.UpdateGroup returned error: %v", err) + } + + want := &Group{ID: 1, AllowedEmailDomainsList: domain} + if !reflect.DeepEqual(want, group) { + t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want) + } +} From f285de48fa4041365857386d5ce6dd55a2e6e323 Mon Sep 17 00:00:00 2001 From: Jeremy Tellaa Date: Fri, 15 Nov 2024 09:37:03 +0100 Subject: [PATCH 2/3] fix: 'ip_restriction_ranges' is not a create group field --- groups.go | 1 - groups_test.go | 26 -------------------------- 2 files changed, 27 deletions(-) diff --git a/groups.go b/groups.go index 593883f50..c7b9e548f 100644 --- a/groups.go +++ b/groups.go @@ -384,7 +384,6 @@ type CreateGroupOptions struct { ParentID *int `url:"parent_id,omitempty" json:"parent_id,omitempty"` SharedRunnersMinutesLimit *int `url:"shared_runners_minutes_limit,omitempty" json:"shared_runners_minutes_limit,omitempty"` ExtraSharedRunnersMinutesLimit *int `url:"extra_shared_runners_minutes_limit,omitempty" json:"extra_shared_runners_minutes_limit,omitempty"` - IPRestrictionRanges *string `url:"ip_restriction_ranges,omitempty" json:"ip_restriction_ranges,omitempty"` WikiAccessLevel *AccessControlValue `url:"wiki_access_level,omitempty" json:"wiki_access_level,omitempty"` // Deprecated: Use EmailsEnabled instead diff --git a/groups_test.go b/groups_test.go index 6f0995b64..7138702d7 100644 --- a/groups_test.go +++ b/groups_test.go @@ -783,32 +783,6 @@ func TestUnshareGroupFromGroup(t *testing.T) { } } -func TestCreateGroupWithIPRestrictionRanges(t *testing.T) { - mux, client := setup(t) - - mux.HandleFunc("/api/v4/groups", - func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, http.MethodPost) - fmt.Fprint(w, `{"id": 1, "name": "g", "path": "g", "ip_restriction_ranges" : "192.168.0.0/24"}`) - }) - - opt := &CreateGroupOptions{ - Name: Ptr("g"), - Path: Ptr("g"), - IPRestrictionRanges: Ptr("192.168.0.0/24"), - } - - group, _, err := client.Groups.CreateGroup(opt, nil) - if err != nil { - t.Errorf("Groups.CreateGroup returned error: %v", err) - } - - want := &Group{ID: 1, Name: "g", Path: "g", IPRestrictionRanges: "192.168.0.0/24"} - if !reflect.DeepEqual(want, group) { - t.Errorf("Groups.CreateGroup returned %+v, want %+v", group, want) - } -} - func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) { mux, client := setup(t) From 4f7ea733c05d3596e6c5f9404ddc7a93bcd6d403 Mon Sep 17 00:00:00 2001 From: Jeremy Tellaa Date: Fri, 15 Nov 2024 10:05:20 +0100 Subject: [PATCH 3/3] chore: improve IPRestrictionRanges test --- groups_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/groups_test.go b/groups_test.go index 7138702d7..7a8c281c0 100644 --- a/groups_test.go +++ b/groups_test.go @@ -785,21 +785,38 @@ func TestUnshareGroupFromGroup(t *testing.T) { func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) { mux, client := setup(t) + const ipRange = "192.168.0.0/24" mux.HandleFunc("/api/v4/groups/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPut) - fmt.Fprint(w, `{"id": 1, "ip_restriction_ranges" : "192.168.0.0/24"}`) + + body, err := io.ReadAll(r.Body) + if err != nil { + t.Fatalf("Failed to read the request body. Error: %v", err) + } + + var bodyJson map[string]interface{} + err = json.Unmarshal(body, &bodyJson) + if err != nil { + t.Fatalf("Failed to parse the request body into JSON. Error: %v", err) + } + + if bodyJson["ip_restriction_ranges"] != ipRange { + t.Fatalf("Test failed. `ip_restriction_ranges` expected to be '%v', got %v", ipRange, bodyJson["ip_restriction_ranges"]) + } + + fmt.Fprintf(w, `{"id": 1, "ip_restriction_ranges" : "%v"}`, ipRange) }) group, _, err := client.Groups.UpdateGroup(1, &UpdateGroupOptions{ - IPRestrictionRanges: Ptr("192.168.0.0/24"), + IPRestrictionRanges: Ptr(ipRange), }) if err != nil { t.Errorf("Groups.UpdateGroup returned error: %v", err) } - want := &Group{ID: 1, IPRestrictionRanges: "192.168.0.0/24"} + want := &Group{ID: 1, IPRestrictionRanges: ipRange} if !reflect.DeepEqual(want, group) { t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", group, want) }