From d54059ae1b3a308ca0b29e76db5136ab1f5c6da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20P=2E=20Michalik?= Date: Thu, 2 Oct 2025 16:01:49 +0200 Subject: [PATCH] AC-1384: allowed domains --- configuration/api.go | 17 ++++++++++ configuration/api_test.go | 65 +++++++++++++++++++++++++++++++++++++++ configuration/internal.go | 15 +++++++++ 3 files changed, 97 insertions(+) diff --git a/configuration/api.go b/configuration/api.go index d0aac0f..b968b20 100644 --- a/configuration/api.go +++ b/configuration/api.go @@ -529,6 +529,23 @@ func (a *API) ListAutoAccesses() ([]*AutoAccess, error) { return resp, err } +// AddAllowedDomain adds a domain to the allowed domains list. +func (a *API) AddAllowedDomain(domain string) error { + return a.Call("add_allowed_domain", &addAllowedDomainRequest{Domain: domain}, &emptyResponse{}) +} + +// DeleteAllowedDomain removes a domain from the allowed domains list. +func (a *API) DeleteAllowedDomain(domain string) error { + return a.Call("delete_allowed_domain", &deleteAllowedDomainRequest{Domain: domain}, &emptyResponse{}) +} + +// ListAllowedDomains returns all allowed domains. +func (a *API) ListAllowedDomains() ([]string, error) { + var resp listAllowedDomainsResponse + err := a.Call("list_allowed_domains", &listAllowedDomainsRequest{}, &resp) + return resp.Domains, err +} + // CheckProductLimitsForPlan compares your organization's current resources with a given plan and returns those which exceeded the called plan's limits. func (a *API) CheckProductLimitsForPlan(plan string) (PlanLimits, error) { var resp PlanLimits diff --git a/configuration/api_test.go b/configuration/api_test.go index 32f7ef2..6d6e201 100644 --- a/configuration/api_test.go +++ b/configuration/api_test.go @@ -318,6 +318,11 @@ var mockedResponses = map[string]string{ "next_id": "pqi8oasdjahuakndw9nsad9na" } ]`, + "add_allowed_domain": `{}`, + "delete_allowed_domain": `{}`, + "list_allowed_domains": `{ + "domains": ["example.com", "test.com"] + }`, "check_product_limits_for_plan": `[ { "resource": "groups", @@ -1852,3 +1857,63 @@ func TestListCannedResponsesShouldReturnDataReceivedFromConfAPI(t *testing.T) { validateRequestBody(t, `{"group_ids":[0,1],"include_private":true,"limit":2,"page_id":"some_page=="}`, serverMock.LastRequest.Body) } + +func TestAddAllowedDomainOK(t *testing.T) { + serverMock := newServerMock(t, "add_allowed_domain") + client := NewTestClient(serverMock) + + api, err := configuration.NewAPI(stubTokenGetter, client, "client_id") + if err != nil { + t.Error("API creation failed") + } + + err = api.AddAllowedDomain("example.com") + if err != nil { + t.Errorf("AddAllowedDomain failed: %v", err) + } + + validateRequestBody(t, `{"domain":"example.com"}`, serverMock.LastRequest.Body) +} + +func TestDeleteAllowedDomainOK(t *testing.T) { + serverMock := newServerMock(t, "delete_allowed_domain") + client := NewTestClient(serverMock) + + api, err := configuration.NewAPI(stubTokenGetter, client, "client_id") + if err != nil { + t.Error("API creation failed") + } + + err = api.DeleteAllowedDomain("example.com") + if err != nil { + t.Errorf("DeleteAllowedDomain failed: %v", err) + } + + validateRequestBody(t, `{"domain":"example.com"}`, serverMock.LastRequest.Body) +} + +func TestListAllowedDomainsShouldReturnDataReceivedFromConfAPI(t *testing.T) { + client := NewTestClient(newServerMock(t, "list_allowed_domains")) + + api, err := configuration.NewAPI(stubTokenGetter, client, "client_id") + if err != nil { + t.Error("API creation failed") + } + + resp, err := api.ListAllowedDomains() + if err != nil { + t.Errorf("ListAllowedDomains failed: %v", err) + } + + if len(resp) != 2 { + t.Errorf("Invalid response length: %v", len(resp)) + } + + if resp[0] != "example.com" { + t.Errorf("Invalid first domain: %v", resp[0]) + } + + if resp[1] != "test.com" { + t.Errorf("Invalid second domain: %v", resp[1]) + } +} diff --git a/configuration/internal.go b/configuration/internal.go index d2ca1e9..d7dbbf0 100644 --- a/configuration/internal.go +++ b/configuration/internal.go @@ -227,6 +227,21 @@ type deleteAutoAccessRequest struct { type listAutoAccessesRequest struct { } +type addAllowedDomainRequest struct { + Domain string `json:"domain"` +} + +type deleteAllowedDomainRequest struct { + Domain string `json:"domain"` +} + +type listAllowedDomainsRequest struct { +} + +type listAllowedDomainsResponse struct { + Domains []string `json:"domains"` +} + type checkProductLimitsForPlanRequest struct { Plan string `json:"plan"` }