api-tuner 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/package.json +1 -1
- package/rules/assertions.n3 +17 -0
- package/rules/headers.n3 +18 -1
- package/rules/requests.n3 +8 -3
package/README.md
CHANGED
|
@@ -188,6 +188,18 @@ Query parameters can be added to a request using `tuner:query`.
|
|
|
188
188
|
?req tuner:query ( "name" "value" ) .
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
+
#### Basic Authentication
|
|
192
|
+
|
|
193
|
+
Use `tuner:basicAuth` to add HTTP Basic Authentication to a request. It takes a list of `( username password )` and automatically sets the `Authorization: Basic ...` header.
|
|
194
|
+
|
|
195
|
+
```turtle
|
|
196
|
+
<#test> tuner:request [
|
|
197
|
+
a tuner:Request ;
|
|
198
|
+
tuner:url <http://example.com/api> ;
|
|
199
|
+
tuner:basicAuth ( "admin" "secret" ) ;
|
|
200
|
+
] .
|
|
201
|
+
```
|
|
202
|
+
|
|
191
203
|
#### Shell Variables
|
|
192
204
|
|
|
193
205
|
Values used in request URL, headers and query params are resolved from the shell environment.
|
package/package.json
CHANGED
package/rules/assertions.n3
CHANGED
|
@@ -114,8 +114,25 @@ prefix file: <http://www.w3.org/2000/10/swap/file#>
|
|
|
114
114
|
{
|
|
115
115
|
?res tuner:header ( ?name ?value ?builtIn ) .
|
|
116
116
|
} <= {
|
|
117
|
+
?name log:rawType log:Literal .
|
|
117
118
|
?name string:lowerCase ?nameLower .
|
|
118
119
|
|
|
120
|
+
(
|
|
121
|
+
{
|
|
122
|
+
?res log:notIncludes {
|
|
123
|
+
[] a tuner:Response ;
|
|
124
|
+
tuner:headers [
|
|
125
|
+
tuner:name ?nameLower ;
|
|
126
|
+
] .
|
|
127
|
+
} .
|
|
128
|
+
}
|
|
129
|
+
{
|
|
130
|
+
("Expected header '" ?name "' but it was not present in the response")!string:concatenation^tuner:info .
|
|
131
|
+
true log:equalTo false .
|
|
132
|
+
}
|
|
133
|
+
true
|
|
134
|
+
) log:ifThenElseIn [] .
|
|
135
|
+
|
|
119
136
|
?res log:includes {
|
|
120
137
|
[] a tuner:Response ;
|
|
121
138
|
tuner:headers [
|
package/rules/headers.n3
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
PREFIX log: <http://www.w3.org/2000/10/swap/log#>
|
|
1
2
|
prefix tuner: <https://api-tuner.described.at/>
|
|
2
3
|
prefix string: <http://www.w3.org/2000/10/swap/string#>
|
|
3
4
|
|
|
5
|
+
tuner:header a tuner:HeaderRule ; tuner:headerArgsRule <#defaultHeader> .
|
|
6
|
+
|
|
4
7
|
{
|
|
5
|
-
(?fieldName ?fieldValue)
|
|
8
|
+
(?fieldName ?fieldValue) <#defaultHeader> ?curlArg .
|
|
6
9
|
} <= {
|
|
7
10
|
( ' -H "' ?fieldName ":" ?fieldValue '"' ) string:concatenation ?curlArg .
|
|
8
11
|
} .
|
|
12
|
+
|
|
13
|
+
####
|
|
14
|
+
|
|
15
|
+
tuner:basicAuth a tuner:HeaderRule ; tuner:headerArgsRule <#basicAuth> .
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
( ?user ?password ) <#basicAuth> ?curlArgs .
|
|
19
|
+
} <= {
|
|
20
|
+
( ?user ":" ?password ) string:concatenation ?credentials .
|
|
21
|
+
|
|
22
|
+
( "node -e 'console.log(Buffer.from(\"" ?credentials "\").toString(\"base64\"))'" )!string:concatenation log:shell ?encoded .
|
|
23
|
+
|
|
24
|
+
( "Authorization" ("Basic " (?encoded "\n$" "")!string:replace)!string:concatenation ) <#defaultHeader> ?curlArgs .
|
|
25
|
+
} .
|
package/rules/requests.n3
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
1
2
|
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
|
|
2
3
|
prefix e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
|
|
3
4
|
prefix log: <http://www.w3.org/2000/10/swap/log#>
|
|
@@ -20,10 +21,14 @@ prefix earl: <http://www.w3.org/ns/earl#>
|
|
|
20
21
|
true log:becomes { ?req tuner:done true } .
|
|
21
22
|
|
|
22
23
|
(
|
|
23
|
-
{ ?req tuner:header [] . }
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
?req ?headerRule [] .
|
|
26
|
+
?headerRule a tuner:HeaderRule .
|
|
27
|
+
?headerRule tuner:headerArgsRule ?headerRuleFn .
|
|
28
|
+
}
|
|
29
|
+
{
|
|
30
|
+
( ?header { ?req ?headerRule ?header } ?headers ) log:collectAllIn [] .
|
|
31
|
+
( ?headers ?headerRuleFn )!list:map string:concatenation ?headersArgs .
|
|
27
32
|
}
|
|
28
33
|
{ ?headersArgs log:equalTo "" }
|
|
29
34
|
) log:ifThenElseIn [] .
|