Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions configuration/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions configuration/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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])
}
}
15 changes: 15 additions & 0 deletions configuration/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down