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
|
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/ec2credentials"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
const userID = "2844b2a08be147a08ef58317d6471f1f"
const credentialID = "f741662395b249c9b8acdebf1722c5ae"
// ListOutput provides a single page of EC2Credential results.
const ListOutput = `
{
"credentials": [
{
"user_id": "2844b2a08be147a08ef58317d6471f1f",
"links": {
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae"
},
"tenant_id": "6238dee2fec940a6bf31e49e9faf995a",
"access": "f741662395b249c9b8acdebf1722c5ae",
"secret": "6a61eb0296034c89b49cc51dde9b40aa",
"trust_id": null
},
{
"user_id": "2844b2a08be147a08ef58317d6471f1f",
"links": {
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/ad6fc85fc2df49e6b5c23d5b5bdff980"
},
"tenant_id": "6238dee2fec940a6bf31e49e9faf995a",
"access": "ad6fc85fc2df49e6b5c23d5b5bdff980",
"secret": "eb233f680a204097ac329ebe8dba6d32",
"trust_id": null
}
],
"links": {
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2",
"previous": null,
"next": null
}
}
`
// GetOutput provides a Get result.
const GetOutput = `
{
"credential": {
"user_id": "2844b2a08be147a08ef58317d6471f1f",
"links": {
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae"
},
"tenant_id": "6238dee2fec940a6bf31e49e9faf995a",
"access": "f741662395b249c9b8acdebf1722c5ae",
"secret": "6a61eb0296034c89b49cc51dde9b40aa",
"trust_id": null
}
}
`
// CreateRequest provides the input to a Create request.
const CreateRequest = `
{
"tenant_id": "6238dee2fec940a6bf31e49e9faf995a"
}
`
const CreateResponse = `
{
"credential": {
"user_id": "2844b2a08be147a08ef58317d6471f1f",
"links": {
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae"
},
"tenant_id": "6238dee2fec940a6bf31e49e9faf995a",
"access": "f741662395b249c9b8acdebf1722c5ae",
"secret": "6a61eb0296034c89b49cc51dde9b40aa",
"trust_id": null
}
}
`
var EC2Credential = ec2credentials.Credential{
UserID: "2844b2a08be147a08ef58317d6471f1f",
TenantID: "6238dee2fec940a6bf31e49e9faf995a",
Access: "f741662395b249c9b8acdebf1722c5ae",
Secret: "6a61eb0296034c89b49cc51dde9b40aa",
TrustID: "",
Links: map[string]interface{}{
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae",
},
}
var SecondEC2Credential = ec2credentials.Credential{
UserID: "2844b2a08be147a08ef58317d6471f1f",
TenantID: "6238dee2fec940a6bf31e49e9faf995a",
Access: "ad6fc85fc2df49e6b5c23d5b5bdff980",
Secret: "eb233f680a204097ac329ebe8dba6d32",
TrustID: "",
Links: map[string]interface{}{
"self": "http://identity:5000/v3/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/ad6fc85fc2df49e6b5c23d5b5bdff980",
},
}
// ExpectedEC2CredentialsSlice is the slice of application credentials expected to be returned from ListOutput.
var ExpectedEC2CredentialsSlice = []ec2credentials.Credential{EC2Credential, SecondEC2Credential}
// HandleListEC2CredentialsSuccessfully creates an HTTP handler at `/users` on the
// test handler mux that responds with a list of two applicationcredentials.
func HandleListEC2CredentialsSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2", 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, ListOutput)
})
}
// HandleGetEC2CredentialSuccessfully creates an HTTP handler at `/users` on the
// test handler mux that responds with a single application credential.
func HandleGetEC2CredentialSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae", 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, GetOutput)
})
}
// HandleCreateEC2CredentialSuccessfully creates an HTTP handler at `/users` on the
// test handler mux that tests application credential creation.
func HandleCreateEC2CredentialSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, CreateRequest)
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, CreateResponse)
})
}
// HandleDeleteEC2CredentialSuccessfully creates an HTTP handler at `/users` on the
// test handler mux that tests application credential deletion.
func HandleDeleteEC2CredentialSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/users/2844b2a08be147a08ef58317d6471f1f/credentials/OS-EC2/f741662395b249c9b8acdebf1722c5ae", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
}
|