1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//go:build acceptance
// +build acceptance
package v3
import (
"testing"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/federation"
th "github.com/gophercloud/gophercloud/testhelper"
)
func TestListMappings(t *testing.T) {
client, err := clients.NewIdentityV3Client()
th.AssertNoErr(t, err)
allPages, err := federation.ListMappings(client).AllPages()
th.AssertNoErr(t, err)
mappings, err := federation.ExtractMappings(allPages)
th.AssertNoErr(t, err)
tools.PrintResource(t, mappings)
}
func TestMappingsCRUD(t *testing.T) {
mappingName := tools.RandomString("TESTMAPPING-", 8)
clients.RequireAdmin(t)
client, err := clients.NewIdentityV3Client()
th.AssertNoErr(t, err)
createOpts := federation.CreateMappingOpts{
Rules: []federation.MappingRule{
{
Local: []federation.RuleLocal{
{
User: &federation.RuleUser{
Name: "{0}",
},
},
{
Group: &federation.Group{
ID: "0cd5e9",
},
},
},
Remote: []federation.RuleRemote{
{
Type: "UserName",
},
{
Type: "orgPersonType",
NotAnyOf: []string{
"Contractor",
"Guest",
},
},
},
},
},
}
createdMapping, err := federation.CreateMapping(client, mappingName, createOpts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, len(createOpts.Rules), len(createdMapping.Rules))
th.CheckDeepEquals(t, createOpts.Rules[0], createdMapping.Rules[0])
mapping, err := federation.GetMapping(client, mappingName).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, len(createOpts.Rules), len(mapping.Rules))
th.CheckDeepEquals(t, createOpts.Rules[0], mapping.Rules[0])
updateOpts := federation.UpdateMappingOpts{
Rules: []federation.MappingRule{
{
Local: []federation.RuleLocal{
{
User: &federation.RuleUser{
Name: "{0}",
},
},
{
Group: &federation.Group{
ID: "0cd5e9",
},
},
},
Remote: []federation.RuleRemote{
{
Type: "UserName",
},
{
Type: "orgPersonType",
AnyOneOf: []string{
"Contractor",
"SubContractor",
},
},
},
},
},
}
updatedMapping, err := federation.UpdateMapping(client, mappingName, updateOpts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, len(updateOpts.Rules), len(updatedMapping.Rules))
th.CheckDeepEquals(t, updateOpts.Rules[0], updatedMapping.Rules[0])
err = federation.DeleteMapping(client, mappingName).ExtractErr()
th.AssertNoErr(t, err)
resp := federation.GetMapping(client, mappingName)
th.AssertErr(t, resp.Err)
_, ok := resp.Err.(gophercloud.ErrDefault404)
th.AssertEquals(t, true, ok)
}
|