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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
package testing
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/gophercloud/gophercloud/openstack/keymanager/v1/acls"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
const GetResponse = `
{
"read": {
"created": "2018-06-22T17:54:24",
"project-access": false,
"updated": "2018-06-22T17:54:24",
"users": [
"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW"
]
}
}`
const SetRequest = `
{
"read": {
"project-access": false,
"users": [
"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW"
]
}
}`
const SecretSetResponse = `
{
"acl_ref": "http://barbican:9311/v1/secrets/4befede0-fbde-4480-982c-b160c1014a47/acl"
}`
const ContainerSetResponse = `
{
"acl_ref": "http://barbican:9311/v1/containers/4befede0-fbde-4480-982c-b160c1014a47/acl"
}`
var ExpectedACL = acls.ACL{
"read": acls.ACLDetails{
Created: time.Date(2018, 6, 22, 17, 54, 24, 0, time.UTC),
ProjectAccess: false,
Updated: time.Date(2018, 6, 22, 17, 54, 24, 0, time.UTC),
Users: []string{
"GG27dVwR9gBMnsOaRoJ1DFJmZfdVjIdW",
},
},
}
var ExpectedSecretACLRef = acls.ACLRef("http://barbican:9311/v1/secrets/4befede0-fbde-4480-982c-b160c1014a47/acl")
var ExpectedContainerACLRef = acls.ACLRef("http://barbican:9311/v1/containers/4befede0-fbde-4480-982c-b160c1014a47/acl")
const UpdateRequest = `
{
"read": {
"users": []
}
}`
// HandleGetSecretACLSuccessfully creates an HTTP handler at `/secrets/uuid/acl`
// on the test handler mux that responds with an acl.
func HandleGetSecretACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, GetResponse)
})
}
// HandleGetContainerACLSuccessfully creates an HTTP handler at `/secrets/uuid/acl`
// on the test handler mux that responds with an acl.
func HandleGetContainerACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, GetResponse)
})
}
// HandleSetSecretACLSuccessfully creates an HTTP handler at `/secrets` on the
// test handler mux that tests secret creation.
func HandleSetSecretACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, SetRequest)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, SecretSetResponse)
})
}
// HandleSetContainerACLSuccessfully creates an HTTP handler at `/secrets` on the
// test handler mux that tests secret creation.
func HandleSetContainerACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, SetRequest)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, ContainerSetResponse)
})
}
// HandleUpdateSecretACLSuccessfully creates an HTTP handler at `/secrets` on the
// test handler mux that tests secret creation.
func HandleUpdateSecretACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PATCH")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, UpdateRequest)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, SecretSetResponse)
})
}
// HandleUpdateContainerACLSuccessfully creates an HTTP handler at `/secrets` on the
// test handler mux that tests secret creation.
func HandleUpdateContainerACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PATCH")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, UpdateRequest)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, ContainerSetResponse)
})
}
// HandleDeleteSecretACLSuccessfully creates an HTTP handler at `/secrets` on the
// test handler mux that tests secret deletion.
func HandleDeleteSecretACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusOK)
})
}
// HandleDeleteContainerACLSuccessfully creates an HTTP handler at `/secrets` on the
// test handler mux that tests secret deletion.
func HandleDeleteContainerACLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/containers/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c/acl", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusOK)
})
}
|