forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding.feature
120 lines (106 loc) · 4.02 KB
/
encoding.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@parallel=false
Feature: encoding tests
Scenario: special characters in the url
Given url demoBaseUrl + '/encoding/�Ill~Formed@RequiredString!'
When method get
Then status 200
And match response == '�Ill~Formed@RequiredString!'
Scenario: special characters in the path
Given url demoBaseUrl
And path 'encoding', '�Ill~Formed@RequiredString!'
When method get
Then status 200
And match response == '�Ill~Formed@RequiredString!'
Scenario: question mark in the url
Given url demoBaseUrl + '/encoding/index.php%3F/api/v2'
And path 'hello'
When method get
Then status 200
And match response == 'hello'
Scenario: append trailing / to url
Given url demoBaseUrl
And path 'encoding', 'hello', ''
When method get
Then status 200
And match response == 'hello/'
Scenario: path escapes special characters
Given url demoBaseUrl
And path 'encoding', '"<>#{}|\^[]`'
When method get
Then status 200
And match response == '"<>#{}|\^[]`'
Scenario: leading / in path is not required
Given url demoBaseUrl
And path 'encoding', 'hello'
When method get
Then status 200
And match response == 'hello'
Scenario: manually decode before using as the url
* def encoded = 'encoding%2Ffoo%2Bbar'
* def decoded = karate.urlDecode(encoded)
Given url demoBaseUrl + '/' + decoded
When method get
Then status 200
And match response == 'foo+bar'
Scenario: path but with forward-slashes
Given url demoBaseUrl + '/encoding'
And path '/hello/world/123/'
When method get
Then status 200
And match response == 'hello/world/123'
Scenario: german xml
Given url demoBaseUrl
And path 'echo'
And request <name>Müller</name>
And header Content-Type = 'application/xml; charset=utf-8'
When method post
Then status 200
And xml response = response
And match response == <name>Müller</name>
Scenario: french json
Given url demoBaseUrl
And path 'echo'
And request { givenName: 'oliàèôç' }
And header Content-Type = 'application/json; charset=utf-8'
When method post
Then status 200
And match response == { givenName: 'oliàèôç' }
Scenario: french json ISO-8859-1
Given url demoBaseUrl
And path 'echo'
And request { givenName: 'oliàèôç' }
And header Content-Type = 'application/json; charset=ISO-8859-1'
When method post
Then status 200
And match response == { givenName: '#string' }
* def contentType = karate.prevRequest.headers['Content-Type'][0]
* match contentType contains 'application/json'
* match contentType contains 'charset=ISO-8859-1'
Scenario: french & german form field
Given url demoBaseUrl
And path 'echo', 'message'
And form field text = 'oliàèôç Müller'
And header Content-Type = 'application/x-www-form-urlencoded'
When method post
Then status 200
And match response == 'oliàèôç Müller'
Scenario: french & german multipart
Given url demoBaseUrl
Given path 'files'
And multipart file myFile = { read: '../upload/karate-logo.jpg', filename: 'karate-logo.jpg', contentType: 'image/jpg' }
And multipart field message = 'oliàèôç Müller'
And header Content-Type = 'multipart/form-data; charset=utf-8'
When method post
Then status 200
And match response == { id: '#uuid', filename: 'karate-logo.jpg', message: 'oliàèôç Müller', contentType: 'image/jpg' }
Scenario: multipart but forcing the charset to NOT be sent
Given url demoBaseUrl
Given path 'files'
And multipart file myFile = { read: '../upload/karate-logo.jpg', filename: 'karate-logo.jpg', contentType: 'image/jpg' }
And multipart field message = 'oliàèôç Müller'
# this ensures that "charset" does NOT appear in the Content-Type header
# which is often required as some servers don't like it
And configure charset = null
When method post
Then status 200
And match response == { id: '#uuid', filename: 'karate-logo.jpg', message: 'oliàèôç Müller', contentType: 'image/jpg' }