github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/roles/testing/fixtures_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/identity/v3/roles"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    11  )
    12  
    13  // ListOutput provides a single page of Role results.
    14  const ListOutput = `
    15  {
    16      "links": {
    17          "next": null,
    18          "previous": null,
    19          "self": "http://example.com/identity/v3/roles"
    20      },
    21      "roles": [
    22          {
    23              "domain_id": "default",
    24              "id": "2844b2a08be147a08ef58317d6471f1f",
    25              "links": {
    26                  "self": "http://example.com/identity/v3/roles/2844b2a08be147a08ef58317d6471f1f"
    27              },
    28              "name": "admin-read-only"
    29          },
    30          {
    31              "domain_id": "1789d1",
    32              "id": "9fe1d3",
    33              "links": {
    34                  "self": "https://example.com/identity/v3/roles/9fe1d3"
    35              },
    36              "name": "support",
    37              "extra": {
    38                  "description": "read-only support role"
    39              }
    40          }
    41      ]
    42  }
    43  `
    44  
    45  // GetOutput provides a Get result.
    46  const GetOutput = `
    47  {
    48      "role": {
    49          "domain_id": "1789d1",
    50          "id": "9fe1d3",
    51          "links": {
    52              "self": "https://example.com/identity/v3/roles/9fe1d3"
    53          },
    54          "name": "support",
    55          "extra": {
    56              "description": "read-only support role"
    57          }
    58      }
    59  }
    60  `
    61  
    62  // CreateRequest provides the input to a Create request.
    63  const CreateRequest = `
    64  {
    65      "role": {
    66          "domain_id": "1789d1",
    67          "name": "support",
    68          "description": "read-only support role"
    69      }
    70  }
    71  `
    72  
    73  // UpdateRequest provides the input to as Update request.
    74  const UpdateRequest = `
    75  {
    76      "role": {
    77          "description": "admin read-only support role"
    78      }
    79  }
    80  `
    81  
    82  // UpdateOutput provides an update result.
    83  const UpdateOutput = `
    84  {
    85      "role": {
    86          "domain_id": "1789d1",
    87          "id": "9fe1d3",
    88          "links": {
    89              "self": "https://example.com/identity/v3/roles/9fe1d3"
    90          },
    91          "name": "support",
    92          "extra": {
    93              "description": "admin read-only support role"
    94          }
    95      }
    96  }
    97  `
    98  
    99  // ListAssignmentOutput provides a result of ListAssignment request.
   100  const ListAssignmentOutput = `
   101  {
   102      "role_assignments": [
   103          {
   104              "links": {
   105                  "assignment": "http://identity:35357/v3/domains/161718/users/313233/roles/123456"
   106              },
   107              "role": {
   108                  "id": "123456"
   109              },
   110              "scope": {
   111                  "domain": {
   112                      "id": "161718"
   113                  }
   114              },
   115              "user": {
   116                  "domain": {
   117                    "id": "161718"
   118                  },
   119                  "id": "313233"
   120              }
   121          },
   122          {
   123              "links": {
   124                  "assignment": "http://identity:35357/v3/projects/456789/groups/101112/roles/123456",
   125                  "membership": "http://identity:35357/v3/groups/101112/users/313233"
   126              },
   127              "role": {
   128                  "id": "123456"
   129              },
   130              "scope": {
   131                  "project": {
   132                      "domain": {
   133                        "id": "161718"
   134                      },
   135                      "id": "456789"
   136                  }
   137              },
   138              "user": {
   139                  "domain": {
   140                    "id": "161718"
   141                  },
   142                  "id": "313233"
   143              }
   144          }
   145      ],
   146      "links": {
   147          "self": "http://identity:35357/v3/role_assignments?effective",
   148          "previous": null,
   149          "next": null
   150      }
   151  }
   152  `
   153  
   154  // ListAssignmentWithNamesOutput provides a result of ListAssignment request with IncludeNames option.
   155  const ListAssignmentWithNamesOutput = `
   156  {
   157      "role_assignments": [
   158          {
   159              "links": {
   160                  "assignment": "http://identity:35357/v3/domains/161718/users/313233/roles/123456"
   161              },
   162              "role": {
   163                  "id": "123456",
   164                  "name": "include_names_role"
   165              },
   166              "scope": {
   167                  "domain": {
   168                      "id": "161718",
   169                      "name": "52833"
   170                  }
   171              },
   172              "user": {
   173                  "domain": {
   174                      "id": "161718",
   175                      "name": "52833"
   176                  },
   177                  "id": "313233",
   178                  "name": "example-user-name"
   179              }
   180          }
   181      ],
   182      "links": {
   183          "self": "http://identity:35357/v3/role_assignments?include_names=True",
   184          "previous": null,
   185          "next": null
   186      }
   187  }
   188  `
   189  
   190  // ListAssignmentsOnResourceOutput provides a result of ListAssignmentsOnResource request.
   191  const ListAssignmentsOnResourceOutput = `
   192  {
   193      "links": {
   194          "next": null,
   195          "previous": null,
   196          "self": "http://example.com/identity/v3/projects/9e5a15/users/b964a9/roles"
   197      },
   198      "roles": [
   199          {
   200              "id": "9fe1d3",
   201              "links": {
   202                  "self": "https://example.com/identity/v3/roles/9fe1d3"
   203              },
   204              "name": "support",
   205              "extra": {
   206                  "description": "read-only support role"
   207              }
   208          }
   209      ]
   210  }
   211  `
   212  
   213  const CreateRoleInferenceRuleOutput = `
   214  {
   215      "role_inference": {
   216          "prior_role": {
   217              "id": "7ceab6192ea34a548cc71b24f72e762c",
   218              "links": {
   219                  "self": "http://example.com/identity/v3/roles/7ceab6192ea34a548cc71b24f72e762c"
   220              },
   221              "name": "prior role name"
   222          },
   223          "implies": {
   224              "id": "97e2f5d38bc94842bc3da818c16762ed",
   225              "links": {
   226                  "self": "http://example.com/identity/v3/roles/97e2f5d38bc94842bc3da818c16762ed"
   227              },
   228              "name": "implied role name"
   229          }
   230      },
   231      "links": {
   232          "self": "http://example.com/identity/v3/roles/7ceab6192ea34a548cc71b24f72e762c/implies/97e2f5d38bc94842bc3da818c16762ed"
   233      }
   234  }
   235  `
   236  
   237  const ListRoleInferenceRulesOutput = `
   238  {
   239      "role_inferences": [
   240          {
   241              "prior_role": {
   242                  "id": "1acd3c5aa0e246b9a7427d252160dcd1",
   243                  "links": {
   244                      "self": "http://example.com/identity/v3/roles/1acd3c5aa0e246b9a7427d252160dcd1"
   245                  },
   246                  "description": "My new role",
   247                  "name": "prior role name"
   248              },
   249              "implies": [
   250                  {
   251                      "id": "3602510e2e1f499589f78a0724dcf614",
   252                      "links": {
   253                          "self": "http://example.com/identity/v3/roles/3602510e2e1f499589f78a0724dcf614"
   254                      },
   255                      "description": "My new role",
   256                      "name": "implied role1 name"
   257                  },
   258                  {
   259                      "id": "738289aeef684e73a987f7cf2ec6d925",
   260                      "links": {
   261                          "self": "http://example.com/identity/v3/roles/738289aeef684e73a987f7cf2ec6d925"
   262                      },
   263                      "description": "My new role",
   264                      "name": "implied role2 name"
   265                  }
   266              ]
   267          },
   268          {
   269              "prior_role": {
   270                  "id": "bbf7a5098bb34407b7164eb6ff9f144e",
   271                  "links": {
   272                      "self" : "http://example.com/identity/v3/roles/bbf7a5098bb34407b7164eb6ff9f144e"
   273                  },
   274                  "description": "My new role",
   275                  "name": "prior role name"
   276              },
   277              "implies": [
   278                  {
   279                      "id": "872b20ad124c4c1bafaef2b1aae316ab",
   280                      "links": {
   281                          "self": "http://example.com/identity/v3/roles/872b20ad124c4c1bafaef2b1aae316ab"
   282                      },
   283                      "description": null,
   284                      "name": "implied role1 name"
   285                  },
   286                  {
   287                      "id": "1d865b1b2da14cb7b05254677e5f36a2",
   288                      "links": {
   289                          "self": "http://example.com/identity/v3/roles/1d865b1b2da14cb7b05254677e5f36a2"
   290                      },
   291                      "description": null,
   292                      "name": "implied role2 name"
   293                  }
   294              ]
   295          }
   296      ],
   297      "links": {
   298          "self": "http://example.com/identity/v3/role_inferences"
   299      }
   300  }
   301  `
   302  
   303  // FirstRole is the first role in the List request.
   304  var FirstRole = roles.Role{
   305  	DomainID: "default",
   306  	ID:       "2844b2a08be147a08ef58317d6471f1f",
   307  	Links: map[string]any{
   308  		"self": "http://example.com/identity/v3/roles/2844b2a08be147a08ef58317d6471f1f",
   309  	},
   310  	Name:  "admin-read-only",
   311  	Extra: map[string]any{},
   312  }
   313  
   314  // SecondRole is the second role in the List request.
   315  var SecondRole = roles.Role{
   316  	DomainID: "1789d1",
   317  	ID:       "9fe1d3",
   318  	Links: map[string]any{
   319  		"self": "https://example.com/identity/v3/roles/9fe1d3",
   320  	},
   321  	Name: "support",
   322  	Extra: map[string]any{
   323  		"description": "read-only support role",
   324  	},
   325  }
   326  
   327  // SecondRoleUpdated is how SecondRole should look after an Update.
   328  var SecondRoleUpdated = roles.Role{
   329  	DomainID: "1789d1",
   330  	ID:       "9fe1d3",
   331  	Links: map[string]any{
   332  		"self": "https://example.com/identity/v3/roles/9fe1d3",
   333  	},
   334  	Name: "support",
   335  	Extra: map[string]any{
   336  		"description": "admin read-only support role",
   337  	},
   338  }
   339  
   340  // ExpectedRolesSlice is the slice of roles expected to be returned from ListOutput.
   341  var ExpectedRolesSlice = []roles.Role{FirstRole, SecondRole}
   342  
   343  // HandleListRolesSuccessfully creates an HTTP handler at `/roles` on the
   344  // test handler mux that responds with a list of two roles.
   345  func HandleListRolesSuccessfully(t *testing.T) {
   346  	th.Mux.HandleFunc("/roles", func(w http.ResponseWriter, r *http.Request) {
   347  		th.TestMethod(t, r, "GET")
   348  		th.TestHeader(t, r, "Accept", "application/json")
   349  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   350  
   351  		w.Header().Set("Content-Type", "application/json")
   352  		w.WriteHeader(http.StatusOK)
   353  		fmt.Fprint(w, ListOutput)
   354  	})
   355  }
   356  
   357  // HandleGetRoleSuccessfully creates an HTTP handler at `/roles` on the
   358  // test handler mux that responds with a single role.
   359  func HandleGetRoleSuccessfully(t *testing.T) {
   360  	th.Mux.HandleFunc("/roles/9fe1d3", func(w http.ResponseWriter, r *http.Request) {
   361  		th.TestMethod(t, r, "GET")
   362  		th.TestHeader(t, r, "Accept", "application/json")
   363  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   364  
   365  		w.Header().Set("Content-Type", "application/json")
   366  		w.WriteHeader(http.StatusOK)
   367  		fmt.Fprint(w, GetOutput)
   368  	})
   369  }
   370  
   371  // HandleCreateRoleSuccessfully creates an HTTP handler at `/roles` on the
   372  // test handler mux that tests role creation.
   373  func HandleCreateRoleSuccessfully(t *testing.T) {
   374  	th.Mux.HandleFunc("/roles", func(w http.ResponseWriter, r *http.Request) {
   375  		th.TestMethod(t, r, "POST")
   376  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   377  		th.TestJSONRequest(t, r, CreateRequest)
   378  
   379  		w.WriteHeader(http.StatusCreated)
   380  		fmt.Fprint(w, GetOutput)
   381  	})
   382  }
   383  
   384  // HandleUpdateRoleSuccessfully creates an HTTP handler at `/roles` on the
   385  // test handler mux that tests role update.
   386  func HandleUpdateRoleSuccessfully(t *testing.T) {
   387  	th.Mux.HandleFunc("/roles/9fe1d3", func(w http.ResponseWriter, r *http.Request) {
   388  		th.TestMethod(t, r, "PATCH")
   389  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   390  		th.TestJSONRequest(t, r, UpdateRequest)
   391  
   392  		w.WriteHeader(http.StatusOK)
   393  		fmt.Fprint(w, UpdateOutput)
   394  	})
   395  }
   396  
   397  // HandleDeleteRoleSuccessfully creates an HTTP handler at `/roles` on the
   398  // test handler mux that tests role deletion.
   399  func HandleDeleteRoleSuccessfully(t *testing.T) {
   400  	th.Mux.HandleFunc("/roles/9fe1d3", func(w http.ResponseWriter, r *http.Request) {
   401  		th.TestMethod(t, r, "DELETE")
   402  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   403  
   404  		w.WriteHeader(http.StatusNoContent)
   405  	})
   406  }
   407  
   408  func HandleAssignSuccessfully(t *testing.T) {
   409  	th.Mux.HandleFunc("/projects/{project_id}/users/{user_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   410  		th.TestMethod(t, r, "PUT")
   411  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   412  		w.WriteHeader(http.StatusNoContent)
   413  	})
   414  
   415  	th.Mux.HandleFunc("/projects/{project_id}/groups/{group_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   416  		th.TestMethod(t, r, "PUT")
   417  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   418  		w.WriteHeader(http.StatusNoContent)
   419  	})
   420  
   421  	th.Mux.HandleFunc("/domains/{domain_id}/users/{user_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   422  		th.TestMethod(t, r, "PUT")
   423  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   424  		w.WriteHeader(http.StatusNoContent)
   425  	})
   426  
   427  	th.Mux.HandleFunc("/domains/{domain_id}/groups/{group_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   428  		th.TestMethod(t, r, "PUT")
   429  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   430  		w.WriteHeader(http.StatusNoContent)
   431  	})
   432  }
   433  
   434  func HandleUnassignSuccessfully(t *testing.T) {
   435  	th.Mux.HandleFunc("/projects/{project_id}/users/{user_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   436  		th.TestMethod(t, r, "DELETE")
   437  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   438  		w.WriteHeader(http.StatusNoContent)
   439  	})
   440  
   441  	th.Mux.HandleFunc("/projects/{project_id}/groups/{group_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   442  		th.TestMethod(t, r, "DELETE")
   443  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   444  		w.WriteHeader(http.StatusNoContent)
   445  	})
   446  
   447  	th.Mux.HandleFunc("/domains/{domain_id}/users/{user_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   448  		th.TestMethod(t, r, "DELETE")
   449  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   450  		w.WriteHeader(http.StatusNoContent)
   451  	})
   452  
   453  	th.Mux.HandleFunc("/domains/{domain_id}/groups/{group_id}/roles/{role_id}", func(w http.ResponseWriter, r *http.Request) {
   454  		th.TestMethod(t, r, "DELETE")
   455  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   456  		w.WriteHeader(http.StatusNoContent)
   457  	})
   458  }
   459  
   460  // FirstRoleAssignment is the first role assignment in the List request.
   461  var FirstRoleAssignment = roles.RoleAssignment{
   462  	Role:  roles.AssignedRole{ID: "123456"},
   463  	Scope: roles.Scope{Domain: roles.Domain{ID: "161718"}},
   464  	User:  roles.User{Domain: roles.Domain{ID: "161718"}, ID: "313233"},
   465  	Group: roles.Group{},
   466  }
   467  
   468  // SecondRoleAssignemnt is the second role assignemnt in the List request.
   469  var SecondRoleAssignment = roles.RoleAssignment{
   470  	Role:  roles.AssignedRole{ID: "123456"},
   471  	Scope: roles.Scope{Project: roles.Project{Domain: roles.Domain{ID: "161718"}, ID: "456789"}},
   472  	User:  roles.User{Domain: roles.Domain{ID: "161718"}, ID: "313233"},
   473  	Group: roles.Group{},
   474  }
   475  
   476  // ThirdRoleAssignment is the third role assignment that has entity names in the List request.
   477  var ThirdRoleAssignment = roles.RoleAssignment{
   478  	Role:  roles.AssignedRole{ID: "123456", Name: "include_names_role"},
   479  	Scope: roles.Scope{Domain: roles.Domain{ID: "161718", Name: "52833"}},
   480  	User:  roles.User{Domain: roles.Domain{ID: "161718", Name: "52833"}, ID: "313233", Name: "example-user-name"},
   481  	Group: roles.Group{},
   482  }
   483  
   484  // ExpectedRoleAssignmentsSlice is the slice of role assignments expected to be
   485  // returned from ListAssignmentOutput.
   486  var ExpectedRoleAssignmentsSlice = []roles.RoleAssignment{FirstRoleAssignment, SecondRoleAssignment}
   487  
   488  // ExpectedRoleAssignmentsWithNamesSlice is the slice of role assignments expected to be
   489  // returned from ListAssignmentWithNamesOutput.
   490  var ExpectedRoleAssignmentsWithNamesSlice = []roles.RoleAssignment{ThirdRoleAssignment}
   491  
   492  // HandleListRoleAssignmentsSuccessfully creates an HTTP handler at `/role_assignments` on the
   493  // test handler mux that responds with a list of two role assignments.
   494  func HandleListRoleAssignmentsSuccessfully(t *testing.T) {
   495  	th.Mux.HandleFunc("/role_assignments", func(w http.ResponseWriter, r *http.Request) {
   496  		th.TestMethod(t, r, "GET")
   497  		th.TestHeader(t, r, "Accept", "application/json")
   498  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   499  
   500  		w.Header().Set("Content-Type", "application/json")
   501  		w.WriteHeader(http.StatusOK)
   502  		fmt.Fprint(w, ListAssignmentOutput)
   503  	})
   504  }
   505  
   506  // HandleListRoleAssignmentsSuccessfully creates an HTTP handler at `/role_assignments` on the
   507  // test handler mux that responds with a list of two role assignments.
   508  func HandleListRoleAssignmentsWithNamesSuccessfully(t *testing.T) {
   509  	th.Mux.HandleFunc("/role_assignments", func(w http.ResponseWriter, r *http.Request) {
   510  		th.TestMethod(t, r, "GET")
   511  		th.TestHeader(t, r, "Accept", "application/json")
   512  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   513  		th.AssertEquals(t, "include_names=true", r.URL.RawQuery)
   514  
   515  		w.Header().Set("Content-Type", "application/json")
   516  		w.WriteHeader(http.StatusOK)
   517  		fmt.Fprint(w, ListAssignmentWithNamesOutput)
   518  	})
   519  }
   520  
   521  // HandleListRoleAssignmentsWithSubtreeSuccessfully creates an HTTP handler at `/role_assignments` on the
   522  // test handler mux that responds with a list of two role assignments.
   523  func HandleListRoleAssignmentsWithSubtreeSuccessfully(t *testing.T) {
   524  	th.Mux.HandleFunc("/role_assignments", func(w http.ResponseWriter, r *http.Request) {
   525  		th.TestMethod(t, r, "GET")
   526  		th.TestHeader(t, r, "Accept", "application/json")
   527  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   528  		th.AssertEquals(t, "include_subtree=true", r.URL.RawQuery)
   529  
   530  		w.Header().Set("Content-Type", "application/json")
   531  		w.WriteHeader(http.StatusOK)
   532  		fmt.Fprint(w, ListAssignmentOutput)
   533  	})
   534  }
   535  
   536  // RoleOnResource is the role in the ListAssignmentsOnResource request.
   537  var RoleOnResource = roles.Role{
   538  	ID: "9fe1d3",
   539  	Links: map[string]any{
   540  		"self": "https://example.com/identity/v3/roles/9fe1d3",
   541  	},
   542  	Name: "support",
   543  	Extra: map[string]any{
   544  		"description": "read-only support role",
   545  	},
   546  }
   547  
   548  // ExpectedRolesOnResourceSlice is the slice of roles expected to be returned
   549  // from ListAssignmentsOnResourceOutput.
   550  var ExpectedRolesOnResourceSlice = []roles.Role{RoleOnResource}
   551  
   552  func HandleListAssignmentsOnResourceSuccessfully_ProjectsUsers(t *testing.T) {
   553  	fn := func(w http.ResponseWriter, r *http.Request) {
   554  		th.TestMethod(t, r, "GET")
   555  		th.TestHeader(t, r, "Accept", "application/json")
   556  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   557  
   558  		w.Header().Set("Content-Type", "application/json")
   559  		w.WriteHeader(http.StatusOK)
   560  		fmt.Fprint(w, ListAssignmentsOnResourceOutput)
   561  	}
   562  
   563  	th.Mux.HandleFunc("/projects/{project_id}/users/{user_id}/roles", fn)
   564  }
   565  
   566  func HandleListAssignmentsOnResourceSuccessfully_ProjectsGroups(t *testing.T) {
   567  	fn := func(w http.ResponseWriter, r *http.Request) {
   568  		th.TestMethod(t, r, "GET")
   569  		th.TestHeader(t, r, "Accept", "application/json")
   570  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   571  
   572  		w.Header().Set("Content-Type", "application/json")
   573  		w.WriteHeader(http.StatusOK)
   574  		fmt.Fprint(w, ListAssignmentsOnResourceOutput)
   575  	}
   576  
   577  	th.Mux.HandleFunc("/projects/{project_id}/groups/{group_id}/roles", fn)
   578  }
   579  
   580  func HandleListAssignmentsOnResourceSuccessfully_DomainsUsers(t *testing.T) {
   581  	fn := func(w http.ResponseWriter, r *http.Request) {
   582  		th.TestMethod(t, r, "GET")
   583  		th.TestHeader(t, r, "Accept", "application/json")
   584  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   585  
   586  		w.Header().Set("Content-Type", "application/json")
   587  		w.WriteHeader(http.StatusOK)
   588  		fmt.Fprint(w, ListAssignmentsOnResourceOutput)
   589  	}
   590  
   591  	th.Mux.HandleFunc("/domains/{domain_id}/users/{user_id}/roles", fn)
   592  }
   593  
   594  func HandleListAssignmentsOnResourceSuccessfully_DomainsGroups(t *testing.T) {
   595  	fn := func(w http.ResponseWriter, r *http.Request) {
   596  		th.TestMethod(t, r, "GET")
   597  		th.TestHeader(t, r, "Accept", "application/json")
   598  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   599  
   600  		w.Header().Set("Content-Type", "application/json")
   601  		w.WriteHeader(http.StatusOK)
   602  		fmt.Fprint(w, ListAssignmentsOnResourceOutput)
   603  	}
   604  
   605  	th.Mux.HandleFunc("/domains/{domain_id}/groups/{group_id}/roles", fn)
   606  }
   607  
   608  var expectedRoleInferenceRule = roles.RoleInferenceRule{
   609  	RoleInference: roles.RoleInference{
   610  		PriorRole: roles.PriorRole{
   611  			ID: "7ceab6192ea34a548cc71b24f72e762c",
   612  			Links: map[string]any{
   613  				"self": "http://example.com/identity/v3/roles/7ceab6192ea34a548cc71b24f72e762c",
   614  			},
   615  			Name: "prior role name",
   616  		},
   617  		ImpliedRole: roles.ImpliedRole{
   618  			ID: "97e2f5d38bc94842bc3da818c16762ed",
   619  			Links: map[string]any{
   620  				"self": "http://example.com/identity/v3/roles/97e2f5d38bc94842bc3da818c16762ed",
   621  			},
   622  			Name: "implied role name",
   623  		},
   624  	},
   625  	Links: map[string]any{
   626  		"self": "http://example.com/identity/v3/roles/7ceab6192ea34a548cc71b24f72e762c/implies/97e2f5d38bc94842bc3da818c16762ed",
   627  	},
   628  }
   629  
   630  func HandleCreateRoleInferenceRule(t *testing.T) {
   631  	fn := func(w http.ResponseWriter, r *http.Request) {
   632  		th.TestMethod(t, r, "PUT")
   633  		th.TestHeader(t, r, "Accept", "application/json")
   634  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   635  
   636  		w.Header().Set("Content-Type", "application/json")
   637  		w.WriteHeader(http.StatusCreated)
   638  		fmt.Fprint(w, CreateRoleInferenceRuleOutput)
   639  	}
   640  
   641  	th.Mux.HandleFunc("/roles/7ceab6192ea34a548cc71b24f72e762c/implies/97e2f5d38bc94842bc3da818c16762ed", fn)
   642  }
   643  
   644  var expectedRoleInferenceRuleList = roles.RoleInferenceRuleList{
   645  	RoleInferenceRuleList: []roles.RoleInferenceRules{
   646  		{
   647  			PriorRole: roles.PriorRoleObject{
   648  				ID: "1acd3c5aa0e246b9a7427d252160dcd1",
   649  				Links: map[string]any{
   650  					"self": "http://example.com/identity/v3/roles/1acd3c5aa0e246b9a7427d252160dcd1",
   651  				},
   652  				Name:        "prior role name",
   653  				Description: "My new role",
   654  			},
   655  			ImpliedRoles: []roles.ImpliedRoleObject{
   656  				{
   657  					ID: "3602510e2e1f499589f78a0724dcf614",
   658  					Links: map[string]any{
   659  						"self": "http://example.com/identity/v3/roles/3602510e2e1f499589f78a0724dcf614",
   660  					},
   661  					Name:        "implied role1 name",
   662  					Description: "My new role",
   663  				},
   664  				{
   665  					ID: "738289aeef684e73a987f7cf2ec6d925",
   666  					Links: map[string]any{
   667  						"self": "http://example.com/identity/v3/roles/738289aeef684e73a987f7cf2ec6d925",
   668  					},
   669  					Name:        "implied role2 name",
   670  					Description: "My new role",
   671  				},
   672  			},
   673  		},
   674  		{
   675  			PriorRole: roles.PriorRoleObject{
   676  				ID: "bbf7a5098bb34407b7164eb6ff9f144e",
   677  				Links: map[string]any{
   678  					"self": "http://example.com/identity/v3/roles/bbf7a5098bb34407b7164eb6ff9f144e",
   679  				},
   680  				Name:        "prior role name",
   681  				Description: "My new role",
   682  			},
   683  			ImpliedRoles: []roles.ImpliedRoleObject{
   684  				{
   685  					ID: "872b20ad124c4c1bafaef2b1aae316ab",
   686  					Links: map[string]any{
   687  						"self": "http://example.com/identity/v3/roles/872b20ad124c4c1bafaef2b1aae316ab",
   688  					},
   689  					Name:        "implied role1 name",
   690  					Description: "",
   691  				},
   692  				{
   693  					ID: "1d865b1b2da14cb7b05254677e5f36a2",
   694  					Links: map[string]any{
   695  						"self": "http://example.com/identity/v3/roles/1d865b1b2da14cb7b05254677e5f36a2",
   696  					},
   697  					Name:        "implied role2 name",
   698  					Description: "",
   699  				},
   700  			},
   701  		},
   702  	},
   703  	Links: map[string]any{
   704  		"self": "http://example.com/identity/v3/role_inferences",
   705  	},
   706  }
   707  
   708  func HandleListRoleInferenceRules(t *testing.T) {
   709  	fn := func(w http.ResponseWriter, r *http.Request) {
   710  		th.TestMethod(t, r, "GET")
   711  		th.TestHeader(t, r, "Accept", "application/json")
   712  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   713  
   714  		w.Header().Set("Content-Type", "application/json")
   715  		w.WriteHeader(http.StatusOK)
   716  		fmt.Fprint(w, ListRoleInferenceRulesOutput)
   717  	}
   718  
   719  	th.Mux.HandleFunc("/role_inferences", fn)
   720  }
   721  
   722  func HandleDeleteRoleInferenceRule(t *testing.T) {
   723  	fn := func(w http.ResponseWriter, r *http.Request) {
   724  		th.TestMethod(t, r, "DELETE")
   725  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   726  
   727  		w.WriteHeader(http.StatusNoContent)
   728  	}
   729  	th.Mux.HandleFunc("/roles/7ceab6192ea34a548cc71b24f72e762c/implies/97e2f5d38bc94842bc3da818c16762ed", fn)
   730  }
   731  
   732  func HandleGetRoleInferenceRule(t *testing.T) {
   733  	fn := func(w http.ResponseWriter, r *http.Request) {
   734  		th.TestMethod(t, r, "GET")
   735  		th.TestHeader(t, r, "Accept", "application/json")
   736  		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
   737  
   738  		w.Header().Set("Content-Type", "application/json")
   739  		w.WriteHeader(http.StatusOK)
   740  		fmt.Fprint(w, CreateRoleInferenceRuleOutput)
   741  	}
   742  
   743  	th.Mux.HandleFunc("/roles/7ceab6192ea34a548cc71b24f72e762c/implies/97e2f5d38bc94842bc3da818c16762ed", fn)
   744  }