Skip to content

Commit 646f42c

Browse files
author
cortlyons
committed
api_shield v4->v5 migration
1 parent d56cac5 commit 646f42c

File tree

10 files changed

+2264
-0
lines changed

10 files changed

+2264
-0
lines changed

integration/v4_to_v5/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
// Explicitly import the migrations we want to test
1010
_ "github.com/cloudflare/tf-migrate/internal/resources/account_member"
11+
_ "github.com/cloudflare/tf-migrate/internal/resources/api_shield"
1112
_ "github.com/cloudflare/tf-migrate/internal/resources/api_token"
1213
_ "github.com/cloudflare/tf-migrate/internal/resources/custom_pages"
1314
_ "github.com/cloudflare/tf-migrate/internal/resources/dns_record"
Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
locals {
2+
name_prefix = "cftftest"
3+
}
4+
5+
variable "cloudflare_account_id" {
6+
description = "Cloudflare account ID"
7+
type = string
8+
}
9+
10+
variable "cloudflare_zone_id" {
11+
description = "Cloudflare zone ID"
12+
type = string
13+
}
14+
15+
variable "cloudflare_domain" {
16+
description = "Cloudflare domain for testing"
17+
type = string
18+
}
19+
20+
# Test Case 1: Single header characteristic
21+
resource "cloudflare_api_shield" "single_header" {
22+
zone_id = var.cloudflare_zone_id
23+
24+
auth_id_characteristics = [
25+
{
26+
type = "header"
27+
name = "authorization"
28+
}
29+
]
30+
}
31+
32+
# Test Case 2: Single cookie characteristic
33+
resource "cloudflare_api_shield" "single_cookie" {
34+
zone_id = var.cloudflare_zone_id
35+
36+
auth_id_characteristics = [
37+
{
38+
type = "cookie"
39+
name = "session_id"
40+
}
41+
]
42+
}
43+
44+
# Test Case 3: Multiple header characteristics
45+
resource "cloudflare_api_shield" "multiple_headers" {
46+
zone_id = var.cloudflare_zone_id
47+
48+
49+
50+
auth_id_characteristics = [
51+
{
52+
type = "header"
53+
name = "authorization"
54+
},
55+
{
56+
type = "header"
57+
name = "x-api-key"
58+
},
59+
{
60+
type = "header"
61+
name = "x-client-id"
62+
}
63+
]
64+
}
65+
66+
# Test Case 4: Multiple cookie characteristics
67+
resource "cloudflare_api_shield" "multiple_cookies" {
68+
zone_id = var.cloudflare_zone_id
69+
70+
71+
72+
auth_id_characteristics = [
73+
{
74+
type = "cookie"
75+
name = "session_id"
76+
},
77+
{
78+
type = "cookie"
79+
name = "user_token"
80+
},
81+
{
82+
type = "cookie"
83+
name = "auth_token"
84+
}
85+
]
86+
}
87+
88+
# Test Case 5: Mixed header and cookie characteristics
89+
resource "cloudflare_api_shield" "mixed_types" {
90+
zone_id = var.cloudflare_zone_id
91+
92+
93+
94+
95+
auth_id_characteristics = [
96+
{
97+
type = "header"
98+
name = "authorization"
99+
},
100+
{
101+
type = "cookie"
102+
name = "session_id"
103+
},
104+
{
105+
type = "header"
106+
name = "x-api-key"
107+
},
108+
{
109+
type = "cookie"
110+
name = "user_token"
111+
}
112+
]
113+
}
114+
115+
# Test Case 6: Header with common name
116+
resource "cloudflare_api_shield" "common_header_1" {
117+
zone_id = var.cloudflare_zone_id
118+
119+
auth_id_characteristics = [
120+
{
121+
type = "header"
122+
name = "X-Auth-Token"
123+
}
124+
]
125+
}
126+
127+
# Test Case 7: Cookie with common name
128+
resource "cloudflare_api_shield" "common_cookie_1" {
129+
zone_id = var.cloudflare_zone_id
130+
131+
auth_id_characteristics = [
132+
{
133+
type = "cookie"
134+
name = "JSESSIONID"
135+
}
136+
]
137+
}
138+
139+
# Test Case 8: Multiple characteristics with varied order
140+
resource "cloudflare_api_shield" "varied_order" {
141+
zone_id = var.cloudflare_zone_id
142+
143+
144+
145+
146+
auth_id_characteristics = [
147+
{
148+
type = "cookie"
149+
name = "auth_cookie"
150+
},
151+
{
152+
type = "header"
153+
name = "Authorization"
154+
},
155+
{
156+
type = "cookie"
157+
name = "session"
158+
},
159+
{
160+
type = "header"
161+
name = "X-Forwarded-For"
162+
}
163+
]
164+
}
165+
166+
# Test Case 9: Header with lowercase name
167+
resource "cloudflare_api_shield" "lowercase_header" {
168+
zone_id = var.cloudflare_zone_id
169+
170+
auth_id_characteristics = [
171+
{
172+
type = "header"
173+
name = "content-type"
174+
}
175+
]
176+
}
177+
178+
# Test Case 10: Cookie with uppercase name
179+
resource "cloudflare_api_shield" "uppercase_cookie" {
180+
zone_id = var.cloudflare_zone_id
181+
182+
auth_id_characteristics = [
183+
{
184+
type = "cookie"
185+
name = "SESSIONID"
186+
}
187+
]
188+
}
189+
190+
# Test Case 11: Multiple headers with hyphens
191+
resource "cloudflare_api_shield" "hyphenated_headers" {
192+
zone_id = var.cloudflare_zone_id
193+
194+
195+
196+
auth_id_characteristics = [
197+
{
198+
type = "header"
199+
name = "x-api-key"
200+
},
201+
{
202+
type = "header"
203+
name = "x-client-id"
204+
},
205+
{
206+
type = "header"
207+
name = "x-request-id"
208+
}
209+
]
210+
}
211+
212+
# Test Case 12: Multiple cookies with underscores
213+
resource "cloudflare_api_shield" "underscore_cookies" {
214+
zone_id = var.cloudflare_zone_id
215+
216+
217+
218+
auth_id_characteristics = [
219+
{
220+
type = "cookie"
221+
name = "user_id"
222+
},
223+
{
224+
type = "cookie"
225+
name = "session_token"
226+
},
227+
{
228+
type = "cookie"
229+
name = "csrf_token"
230+
}
231+
]
232+
}
233+
234+
# Test Case 13: Single characteristic with capitalized type
235+
resource "cloudflare_api_shield" "basic_auth" {
236+
zone_id = var.cloudflare_zone_id
237+
238+
auth_id_characteristics = [
239+
{
240+
type = "header"
241+
name = "Authorization"
242+
}
243+
]
244+
}
245+
246+
# Test Case 14: Cookie for session management
247+
resource "cloudflare_api_shield" "session_management" {
248+
zone_id = var.cloudflare_zone_id
249+
250+
auth_id_characteristics = [
251+
{
252+
type = "cookie"
253+
name = "session_key"
254+
}
255+
]
256+
}
257+
258+
# Test Case 15: Multiple characteristics for OAuth
259+
resource "cloudflare_api_shield" "oauth_flow" {
260+
zone_id = var.cloudflare_zone_id
261+
262+
263+
264+
auth_id_characteristics = [
265+
{
266+
type = "header"
267+
name = "Authorization"
268+
},
269+
{
270+
type = "header"
271+
name = "X-OAuth-Token"
272+
},
273+
{
274+
type = "cookie"
275+
name = "oauth_state"
276+
}
277+
]
278+
}
279+
280+
# Test Case 16: JWT authentication headers
281+
resource "cloudflare_api_shield" "jwt_auth" {
282+
zone_id = var.cloudflare_zone_id
283+
284+
285+
auth_id_characteristics = [
286+
{
287+
type = "header"
288+
name = "Authorization"
289+
},
290+
{
291+
type = "header"
292+
name = "X-JWT-Token"
293+
}
294+
]
295+
}
296+
297+
# Test Case 17: API key authentication
298+
resource "cloudflare_api_shield" "api_key_auth" {
299+
zone_id = var.cloudflare_zone_id
300+
301+
302+
auth_id_characteristics = [
303+
{
304+
type = "header"
305+
name = "X-API-Key"
306+
},
307+
{
308+
type = "header"
309+
name = "X-API-Secret"
310+
}
311+
]
312+
}
313+
314+
# Test Case 18: Bearer token authentication
315+
resource "cloudflare_api_shield" "bearer_auth" {
316+
zone_id = var.cloudflare_zone_id
317+
318+
auth_id_characteristics = [
319+
{
320+
type = "header"
321+
name = "Authorization"
322+
}
323+
]
324+
}
325+
326+
# Test Case 19: Custom authentication scheme
327+
resource "cloudflare_api_shield" "custom_auth" {
328+
zone_id = var.cloudflare_zone_id
329+
330+
331+
332+
auth_id_characteristics = [
333+
{
334+
type = "header"
335+
name = "X-Custom-Auth"
336+
},
337+
{
338+
type = "cookie"
339+
name = "custom_session"
340+
},
341+
{
342+
type = "header"
343+
name = "X-Custom-Token"
344+
}
345+
]
346+
}
347+
348+
# Test Case 20: Multi-factor authentication
349+
resource "cloudflare_api_shield" "mfa_auth" {
350+
zone_id = var.cloudflare_zone_id
351+
352+
353+
354+
auth_id_characteristics = [
355+
{
356+
type = "header"
357+
name = "Authorization"
358+
},
359+
{
360+
type = "header"
361+
name = "X-MFA-Token"
362+
},
363+
{
364+
type = "cookie"
365+
name = "mfa_session"
366+
}
367+
]
368+
}

0 commit comments

Comments
 (0)