blob: c0dc62b29c5ae02970f854fd0232636c1af88715 [file] [log] [blame]
Jamie Hannaford17d2f872014-11-24 12:20:33 +01001package defsecrules
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12const rootPath = "/os-security-group-default-rules"
13
14func mockListRulesResponse(t *testing.T) {
15 th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
16 th.TestMethod(t, r, "GET")
17 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
18
19 w.Header().Add("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21
22 fmt.Fprintf(w, `
23{
24 "security_group_default_rules": [
25 {
26 "from_port": 80,
27 "id": "f9a97fcf-3a97-47b0-b76f-919136afb7ed",
28 "ip_protocol": "TCP",
29 "ip_range": {
30 "cidr": "10.10.10.0/24"
31 },
32 "to_port": 80
33 }
34 ]
35}
36 `)
37 })
38}
Jamie Hannaford43fa4a22014-11-24 12:49:17 +010039
40func mockCreateRuleResponse(t *testing.T) {
41 th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
42 th.TestMethod(t, r, "POST")
43 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
44
45 th.TestJSONRequest(t, r, `
46{
47 "security_group_default_rule": {
48 "ip_protocol": "TCP",
49 "from_port": 80,
50 "to_port": 80,
51 "cidr": "10.10.12.0/24"
52 }
53}
54 `)
55
56 w.Header().Add("Content-Type", "application/json")
57 w.WriteHeader(http.StatusOK)
58
59 fmt.Fprintf(w, `
60{
61 "security_group_default_rule": {
62 "from_port": 80,
63 "id": 1,
64 "ip_protocol": "TCP",
65 "ip_range": {
66 "cidr": "10.10.12.0/24"
67 },
68 "to_port": 80,
69 "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5"
70 }
71}
72`)
73 })
74}