github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/adminorg_administration_test.go (about)

     1  //go:build org || functional || ALL
     2  
     3  /*
     4   * Copyright 2020 VMware, Inc.  All rights reserved.  Licensed under the Apache v2 License.
     5   */
     6  
     7  package govcd
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/vmware/go-vcloud-director/v2/types/v56"
    13  	. "gopkg.in/check.v1"
    14  )
    15  
    16  // Test_LDAP_Configuration tests LDAP configuration functions
    17  func (vcd *TestVCD) Test_LDAP_Configuration(check *C) {
    18  	if vcd.skipAdminTests {
    19  		check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName()))
    20  	}
    21  
    22  	org, err := vcd.client.GetAdminOrgByName(vcd.config.VCD.Org)
    23  	check.Assert(err, IsNil)
    24  
    25  	ldapSettings := &types.OrgLdapSettingsType{
    26  		OrgLdapMode: types.LdapModeCustom,
    27  		CustomOrgLdapSettings: &types.CustomOrgLdapSettings{
    28  			HostName:                "1.1.1.1",
    29  			Port:                    389,
    30  			SearchBase:              "dc=planetexpress,dc=com",
    31  			AuthenticationMechanism: "SIMPLE",
    32  			ConnectorType:           "OPEN_LDAP",
    33  			Username:                "cn=admin,dc=planetexpress,dc=com",
    34  			Password:                "GoodNewsEveryone",
    35  			UserAttributes: &types.OrgLdapUserAttributes{
    36  				ObjectClass:               "inetOrgPerson",
    37  				ObjectIdentifier:          "uid",
    38  				Username:                  "uid",
    39  				Email:                     "mail",
    40  				FullName:                  "cn",
    41  				GivenName:                 "givenName",
    42  				Surname:                   "sn",
    43  				Telephone:                 "telephoneNumber",
    44  				GroupMembershipIdentifier: "dn",
    45  			},
    46  			GroupAttributes: &types.OrgLdapGroupAttributes{
    47  				ObjectClass:          "group",
    48  				ObjectIdentifier:     "cn",
    49  				GroupName:            "cn",
    50  				Membership:           "member",
    51  				MembershipIdentifier: "dn",
    52  			},
    53  		},
    54  	}
    55  	gotSettings, err := org.LdapConfigure(ldapSettings)
    56  	check.Assert(err, IsNil)
    57  
    58  	AddToCleanupList("LDAP-configuration", "orgLdapSettings", org.AdminOrg.Name, check.TestName())
    59  
    60  	check.Assert(ldapSettings.CustomOrgLdapSettings.GroupAttributes, DeepEquals, gotSettings.CustomOrgLdapSettings.GroupAttributes)
    61  	check.Assert(ldapSettings.CustomOrgLdapSettings.UserAttributes, DeepEquals, gotSettings.CustomOrgLdapSettings.UserAttributes)
    62  	check.Assert(ldapSettings.CustomOrgLdapSettings.UserAttributes, DeepEquals, gotSettings.CustomOrgLdapSettings.UserAttributes)
    63  	check.Assert(ldapSettings.CustomOrgLdapSettings.Username, DeepEquals, gotSettings.CustomOrgLdapSettings.Username)
    64  	check.Assert(ldapSettings.CustomOrgLdapSettings.AuthenticationMechanism, DeepEquals, gotSettings.CustomOrgLdapSettings.AuthenticationMechanism)
    65  	check.Assert(ldapSettings.CustomOrgLdapSettings.ConnectorType, DeepEquals, gotSettings.CustomOrgLdapSettings.ConnectorType)
    66  
    67  	err = org.LdapDisable()
    68  	check.Assert(err, IsNil)
    69  
    70  	ldapConfig, err := org.GetLdapConfiguration()
    71  	check.Assert(err, IsNil)
    72  
    73  	check.Assert(ldapConfig.OrgLdapMode, Equals, types.LdapModeNone)
    74  
    75  }