...

Source file src/github.com/okta/okta-sdk-golang/v2/tests/integration/orgs_test.go

Documentation: github.com/okta/okta-sdk-golang/v2/tests/integration

     1  /*
     2   * Copyright 2018 - Present Okta, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package integration
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"testing"
    23  	"time"
    24  
    25  	"github.com/okta/okta-sdk-golang/v2/okta"
    26  	"github.com/okta/okta-sdk-golang/v2/tests"
    27  	"github.com/stretchr/testify/assert"
    28  	"github.com/stretchr/testify/require"
    29  )
    30  
    31  func TestGetOrgContactTypes(t *testing.T) {
    32  	ctx, client, err := tests.NewClient(context.TODO())
    33  	require.NoError(t, err)
    34  
    35  	contactTypes, _, err := client.OrgSetting.GetOrgContactTypes(ctx)
    36  	require.NoError(t, err)
    37  
    38  	// there should be a billing and technical contact type
    39  	var foundBilling, foundTechnical bool
    40  	for _, concontactType := range contactTypes {
    41  		if concontactType.ContactType == "BILLING" {
    42  			foundBilling = true
    43  		}
    44  		if concontactType.ContactType == "TECHNICAL" {
    45  			foundTechnical = true
    46  		}
    47  	}
    48  	assert.True(t, foundBilling, "There should be billing contact type.")
    49  	assert.True(t, foundTechnical, "There should be technical contact type.")
    50  }
    51  
    52  func TestGetAndUpdateOrgContactUser(t *testing.T) {
    53  	// switch the billing and technical contacts
    54  
    55  	ctx, client, err := tests.NewClient(context.TODO())
    56  	require.NoError(t, err)
    57  
    58  	technicalUser, _, err := client.OrgSetting.GetOrgContactUser(ctx, "TECHNICAL")
    59  	require.NoError(t, err)
    60  
    61  	billingUser, _, err := client.OrgSetting.GetOrgContactUser(ctx, "BILLING")
    62  	require.NoError(t, err)
    63  
    64  	_, _, err = client.OrgSetting.UpdateOrgContactUser(ctx, "TECHNICAL", okta.UserIdString{UserId: billingUser.UserId})
    65  	require.NoError(t, err)
    66  
    67  	_, _, err = client.OrgSetting.UpdateOrgContactUser(ctx, "BILLING", okta.UserIdString{UserId: technicalUser.UserId})
    68  	require.NoError(t, err)
    69  }
    70  
    71  func TestOptInOptOutOktaCommunicationSettings(t *testing.T) {
    72  	ctx, client, err := tests.NewClient(context.TODO())
    73  	require.NoError(t, err)
    74  
    75  	// get the communication settings
    76  	// if opted in, opt out, then opt in
    77  	// if opted opted out, opt in, then opt out
    78  
    79  	settings, _, err := client.OrgSetting.GetOktaCommunicationSettings(ctx)
    80  	require.NoError(t, err)
    81  
    82  	var foundOptIn, foundOptOut bool
    83  	links := settings.Links.(map[string]interface{})
    84  	_, foundOptIn = links["optIn"]
    85  	_, foundOptOut = links["optOut"]
    86  
    87  	assert.True(t, (foundOptIn || foundOptOut), "There should be optIn or optOut setting")
    88  
    89  	if foundOptIn {
    90  		_, _, err := client.OrgSetting.OptInUsersToOktaCommunicationEmails(ctx)
    91  		require.NoError(t, err)
    92  		_, _, err = client.OrgSetting.OptOutUsersFromOktaCommunicationEmails(ctx)
    93  		require.NoError(t, err)
    94  	}
    95  
    96  	if foundOptOut {
    97  		_, _, err := client.OrgSetting.OptOutUsersFromOktaCommunicationEmails(ctx)
    98  		require.NoError(t, err)
    99  		_, _, err = client.OrgSetting.OptInUsersToOktaCommunicationEmails(ctx)
   100  		require.NoError(t, err)
   101  	}
   102  }
   103  
   104  func TestGetGrantExtentRevokeOktaCommunicationSettings(t *testing.T) {
   105  	ctx, client, err := tests.NewClient(context.TODO())
   106  	require.NoError(t, err)
   107  
   108  	// get the support settings
   109  	// if support not granted, grant it, extend it, revoke it
   110  	// if support granted, revoke it, grant it, extend it
   111  
   112  	settings, _, err := client.OrgSetting.GetOrgOktaSupportSettings(ctx)
   113  	require.NoError(t, err)
   114  
   115  	ops := []string{"revoke", "grant", "extend"}
   116  	opIndex := 0
   117  	if settings.Support != "ENABLED" {
   118  		opIndex = 1
   119  	}
   120  
   121  	// will grant, extend, revoke
   122  	// or will revoke, grant, extend
   123  	countOps := 0
   124  	for countOps < len(ops) {
   125  		switch ops[opIndex] {
   126  		case "revoke":
   127  			_, _, err := client.OrgSetting.RevokeOktaSupport(ctx)
   128  			require.NoError(t, err)
   129  		case "grant":
   130  			_, _, err := client.OrgSetting.GrantOktaSupport(ctx)
   131  			require.NoError(t, err)
   132  		case "extend":
   133  			_, _, err := client.OrgSetting.ExtendOktaSupport(ctx)
   134  			require.NoError(t, err)
   135  		}
   136  
   137  		opIndex++
   138  		if opIndex >= len(ops) {
   139  			opIndex = 0
   140  		}
   141  		countOps++
   142  	}
   143  }
   144  
   145  func TestGetPerfsShowHideFooter(t *testing.T) {
   146  	ctx, client, err := tests.NewClient(context.TODO())
   147  	require.NoError(t, err)
   148  
   149  	// get the org preferences
   150  	// if hidden footer, show it, then hide it
   151  	// if showing footer, hide it, then show it
   152  
   153  	preferences, _, err := client.OrgSetting.GetOrgPreferences(ctx)
   154  	require.NoError(t, err)
   155  
   156  	var showEndUserFooter, hideEndUserFooter bool
   157  	links := preferences.Links.(map[string]interface{})
   158  	_, showEndUserFooter = links["showEndUserFooter"]
   159  	_, hideEndUserFooter = links["hideEndUserFooter"]
   160  	assert.True(t, (showEndUserFooter || hideEndUserFooter), "There should be show or hide end user preference")
   161  
   162  	if showEndUserFooter {
   163  		_, _, err = client.OrgSetting.HideOktaUIFooter(ctx)
   164  		require.NoError(t, err)
   165  		_, _, err := client.OrgSetting.ShowOktaUIFooter(ctx)
   166  		require.NoError(t, err)
   167  	}
   168  
   169  	if hideEndUserFooter {
   170  		_, _, err := client.OrgSetting.ShowOktaUIFooter(ctx)
   171  		require.NoError(t, err)
   172  		_, _, err = client.OrgSetting.HideOktaUIFooter(ctx)
   173  		require.NoError(t, err)
   174  	}
   175  }
   176  
   177  func TestGetAndPartialUpdateOrgSettings(t *testing.T) {
   178  	ctx, client, err := tests.NewClient(context.TODO())
   179  	require.NoError(t, err)
   180  
   181  	// get org settings, partial update org with new website
   182  	settings, _, err := client.OrgSetting.GetOrgSettings(ctx)
   183  	require.NoError(t, err)
   184  
   185  	website := fmt.Sprintf("https://developer.okta.com/golang-sdk-oie/testing/%d", time.Now().UnixNano())
   186  	assert.True(t, settings.Website != website)
   187  
   188  	partialSettings := okta.OrgSetting{Website: website}
   189  	newSettings, _, err := client.OrgSetting.PartialUpdateOrgSetting(ctx, partialSettings)
   190  	require.NoError(t, err)
   191  
   192  	assert.True(t, newSettings.Website == website, "Expected org website %q, got %q", website, newSettings.Website)
   193  }
   194  

View as plain text