@@ -18,58 +18,74 @@ defmodule ExAws.Request.UrlTest do
18
18
{ :ok , % { query: query , config: config } }
19
19
end
20
20
21
- test "it build urls for query operation" , % { query: query , config: config } do
22
- assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
23
- end
21
+ describe "build" do
22
+ test "it build urls for query operation" , % { query: query , config: config } do
23
+ assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
24
+ end
24
25
25
- test "it allows setting custom port" , % { query: query , config: config } do
26
- config = config |> Map . put ( :port , 4430 )
27
- assert Url . build ( query , config ) == "https://example.com:4430/path?foo=bar"
28
- end
26
+ test "it allows setting custom port" , % { query: query , config: config } do
27
+ config = config |> Map . put ( :port , 4430 )
28
+ assert Url . build ( query , config ) == "https://example.com:4430/path?foo=bar"
29
+ end
29
30
30
- test "it converts the port to an integer if it is a string" , % { query: query , config: config } do
31
- config = config |> Map . put ( :port , "4430" )
32
- assert Url . build ( query , config ) == "https://example.com:4430/path?foo=bar"
33
- end
31
+ test "it converts the port to an integer if it is a string" , % { query: query , config: config } do
32
+ config = config |> Map . put ( :port , "4430" )
33
+ assert Url . build ( query , config ) == "https://example.com:4430/path?foo=bar"
34
+ end
34
35
35
- test "it allows passing scheme with trailing ://" , % { query: query , config: config } do
36
- config = config |> Map . put ( :scheme , "https://" )
37
- assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
38
- end
36
+ test "it allows passing scheme with trailing ://" , % { query: query , config: config } do
37
+ config = config |> Map . put ( :scheme , "https://" )
38
+ assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
39
+ end
39
40
40
- test "it accepts params as a list of keywords" , % { query: query , config: config } do
41
- query = query |> Map . put ( :params , foo: :bar )
42
- assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
43
- end
41
+ test "it accepts params as a list of keywords" , % { query: query , config: config } do
42
+ query = query |> Map . put ( :params , foo: :bar )
43
+ assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
44
+ end
44
45
45
- test "it does not have trailing ? when params is an empty map" , % { query: query , config: config } do
46
- query = query |> Map . put ( :params , % { } )
47
- assert Url . build ( query , config ) == "https://example.com/path"
48
- end
46
+ test "it does not have trailing ? when params is an empty map" , % {
47
+ query: query ,
48
+ config: config
49
+ } do
50
+ query = query |> Map . put ( :params , % { } )
51
+ assert Url . build ( query , config ) == "https://example.com/path"
52
+ end
49
53
50
- test "it does not have trailing ? when params is an empty list" , % { query: query , config: config } do
51
- query = query |> Map . put ( :params , [ ] )
52
- assert Url . build ( query , config ) == "https://example.com/path"
53
- end
54
+ test "it does not have trailing ? when params is an empty list" , % {
55
+ query: query ,
56
+ config: config
57
+ } do
58
+ query = query |> Map . put ( :params , [ ] )
59
+ assert Url . build ( query , config ) == "https://example.com/path"
60
+ end
54
61
55
- test "it accepts query without params key" , % { query: query , config: config } do
56
- query = query |> Map . delete ( :params )
57
- assert Url . build ( query , config ) == "https://example.com/path"
58
- end
62
+ test "it accepts query without params key" , % { query: query , config: config } do
63
+ query = query |> Map . delete ( :params )
64
+ assert Url . build ( query , config ) == "https://example.com/path"
65
+ end
59
66
60
- test "it cleans up excessive slashes in the path" , % { query: query , config: config } do
61
- query = query |> Map . put ( :path , "//path///with/too/many//slashes//" )
62
- assert Url . build ( query , config ) == "https://example.com/path/with/too/many/slashes/?foo=bar"
63
- end
67
+ test "it cleans up excessive slashes in the path" , % { query: query , config: config } do
68
+ query = query |> Map . put ( :path , "//path///with/too/many//slashes//" )
69
+ assert Url . build ( query , config ) == "https://example.com/path/with/too/many/slashes/?foo=bar"
70
+ end
64
71
65
- test "it ignores empty parameter key" , % { query: query , config: config } do
66
- query = query |> Map . put ( :params , % { "foo" => "bar" , "" => 1 } )
67
- assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
68
- end
72
+ test "it ignores empty parameter key" , % { query: query , config: config } do
73
+ query = query |> Map . put ( :params , % { "foo" => "bar" , "" => 1 } )
74
+ assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
75
+ end
69
76
70
- test "it ignores nil parameter key" , % { query: query , config: config } do
71
- query = query |> Map . put ( :params , % { "foo" => "bar" , nil => 1 } )
72
- assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
77
+ test "it ignores nil parameter key" , % { query: query , config: config } do
78
+ query = query |> Map . put ( :params , % { "foo" => "bar" , nil => 1 } )
79
+ assert Url . build ( query , config ) == "https://example.com/path?foo=bar"
80
+ end
81
+
82
+ test "it URI encodes spaces, + and unicode characters in query parameters" , % {
83
+ query: query ,
84
+ config: config
85
+ } do
86
+ query = query |> Map . put ( :params , % { "foo" => "put: it+й" } )
87
+ assert Url . build ( query , config ) == "https://example.com/path?foo=put%3A+it%2B%D0%B9"
88
+ end
73
89
end
74
90
75
91
describe "get_path" do
@@ -83,4 +99,23 @@ defmodule ExAws.Request.UrlTest do
83
99
assert Url . get_path ( url ) == "/uploads/invalid path but+valid//for"
84
100
end
85
101
end
102
+
103
+ describe "sanitize" do
104
+ test "it URI encodes spaces, + and unicode characters in the path" do
105
+ url = "s3://my-bucket/uploads/a key with ++"
106
+ assert Url . sanitize ( url , :s3 ) == "s3://my-bucket/uploads/a%20key%20with%20%2B%2B"
107
+ end
108
+
109
+ test "it URI encodes unicode characters in the path" do
110
+ url = "s3://my-bucket/uploads/a key with й"
111
+ assert Url . sanitize ( url , :s3 ) == "s3://my-bucket/uploads/a%20key%20with%20%D0%B9"
112
+ end
113
+
114
+ test "it doesn't re-encode query parameters" do
115
+ url = "s3://my-bucket/uploads/a key with й?foo=put%3A+it%2B%D0%B9"
116
+
117
+ assert Url . sanitize ( url , :s3 ) ==
118
+ "s3://my-bucket/uploads/a%20key%20with%20%D0%B9?foo=put%3A%20it%2B%D0%B9"
119
+ end
120
+ end
86
121
end
0 commit comments