Skip to content

Commit 903bb3c

Browse files
committed
Add integration test for request body during redirections.
1 parent 53beece commit 903bb3c

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
curl --header 'Accept: text/plain' --location 'http://localhost:8000/follow-redirect'
2-
curl --data '' --header 'Accept: text/plain' --location 'http://localhost:8000/follow-redirect'
2+
curl --header 'Content-Type: text/plain' --header 'Accept: text/plain' --data 'Hello world!' --location 'http://localhost:8000/follow-redirect-from-post'
33
curl --header 'Accept: text/plain' --location 'http://localhost:8000/follow-redirect/relative/foo'
4-
curl --header 'Authorization: Basic Ym9iQGVtYWlsLmNvbTpzZWNyZXQ=' --location 'http://localhost:8000/follow-redirect-basic-auth'
5-
curl --location --user 'bob@email.com:secret' 'http://localhost:8000/follow-redirect-basic-auth'
6-
curl --header 'Authorization: Basic Ym9iQGVtYWlsLmNvbTpzZWNyZXQ=' --location 'http://localhost:8000/follow-redirect-basic-auth'
7-
curl --data '' --header 'Accept: text/plain' --location 'http://localhost:8000/follow-redirect-308'
4+
curl --header 'Authorization: Basic Ym9iQGVtYWlsLmNvbTpzZWNyZXQ=' --location 'http://localhost:8000/follow-redirect-basic-auth?change_host=true'
5+
curl --header 'Authorization: Basic Ym9iQGVtYWlsLmNvbTpzZWNyZXQ=' --location 'http://localhost:8000/follow-redirect-basic-auth?change_host=false'
6+
curl --location --user 'bob@email.com:secret' 'http://localhost:8000/follow-redirect-basic-auth?change_host=true'
7+
curl --location --user 'bob@email.com:secret' 'http://localhost:8000/follow-redirect-basic-auth?change_host=false'
8+
curl --header 'Authorization: Basic Ym9iQGVtYWlsLmNvbTpzZWNyZXQ=' --location 'http://localhost:8000/follow-redirect-basic-auth?change_host=true'
9+
curl --header 'Authorization: Basic Ym9iQGVtYWlsLmNvbTpzZWNyZXQ=' --location 'http://localhost:8000/follow-redirect-basic-auth?change_host=false'
10+
curl --header 'Content-Type: text/plain' --header 'Accept: text/plain' --data 'Hello world!' --location 'http://localhost:8000/follow-redirect-308'

integration/hurl/tests_ok/follow_redirect/follow_redirect.hurl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ url == "http://localhost:8000/followed-redirect"
1919
`Followed redirect!`
2020

2121

22-
# On 301, 302, 303, redirected request switch to GET.
23-
# Otherwise, method are untouched.
24-
POST http://localhost:8000/follow-redirect
22+
# On 301, 302, 303, redirected request switch to GET. Otherwise, method are untouched.
23+
# If method change through redirection, the body request is not transferred through redirections.
24+
POST http://localhost:8000/follow-redirect-from-post
25+
Content-Type: text/plain
2526
Accept: text/plain
27+
`Hello world!`
2628
HTTP 200
2729
[Asserts]
28-
redirects count == 2
29-
redirects nth 0 location == "http://localhost:8000/following-redirect"
30-
redirects nth 1 location == "http://localhost:8000/followed-redirect"
31-
url == "http://localhost:8000/followed-redirect"
30+
redirects count == 1
31+
redirects nth 0 location == "http://localhost:8000/followed-redirect-from-post"
32+
url == "http://localhost:8000/followed-redirect-from-post"
3233
`Followed redirect!`
3334

3435

@@ -118,8 +119,12 @@ header "Location" not exists
118119
`Followed redirect with Authorization header!`
119120

120121

122+
# With a 308 redirection, the method remains POST. In this case, the request body is
123+
# copy from redirection through redirection.
121124
POST http://localhost:8000/follow-redirect-308
125+
Content-Type: text/plain
122126
Accept: text/plain
127+
`Hello world!`
123128
HTTP 200
124129
[Asserts]
125130
redirects count == 1

integration/hurl/tests_ok/follow_redirect/follow_redirect.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@
22
from flask import Response, redirect, request
33

44

5-
@app.route("/follow-redirect", methods=["GET", "POST"])
5+
@app.route("/follow-redirect")
66
def follow_redirect():
77
assert request.headers["Accept"] == "text/plain"
88
return redirect("http://localhost:8000/following-redirect")
99

1010

11+
@app.route("/follow-redirect-from-post", methods=["POST"])
12+
def follow_redirect_from_post():
13+
assert request.headers["Accept"] == "text/plain"
14+
assert request.data.decode(encoding="utf-8") == "Hello world!"
15+
return redirect("http://localhost:8000/followed-redirect-from-post", code=301)
16+
17+
18+
@app.route("/followed-redirect-from-post")
19+
def followed_redirect_from_post():
20+
# A redirection with a method change POST -> GET should not carry the request body.
21+
assert request.data == b""
22+
assert request.headers["Accept"] == "text/plain"
23+
return "Followed redirect!"
24+
25+
1126
@app.route("/following-redirect")
1227
def following_redirect():
1328
# For this redirection, we construct the response instead of using
@@ -32,6 +47,7 @@ def followed_redirect():
3247
@app.route("/followed-redirect-post", methods=["POST"])
3348
def followed_redirect_post():
3449
assert request.headers["Accept"] == "text/plain"
50+
assert request.data.decode(encoding="utf-8") == "Hello world!"
3551
return "Followed redirect POST!"
3652

3753

integration/hurl/tests_ok/follow_redirect/follow_redirect_option.hurl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ header "Location" not exists
2727

2828
# On 301, 302, 303, redirected request switch to GET.
2929
# Otherwise, method are untouched.
30-
POST http://localhost:8000/follow-redirect
30+
POST http://localhost:8000/follow-redirect-from-post
3131
Accept: text/plain
3232
[Options]
3333
location: true
34+
`Hello world!`
3435
HTTP 200
3536
[Asserts]
3637
header "Location" not exists
@@ -41,6 +42,7 @@ POST http://localhost:8000/follow-redirect-308
4142
Accept: text/plain
4243
[Options]
4344
location: true
45+
`Hello world!`
4446
HTTP 200
4547
[Asserts]
4648
header "Location" not exists

0 commit comments

Comments
 (0)