diff --git a/groups.go b/groups.go index 0e85961d6..c7b9e548f 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 @@ -383,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 @@ -532,6 +532,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..7a8c281c0 100644 --- a/groups_test.go +++ b/groups_test.go @@ -783,49 +783,40 @@ func TestUnshareGroupFromGroup(t *testing.T) { } } -func TestCreateGroupWithIPRestrictionRanges(t *testing.T) { +func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) { mux, client := setup(t) + const ipRange = "192.168.0.0/24" - mux.HandleFunc("/api/v4/groups", + mux.HandleFunc("/api/v4/groups/1", 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"), - } + testMethod(t, r, http.MethodPut) - group, _, err := client.Groups.CreateGroup(opt, nil) - if err != nil { - t.Errorf("Groups.CreateGroup returned error: %v", err) - } + body, err := io.ReadAll(r.Body) + if err != nil { + t.Fatalf("Failed to read the request body. 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) - } -} + 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) + } -func TestUpdateGroupWithIPRestrictionRanges(t *testing.T) { - mux, client := setup(t) + if bodyJson["ip_restriction_ranges"] != ipRange { + t.Fatalf("Test failed. `ip_restriction_ranges` expected to be '%v', got %v", ipRange, bodyJson["ip_restriction_ranges"]) + } - 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"}`) + 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) } @@ -1124,3 +1115,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) + } +}