blob: d10af99d0eb93605be5ef76bcda2a4d3b6fe33bc [file] [log] [blame]
Ash Wilsonad612f62014-10-22 14:04:37 -04001// +build fixtures
Ash Wilson0b61c252014-10-22 17:50:20 -04002
Ash Wilsonad612f62014-10-22 14:04:37 -04003package keypairs
4
5import (
6 "fmt"
7 "net/http"
8 "testing"
9
10 th "github.com/rackspace/gophercloud/testhelper"
11 "github.com/rackspace/gophercloud/testhelper/client"
12)
13
14// ListOutput is a sample response to a List call.
15const ListOutput = `
16{
17 "keypairs": [
18 {
19 "keypair": {
20 "fingerprint": "15:b0:f8:b3:f9:48:63:71:cf:7b:5b:38:6d:44:2d:4a",
21 "name": "firstkey",
22 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC+Eo/RZRngaGTkFs7I62ZjsIlO79KklKbMXi8F+KITD4bVQHHn+kV+4gRgkgCRbdoDqoGfpaDFs877DYX9n4z6FrAIZ4PES8TNKhatifpn9NdQYWA+IkU8CuvlEKGuFpKRi/k7JLos/gHi2hy7QUwgtRvcefvD/vgQZOVw/mGR9Q== Generated by Nova\n"
23 }
24 },
25 {
26 "keypair": {
27 "fingerprint": "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
28 "name": "secondkey",
29 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n"
30 }
31 }
32 ]
33}
34`
35
36// GetOutput is a sample response to a Get call.
37const GetOutput = `
38{
39 "keypair": {
Ash Wilson4aaaa1e2014-10-22 14:38:02 -040040 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC+Eo/RZRngaGTkFs7I62ZjsIlO79KklKbMXi8F+KITD4bVQHHn+kV+4gRgkgCRbdoDqoGfpaDFs877DYX9n4z6FrAIZ4PES8TNKhatifpn9NdQYWA+IkU8CuvlEKGuFpKRi/k7JLos/gHi2hy7QUwgtRvcefvD/vgQZOVw/mGR9Q== Generated by Nova\n",
Ash Wilsonad612f62014-10-22 14:04:37 -040041 "name": "firstkey",
Ash Wilson4aaaa1e2014-10-22 14:38:02 -040042 "fingerprint": "15:b0:f8:b3:f9:48:63:71:cf:7b:5b:38:6d:44:2d:4a"
Ash Wilsonad612f62014-10-22 14:04:37 -040043 }
44}
45`
46
47// CreateOutput is a sample response to a Create call.
48const CreateOutput = `
49{
50 "keypair": {
51 "fingerprint": "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
52 "name": "createdkey",
53 "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7\nDUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ\n9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5QIDAQAB\nAoGAE5XO1mDhORy9COvsg+kYPUhB1GsCYxh+v88wG7HeFDKBY6KUc/Kxo6yoGn5T\nTjRjekyi2KoDZHz4VlIzyZPwFS4I1bf3oCunVoAKzgLdmnTtvRNMC5jFOGc2vUgP\n9bSyRj3S1R4ClVk2g0IDeagko/jc8zzLEYuIK+fbkds79YECQQDt3vcevgegnkga\ntF4NsDmmBPRkcSHCqrANP/7vFcBQN3czxeYYWX3DK07alu6GhH1Y4sHbdm616uU0\nll7xbDzxAkEAzAtN2IyftNygV2EGiaGgqLyo/tD9+Vui2qCQplqe4jvWh/5Sparl\nOjmKo+uAW+hLrLVMnHzRWxbWU8hirH5FNQJATO+ZxCK4etXXAnQmG41NCAqANWB2\nB+2HJbH2NcQ2QHvAHUm741JGn/KI/aBlo7KEjFRDWUVUB5ji64BbUwCsMQJBAIku\nLGcjnBf/oLk+XSPZC2eGd2Ph5G5qYmH0Q2vkTx+wtTn3DV+eNsDfgMtWAJVJ5t61\ngU1QSXyhLPVlKpnnxuUCQC+xvvWjWtsLaFtAsZywJiqLxQzHts8XLGZptYJ5tLWV\nrtmYtBcJCN48RrgQHry/xWYeA4K/AFQpXfNPgprQ96Q=\n-----END RSA PRIVATE KEY-----\n",
54 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n",
55 "user_id": "fake"
56 }
57}
58`
59
60// ImportOutput is a sample response to a Create call that provides its own public key.
61const ImportOutput = `
62{
63 "keypair": {
64 "fingerprint": "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
Ash Wilsonbae65cd2014-10-22 15:02:14 -040065 "name": "importedkey",
Ash Wilsonad612f62014-10-22 14:04:37 -040066 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova",
67 "user_id": "fake"
68 }
69}
70`
71
72// FirstKeyPair is the first result in ListOutput.
73var FirstKeyPair = KeyPair{
74 Name: "firstkey",
75 Fingerprint: "15:b0:f8:b3:f9:48:63:71:cf:7b:5b:38:6d:44:2d:4a",
76 PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC+Eo/RZRngaGTkFs7I62ZjsIlO79KklKbMXi8F+KITD4bVQHHn+kV+4gRgkgCRbdoDqoGfpaDFs877DYX9n4z6FrAIZ4PES8TNKhatifpn9NdQYWA+IkU8CuvlEKGuFpKRi/k7JLos/gHi2hy7QUwgtRvcefvD/vgQZOVw/mGR9Q== Generated by Nova\n",
77}
78
79// SecondKeyPair is the second result in ListOutput.
80var SecondKeyPair = KeyPair{
81 Name: "secondkey",
82 Fingerprint: "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
83 PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n",
84}
85
86// ExpectedKeyPairSlice is the slice of results that should be parsed from ListOutput, in the expected
87// order.
88var ExpectedKeyPairSlice = []KeyPair{FirstKeyPair, SecondKeyPair}
89
90// CreatedKeyPair is the parsed result from CreatedOutput.
91var CreatedKeyPair = KeyPair{
92 Name: "createdkey",
93 Fingerprint: "35:9d:d0:c3:4a:80:d3:d8:86:f1:ca:f7:df:c4:f9:d8",
94 PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7DUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5Q== Generated by Nova\n",
95 PrivateKey: "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQC9mC3WZN9UGLxgPBpP7H5jZMc6pKwOoSgre8yun6REFktn/Kz7\nDUt9jaR1UJyRzHxITfCfAIgSxPdGqB/oF1suMyWgu5i0625vavLB5z5kC8Hq3qZJ\n9zJO1poE1kyD+htiTtPWJ88e12xuH2XB/CZN9OpEiF98hAagiOE0EnOS5QIDAQAB\nAoGAE5XO1mDhORy9COvsg+kYPUhB1GsCYxh+v88wG7HeFDKBY6KUc/Kxo6yoGn5T\nTjRjekyi2KoDZHz4VlIzyZPwFS4I1bf3oCunVoAKzgLdmnTtvRNMC5jFOGc2vUgP\n9bSyRj3S1R4ClVk2g0IDeagko/jc8zzLEYuIK+fbkds79YECQQDt3vcevgegnkga\ntF4NsDmmBPRkcSHCqrANP/7vFcBQN3czxeYYWX3DK07alu6GhH1Y4sHbdm616uU0\nll7xbDzxAkEAzAtN2IyftNygV2EGiaGgqLyo/tD9+Vui2qCQplqe4jvWh/5Sparl\nOjmKo+uAW+hLrLVMnHzRWxbWU8hirH5FNQJATO+ZxCK4etXXAnQmG41NCAqANWB2\nB+2HJbH2NcQ2QHvAHUm741JGn/KI/aBlo7KEjFRDWUVUB5ji64BbUwCsMQJBAIku\nLGcjnBf/oLk+XSPZC2eGd2Ph5G5qYmH0Q2vkTx+wtTn3DV+eNsDfgMtWAJVJ5t61\ngU1QSXyhLPVlKpnnxuUCQC+xvvWjWtsLaFtAsZywJiqLxQzHts8XLGZptYJ5tLWV\nrtmYtBcJCN48RrgQHry/xWYeA4K/AFQpXfNPgprQ96Q=\n-----END RSA PRIVATE KEY-----\n",
96 UserID: "fake",
97}
98
99// ImportedKeyPair is the parsed result from ImportOutput.
100var ImportedKeyPair = KeyPair{
101 Name: "importedkey",
102 Fingerprint: "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
103 PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova",
104 UserID: "fake",
105}
106
107// HandleListSuccessfully configures the test server to respond to a List request.
108func HandleListSuccessfully(t *testing.T) {
109 th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
110 th.TestMethod(t, r, "GET")
111 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
112
113 w.Header().Add("Content-Type", "application/json")
114 fmt.Fprintf(w, ListOutput)
115 })
116}
117
118// HandleGetSuccessfully configures the test server to respond to a Get request for "firstkey".
119func HandleGetSuccessfully(t *testing.T) {
120 th.Mux.HandleFunc("/os-keypairs/firstkey", func(w http.ResponseWriter, r *http.Request) {
121 th.TestMethod(t, r, "GET")
122 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
123
124 w.Header().Add("Content-Type", "application/json")
125 fmt.Fprintf(w, GetOutput)
126 })
127}
128
129// HandleCreateSuccessfully configures the test server to respond to a Create request for a new
130// keypair called "createdkey".
131func HandleCreateSuccessfully(t *testing.T) {
132 th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
133 th.TestMethod(t, r, "POST")
134 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
Ash Wilson10fede72014-10-22 14:58:52 -0400135 th.TestJSONRequest(t, r, `{ "keypair": { "name": "createdkey" } }`)
Ash Wilsonad612f62014-10-22 14:04:37 -0400136
137 w.Header().Add("Content-Type", "application/json")
138 fmt.Fprintf(w, CreateOutput)
139 })
140}
141
142// HandleImportSuccessfully configures the test server to respond to an Import request for an
143// existing keypair called "importedkey".
144func HandleImportSuccessfully(t *testing.T) {
145 th.Mux.HandleFunc("/os-keypairs", func(w http.ResponseWriter, r *http.Request) {
146 th.TestMethod(t, r, "POST")
147 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
148 th.TestJSONRequest(t, r, `
149 {
150 "keypair": {
151 "name": "importedkey",
152 "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova"
153 }
154 }
155 `)
156
157 w.Header().Add("Content-Type", "application/json")
158 fmt.Fprintf(w, ImportOutput)
159 })
160}
161
162// HandleDeleteSuccessfully configures the test server to respond to a Delete request for a
163// keypair called "deletedkey".
164func HandleDeleteSuccessfully(t *testing.T) {
165 th.Mux.HandleFunc("/os-keypairs/deletedkey", func(w http.ResponseWriter, r *http.Request) {
166 th.TestMethod(t, r, "DELETE")
167 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
168
169 w.WriteHeader(http.StatusAccepted)
170 })
171}