blob: 4aa7530d02c21cdc97b3bb1173d4af03a7df76ac [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,
Jamie Hannaford8031b732014-11-24 12:55:41 +010027 "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
Jamie Hannaford17d2f872014-11-24 12:20:33 +010028 "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}
Jamie Hannaford8031b732014-11-24 12:55:41 +010075
76func mockGetRuleResponse(t *testing.T, ruleID string) {
77 url := rootPath + "/" + ruleID
78 th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
79 th.TestMethod(t, r, "GET")
80 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
81
82 w.Header().Add("Content-Type", "application/json")
83 w.WriteHeader(http.StatusOK)
84
85 fmt.Fprintf(w, `
86{
87 "security_group_default_rule": {
88 "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5",
89 "from_port": 80,
90 "to_port": 80,
91 "ip_protocol": "TCP",
92 "ip_range": {
93 "cidr": "10.10.12.0/24"
94 }
95 }
96}
97 `)
98 })
99}
Jamie Hannaford20e92912014-11-24 13:01:45 +0100100
101func mockDeleteRuleResponse(t *testing.T, ruleID string) {
102 url := rootPath + "/" + ruleID
103 th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
104 th.TestMethod(t, r, "DELETE")
105 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
106 w.Header().Add("Content-Type", "application/json")
107 w.WriteHeader(http.StatusAccepted)
108 })
109}