Fossil SCM

Add cookie support to fossil_http_json, as well as extra args passed through to fossil_maybe_answer so -expectError can be used. Tweak some comments. Note doc revision eliminating /json/timeline/ci, which clears a previous knownBug. Cache a usable login cookie for both anonymous and user U1 for later use.

rberteig 2016-01-29 23:40 rberteig-json-test
Commit a9edb60a5f24c1dd5b1857a733d7842e6a55b674
1 file changed +11 -8
+11 -8
--- test/json.test
+++ test/json.test
@@ -53,19 +53,19 @@
5353
uplevel 1 fossil json {*}$args
5454
set JR [::json::json2dict $RESULT]
5555
return "200"
5656
}
5757
58
-# Use the HTTP interface to fetch a JSON API URL. Sets the globals
58
+# Use the HTTP interface to GET a JSON API URL. Sets the globals
5959
# RESULT to the HTTP response body, and JR to a Tcl dict conversion of
6060
# the response body.
6161
#
6262
# Returns the status code from the HTTP header.
63
-proc fossil_http_json {url} {
63
+proc fossil_http_json {url {cookie "Muppet=Monster"} args} {
6464
global RESULT JR
65
- set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil"
66
- set RESULT [fossil_maybe_answer $request http]
65
+ set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie"
66
+ set RESULT [fossil_maybe_answer $request http {*}$args]
6767
regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
6868
regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
6969
if {$status eq "200"} {
7070
set JR [::json::json2dict $body]
7171
}
@@ -217,19 +217,22 @@
217217
test_json_envelope_ok json-login-u1-env
218218
test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {}
219219
set AuthU1 [dict get $JR payload]
220220
test_hascaps json-login-c "s" [dict get $AuthU1 capabilities]
221221
222
+set U1Cookie [dict get $AuthU1 loginCookieName]=[regsub -all {[/]} [dict get $AuthU1 authToken] {%2F} ]
223
+set AnonCookie [dict get $AuthAnon loginCookieName]=[regsub -all {[/]} [dict get $AuthAnon authToken] {%2F} ]
224
+
222225
# json cap
223226
# The CLI user has all rights, and no auth token affects that. This
224227
# is consistent with the rest of the fossil CLI, and with the
225228
# pragmatic argument that using the CLI implies physical access to
226229
# the repo file itself, which can be taunted with many tools
227230
# including raw SQLite which will also ignore authentication.
228231
write_file anon-2 [subst {
229232
{"command":"cap",
230
- "authToken":"[dict get $AuthAnon]"
233
+ "authToken":"[dict get $AuthAnon authToken]"
231234
}
232235
}]
233236
fossil_json --json-input anon-2
234237
test_json_envelope_ok json-cap-env
235238
# No point checking any other flags, setup implies all, and all are
@@ -348,11 +351,10 @@
348351
349352
350353
#### TICKETS
351354
# API Docs say not yet defined, so it isn't quite fair to mark this
352355
# category as TODO for the test cases...
353
-# test TODO-json-tickets false knownBug
354356
355357
#### TICKET REPORTS
356358
357359
# json report get NUMBER
358360
fossil_json report get 1
@@ -387,12 +389,13 @@
387389
test_dict_keys json-timeline-checkin-$i $t {type uuid timestamp comment user isLeaf tags} {}
388390
incr i
389391
}
390392
391393
# json timeline ci
392
-fossil_json timeline ci
393
-test json-timeline-ci {[dict get $JR resultCode] ne "FOSSIL-1102"} knownBug
394
+# removed from documentation
395
+#fossil_json timeline ci
396
+#test json-timeline-ci {[dict get $JR resultCode] ne "FOSSIL-1102"} knownBug
394397
#test_json_payload json-timeline-ci {limit timeline} {}
395398
396399
# json timeline ticket
397400
fossil_json timeline ticket
398401
test_json_envelope_ok json-timeline-ticket-env
399402
--- test/json.test
+++ test/json.test
@@ -53,19 +53,19 @@
53 uplevel 1 fossil json {*}$args
54 set JR [::json::json2dict $RESULT]
55 return "200"
56 }
57
58 # Use the HTTP interface to fetch a JSON API URL. Sets the globals
59 # RESULT to the HTTP response body, and JR to a Tcl dict conversion of
60 # the response body.
61 #
62 # Returns the status code from the HTTP header.
63 proc fossil_http_json {url} {
64 global RESULT JR
65 set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil"
66 set RESULT [fossil_maybe_answer $request http]
67 regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
68 regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
69 if {$status eq "200"} {
70 set JR [::json::json2dict $body]
71 }
@@ -217,19 +217,22 @@
217 test_json_envelope_ok json-login-u1-env
218 test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {}
219 set AuthU1 [dict get $JR payload]
220 test_hascaps json-login-c "s" [dict get $AuthU1 capabilities]
221
 
 
 
222 # json cap
223 # The CLI user has all rights, and no auth token affects that. This
224 # is consistent with the rest of the fossil CLI, and with the
225 # pragmatic argument that using the CLI implies physical access to
226 # the repo file itself, which can be taunted with many tools
227 # including raw SQLite which will also ignore authentication.
228 write_file anon-2 [subst {
229 {"command":"cap",
230 "authToken":"[dict get $AuthAnon]"
231 }
232 }]
233 fossil_json --json-input anon-2
234 test_json_envelope_ok json-cap-env
235 # No point checking any other flags, setup implies all, and all are
@@ -348,11 +351,10 @@
348
349
350 #### TICKETS
351 # API Docs say not yet defined, so it isn't quite fair to mark this
352 # category as TODO for the test cases...
353 # test TODO-json-tickets false knownBug
354
355 #### TICKET REPORTS
356
357 # json report get NUMBER
358 fossil_json report get 1
@@ -387,12 +389,13 @@
387 test_dict_keys json-timeline-checkin-$i $t {type uuid timestamp comment user isLeaf tags} {}
388 incr i
389 }
390
391 # json timeline ci
392 fossil_json timeline ci
393 test json-timeline-ci {[dict get $JR resultCode] ne "FOSSIL-1102"} knownBug
 
394 #test_json_payload json-timeline-ci {limit timeline} {}
395
396 # json timeline ticket
397 fossil_json timeline ticket
398 test_json_envelope_ok json-timeline-ticket-env
399
--- test/json.test
+++ test/json.test
@@ -53,19 +53,19 @@
53 uplevel 1 fossil json {*}$args
54 set JR [::json::json2dict $RESULT]
55 return "200"
56 }
57
58 # Use the HTTP interface to GET a JSON API URL. Sets the globals
59 # RESULT to the HTTP response body, and JR to a Tcl dict conversion of
60 # the response body.
61 #
62 # Returns the status code from the HTTP header.
63 proc fossil_http_json {url {cookie "Muppet=Monster"} args} {
64 global RESULT JR
65 set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie"
66 set RESULT [fossil_maybe_answer $request http {*}$args]
67 regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
68 regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
69 if {$status eq "200"} {
70 set JR [::json::json2dict $body]
71 }
@@ -217,19 +217,22 @@
217 test_json_envelope_ok json-login-u1-env
218 test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {}
219 set AuthU1 [dict get $JR payload]
220 test_hascaps json-login-c "s" [dict get $AuthU1 capabilities]
221
222 set U1Cookie [dict get $AuthU1 loginCookieName]=[regsub -all {[/]} [dict get $AuthU1 authToken] {%2F} ]
223 set AnonCookie [dict get $AuthAnon loginCookieName]=[regsub -all {[/]} [dict get $AuthAnon authToken] {%2F} ]
224
225 # json cap
226 # The CLI user has all rights, and no auth token affects that. This
227 # is consistent with the rest of the fossil CLI, and with the
228 # pragmatic argument that using the CLI implies physical access to
229 # the repo file itself, which can be taunted with many tools
230 # including raw SQLite which will also ignore authentication.
231 write_file anon-2 [subst {
232 {"command":"cap",
233 "authToken":"[dict get $AuthAnon authToken]"
234 }
235 }]
236 fossil_json --json-input anon-2
237 test_json_envelope_ok json-cap-env
238 # No point checking any other flags, setup implies all, and all are
@@ -348,11 +351,10 @@
351
352
353 #### TICKETS
354 # API Docs say not yet defined, so it isn't quite fair to mark this
355 # category as TODO for the test cases...
 
356
357 #### TICKET REPORTS
358
359 # json report get NUMBER
360 fossil_json report get 1
@@ -387,12 +389,13 @@
389 test_dict_keys json-timeline-checkin-$i $t {type uuid timestamp comment user isLeaf tags} {}
390 incr i
391 }
392
393 # json timeline ci
394 # removed from documentation
395 #fossil_json timeline ci
396 #test json-timeline-ci {[dict get $JR resultCode] ne "FOSSIL-1102"} knownBug
397 #test_json_payload json-timeline-ci {limit timeline} {}
398
399 # json timeline ticket
400 fossil_json timeline ticket
401 test_json_envelope_ok json-timeline-ticket-env
402

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button