Skip to content

Commit e55da56

Browse files
authored
Update for Hurl 7.0.0 (#103)
1 parent 0604b93 commit e55da56

31 files changed

+1017
-17358
lines changed

sites/build_rss.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
44
Examples:
55
$ python3 build_rss.py hurl.dev/_posts/2023-06-30-announcing-hurl-4.0.0.md
6+
7+
Note: reference links that contains backtick, like `[`location`]: {% link _docs/filters.md %}#location` are
8+
not well-supported and should be inlined.
69
"""
10+
711
from _datetime import datetime
812
import re
913
import sys

sites/generate/get_artifacts_hash.py

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#!/usr/bin/env/python3
1+
#!/usr/bin/env python3
22
"""Create SHASUM from GitHub release artifacts for a given version
33
44
Example:
55
$ python3 get_artifacts_hash.py 1.7.0
66
77
"""
8+
89
import argparse
910
import hashlib
1011
import json

sites/hurl.dev/_data/docs.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@
7979
- title: Testing Bytes Content
8080
- title: SSL Certificate
8181
- title: Checking Full Body
82+
- title: Testing Redirections
83+
- title: Debug Tips
84+
items:
85+
- title: Verbose Mode
86+
- title: Error Format
87+
- title: Output Response Body
88+
- title: Export curl Commands
89+
- title: Using Proxy
8290
- title: Reports
8391
items:
8492
- title: HTML Report
@@ -208,6 +216,7 @@
208216
- title: SHA-256 capture
209217
- title: MD5 capture
210218
- title: URL capture
219+
- title: Redirects capture
211220
- title: IP address capture
212221
- title: Variable capture
213222
- title: Duration capture
@@ -246,6 +255,7 @@
246255
- title: SHA-256 assert
247256
- title: MD5 assert
248257
- title: URL assert
258+
- title: URL redirect
249259
- title: IP address assert
250260
- title: Variable assert
251261
- title: Duration assert
@@ -259,24 +269,31 @@
259269
items:
260270
- title: base64Decode
261271
- title: base64Encode
272+
- title: base64UrlSafeDecode
273+
- title: base64UrlSafeEncode
262274
- title: count
263275
- title: daysAfterNow
264276
- title: daysBeforeNow
265277
- title: decode
278+
- title: first
266279
- title: format
267280
- title: htmlEscape
268281
- title: htmlUnescape
269282
- title: jsonpath
283+
- title: last
284+
- title: location
270285
- title: nth
271286
- title: regex
272287
- title: replace
288+
- title: replaceRegex
273289
- title: split
274290
- title: toDate
275291
- title: toFloat
276292
- title: toInt
277293
- title: toString
278294
- title: urlDecode
279295
- title: urlEncode
296+
- title: urlQueryParam
280297
- title: xpath
281298
- title: Templates
282299
path: /docs/templates.html
@@ -338,7 +355,6 @@
338355
- title: Debugging a specific entry
339356
- title: Use Error Format
340357
- title: Get Response Body
341-
- title: Interactive Mode
342358
- title: Include Headers Like curl
343359
- title: Export curl Commands
344360
- title: Using a Proxy

sites/hurl.dev/_docs/asserting-response.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ The asserts order in a Hurl file is:
9292
</div>
9393
</div>
9494

95-
9695
## Implicit asserts
9796

9897
### Version - Status
@@ -383,6 +382,7 @@ can extract data from
383382
- [`md5`](#md5-assert)
384383
- others:
385384
- [`url`](#url-assert)
385+
- [`redirects`](#redirects-assert)
386386
- [`ip`](#ip-address-assert)
387387
- [`variable`](#variable-assert)
388388
- [`duration`](#duration-assert)
@@ -399,14 +399,14 @@ Predicates consist of a predicate function and a predicate value. Predicate func
399399
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
400400
| __`==`__ | Query and predicate value are equal | `jsonpath "$.book" == "Dune"` |
401401
| __`!=`__ | Query and predicate value are different | `jsonpath "$.color" != "red"` |
402-
| __`>`__ | Query number is greater than predicate value | `jsonpath "$.year" > 1978` |
403-
| __`>=`__ | Query number is greater than or equal to the predicate value | `jsonpath "$.year" >= 1978` |
404-
| __`<`__ | Query number is less than that predicate value | `jsonpath "$.year" < 1978` |
405-
| __`<=`__ | Query number is less than or equal to the predicate value | `jsonpath "$.year" <= 1978` |
402+
| __{% raw %}`>`__ | Query number or date is greater than predicate value | `jsonpath "$.year" > 1978`<br><br>`jsonpath "$.createdAt" toDate "%+" > {{ a_date }}`{% endraw %} |
403+
| __`>=`__ | Query number or date is greater than or equal to the predicate value | `jsonpath "$.year" >= 1978` |
404+
| __`<`__ | Query number or date is less than that predicate value | `jsonpath "$.year" < 1978` |
405+
| __`<=`__ | Query number or date is less than or equal to the predicate value | `jsonpath "$.year" <= 1978` |
406406
| __`startsWith`__ | Query starts with the predicate value<br>Value is string or a binary content | `jsonpath "$.movie" startsWith "The"`<br><br>`bytes startsWith hex,efbbbf;` |
407407
| __`endsWith`__ | Query ends with the predicate value<br>Value is string or a binary content | `jsonpath "$.movie" endsWith "Back"`<br><br>`bytes endsWith hex,ab23456;` |
408408
| __`contains`__ | If query returns a collection of string or numbers, query collection includes the predicate value (string or number)<br>If query returns a string or a binary content, query contains the predicate value (string or bytes) | `jsonpath "$.movie" contains "Empire"`<br><br>`bytes contains hex,beef;`<br><br>`jsonpath "$.numbers" contains 42` |
409-
| __`matches`__ | Part of the query string matches the regex pattern described by the predicate value | `jsonpath "$.release" matches "\\d{4}"`<br><br>`jsonpath "$.release" matches /\d{4}/` |
409+
| __`matches`__ | Part of the query string matches the regex pattern described by the predicate value (see [regex syntax](https://docs.rs/regex/latest/regex/#syntax)) | `jsonpath "$.release" matches "\\d{4}"`<br><br>`jsonpath "$.release" matches /\d{4}/` |
410410
| __`exists`__ | Query returns a value | `jsonpath "$.book" exists` |
411411
| __`isBoolean`__ | Query returns a boolean | `jsonpath "$.succeeded" isBoolean` |
412412
| __`isCollection`__ | Query returns a collection | `jsonpath "$.books" isCollection` |
@@ -418,10 +418,7 @@ Predicates consist of a predicate function and a predicate value. Predicate func
418418
| __`isString`__ | Query returns a string | `jsonpath "$.name" isString` |
419419
| __`isIpv4`__ | Query returns an IPv4 address | `ip isIpv4` |
420420
| __`isIpv6`__ | Query returns an IPv6 address | `ip isIpv6` |
421-
422-
Query contains the predicate value if query returns a collection of string or numbers<br>
423-
Query
424-
421+
| __`isUuid`__ | Query returns a UUID | `ip isUuid` |
425422

426423

427424
Each predicate can be negated by prefixing it with `not` (for instance, `not contains` or `not exists`)
@@ -843,6 +840,16 @@ captured group value. When the regex pattern is a double-quoted string, metachar
843840
pattern (like `\d`, `\s`) must be escaped; literal pattern enclosed by `/` can also be used to avoid metacharacters
844841
escaping.
845842

843+
The regex syntax is documented at <https://docs.rs/regex/latest/regex/#syntax>. For instance, once can use [flags](https://docs.rs/regex/latest/regex/#grouping-and-flags)
844+
to enable case-insensitive match:
845+
846+
```hurl
847+
GET https://example.org/hello
848+
HTTP 200
849+
[Asserts]
850+
regex /(?i)hello (\w+)!/ == "World"
851+
```
852+
846853
### SHA-256 assert
847854

848855
Check response body [SHA-256] hash.
@@ -902,6 +909,24 @@ HTTP 200
902909
url == "https://example.org/redirected"
903910
```
904911

912+
### Redirects assert
913+
914+
Check each step of redirection. This is most meaningful if you have told Hurl to follow redirection (see [`[Options]`section][options] or
915+
[`--location` option]). Redirects assert consists of the keyword `redirects` followed by a predicate function and value. The `redirects`
916+
query returns a collection of redirections that can be tested with a [`location` filter]:
917+
918+
```hurl
919+
GET https://example.org/redirecting/1
920+
[Options]
921+
location: true
922+
HTTP 200
923+
[Asserts]
924+
redirects count == 3
925+
redirects nth 0 location == "https://example.org/redirecting/2"
926+
redirects nth 1 location == "https://example.org/redirecting/3"
927+
redirects nth 2 location == "https://example.org/redirected"
928+
```
929+
905930
### IP address assert
906931

907932
Check the IP address of the last connection. The value of the `ip` query is a string.
@@ -985,3 +1010,4 @@ certificate "Serial-Number" matches "[0-9af]+"
9851010
[`Content-Encoding` HTTP header]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
9861011
[`Content-Type` header]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
9871012
[`body` assert]: #body-assert
1013+
[`location` filter]: {% link _docs/filters.md %}#location

sites/hurl.dev/_docs/capturing-response.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ A query can extract data from
7171
- [`md5`](#md5-capture)
7272
- others:
7373
- [`url`](#url-capture)
74+
- [`redirects`](#redirects-capture)
7475
- [`ip`](#ip-address-capture)
7576
- [`variable`](#variable-capture)
7677
- [`duration`](#duration-capture)
@@ -299,7 +300,17 @@ name: regex "Hello ([a-zA-Z]+)"
299300

300301
The regex pattern must have at least one capture group, otherwise the
301302
capture will fail. When the pattern is a double-quoted string, metacharacters beginning with a backslash in the pattern
302-
(like `\d`, `\s`) must be escaped; literal pattern enclosed by `/` can also be used to avoid metacharacters escaping.
303+
(like `\d`, `\s`) must be escaped; literal pattern enclosed by `/` can also be used to avoid metacharacters escaping.
304+
305+
The regex syntax is documented at <https://docs.rs/regex/latest/regex/#syntax>. For instance, one can use [flags](https://docs.rs/regex/latest/regex/#grouping-and-flags)
306+
to enable case-insensitive match:
307+
308+
```hurl
309+
GET https://example.org/hello
310+
HTTP 200
311+
[Captures]
312+
word: regex /(?i)hello (\w+)!/
313+
```
303314

304315
### SHA-256 capture
305316

@@ -343,6 +354,25 @@ HTTP 200
343354
landing_url: url
344355
```
345356

357+
### Redirects capture
358+
359+
Capture each step of redirection. This is most meaningful if you have told Hurl to follow redirection (see [`[Options]`section][options] or
360+
[`--location` option]). Redirects capture consists of a variable name, followed by a `:`, and the keyword `redirects`.
361+
Redirects query returns a collection so each step of the redirection can be capture.
362+
363+
```hurl
364+
GET https://example.org/redirecting/1
365+
[Options]
366+
location: true
367+
HTTP 200
368+
[Asserts]
369+
redirects count == 3
370+
[Captures]
371+
step1: redirects nth 0 location
372+
step2: redirects nth 1 location
373+
step3: redirects nth 2 location
374+
```
375+
346376
### IP address capture
347377

348378
Capture the IP address of the last connection. The value of the `ip` query is a string.

sites/hurl.dev/_docs/entry.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ of the redirection, allowing insertion of asserts in each response.
8686

8787
```hurl
8888
# First entry, test the redirection (status code and 'Location' header)
89-
GET https://google.fr
89+
GET https://example.org
9090
HTTP 301
91-
Location: https://www.google.fr/
91+
Location: https://www.example.org
9292
9393
# Second entry, the 200 OK response
94-
GET https://www.google.fr
94+
GET https://www.example.org
9595
HTTP 200
9696
```
9797

@@ -100,21 +100,66 @@ to be followed. In this case, asserts are executed on the last received response
100100
redirections can be limited with [`--max-redirs`].
101101

102102
```hurl
103-
# Running hurl --location google.hurl
104-
GET https://google.fr
103+
# Running hurl --location foo.hurl
104+
GET https://example.org
105105
HTTP 200
106106
```
107107

108-
Finally, you can force redirection on a particular request with an [`[Options]` section][options] and the[`--location`]
108+
Finally, you can force redirection on a particular request with an [`[Options]` section][options] and the [`--location`]
109109
/ [`--location-trusted`] options:
110110

111111
```hurl
112-
GET https://google.fr
112+
GET https://example.org
113113
[Options]
114114
location-trusted: true
115115
HTTP 200
116116
```
117117

118+
Redirections can be tested either by:
119+
120+
- running and asserting each step of redirection:
121+
122+
```hurl
123+
GET https://example.org/step1
124+
HTTP 301
125+
[Asserts]
126+
header "Location" == "https://example.org/step2"
127+
128+
129+
GET https://example.org/step2
130+
HTTP 301
131+
[Asserts]
132+
header "Location" == "https://example.org/step3"
133+
134+
135+
GET https://example.org/step3
136+
HTTP 200
137+
```
138+
139+
- using [`--location`] / [`--location-trusted`], testing each step with [`redirects` query]:
140+
141+
```hurl
142+
GET https://example.org/step1
143+
[Options]
144+
location: true
145+
HTTP 200
146+
[Asserts]
147+
redirects count == 2
148+
redirects nth 0 location == "https://example.org/step2"
149+
redirects nth 1 location == "https://example.org/step3"
150+
```
151+
152+
[`url` query] can also be used to get the final effective URL:
153+
154+
```hurl
155+
GET https://example.org/step1
156+
[Options]
157+
location: true
158+
HTTP 200
159+
[Asserts]
160+
url == "https://example.org/step3"
161+
```
162+
118163
### Retry
119164

120165
Every entry can be retried upon asserts, captures or runtime errors. Retries allow polling scenarios and effective runs
@@ -195,7 +240,6 @@ For complete reference, below is a diagram for the executed entries.
195240
</div>
196241

197242

198-
199243
[request]: {% link _docs/request.md %}
200244
[response]: {% link _docs/response.md %}
201245
[capture values]: {% link _docs/capturing-response.md %}
@@ -214,3 +258,5 @@ For complete reference, below is a diagram for the executed entries.
214258
[`--retry-interval`]: {% link _docs/manual.md %}#retry-interval
215259
[`delay`]: {% link _docs/manual.md %}#retry
216260
[`repeat`]: {% link _docs/manual.md %}#repeat
261+
[`redirects` query]: {% link _docs/asserting-response.md %}#redirects-assert
262+
[`url` query]: {% link _docs/asserting-response.md %}#url-assert

0 commit comments

Comments
 (0)