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.
Commit
a9edb60a5f24c1dd5b1857a733d7842e6a55b674
Parent
f34014308039bdd…
1 file changed
+11
-8
+11
-8
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -53,19 +53,19 @@ | ||
| 53 | 53 | uplevel 1 fossil json {*}$args |
| 54 | 54 | set JR [::json::json2dict $RESULT] |
| 55 | 55 | return "200" |
| 56 | 56 | } |
| 57 | 57 | |
| 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 | |
| 59 | 59 | # RESULT to the HTTP response body, and JR to a Tcl dict conversion of |
| 60 | 60 | # the response body. |
| 61 | 61 | # |
| 62 | 62 | # Returns the status code from the HTTP header. |
| 63 | -proc fossil_http_json {url} { | |
| 63 | +proc fossil_http_json {url {cookie "Muppet=Monster"} args} { | |
| 64 | 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] | |
| 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 | 67 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 68 | 68 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 69 | 69 | if {$status eq "200"} { |
| 70 | 70 | set JR [::json::json2dict $body] |
| 71 | 71 | } |
| @@ -217,19 +217,22 @@ | ||
| 217 | 217 | test_json_envelope_ok json-login-u1-env |
| 218 | 218 | test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {} |
| 219 | 219 | set AuthU1 [dict get $JR payload] |
| 220 | 220 | test_hascaps json-login-c "s" [dict get $AuthU1 capabilities] |
| 221 | 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 | + | |
| 222 | 225 | # json cap |
| 223 | 226 | # The CLI user has all rights, and no auth token affects that. This |
| 224 | 227 | # is consistent with the rest of the fossil CLI, and with the |
| 225 | 228 | # pragmatic argument that using the CLI implies physical access to |
| 226 | 229 | # the repo file itself, which can be taunted with many tools |
| 227 | 230 | # including raw SQLite which will also ignore authentication. |
| 228 | 231 | write_file anon-2 [subst { |
| 229 | 232 | {"command":"cap", |
| 230 | - "authToken":"[dict get $AuthAnon]" | |
| 233 | + "authToken":"[dict get $AuthAnon authToken]" | |
| 231 | 234 | } |
| 232 | 235 | }] |
| 233 | 236 | fossil_json --json-input anon-2 |
| 234 | 237 | test_json_envelope_ok json-cap-env |
| 235 | 238 | # No point checking any other flags, setup implies all, and all are |
| @@ -348,11 +351,10 @@ | ||
| 348 | 351 | |
| 349 | 352 | |
| 350 | 353 | #### TICKETS |
| 351 | 354 | # API Docs say not yet defined, so it isn't quite fair to mark this |
| 352 | 355 | # category as TODO for the test cases... |
| 353 | -# test TODO-json-tickets false knownBug | |
| 354 | 356 | |
| 355 | 357 | #### TICKET REPORTS |
| 356 | 358 | |
| 357 | 359 | # json report get NUMBER |
| 358 | 360 | fossil_json report get 1 |
| @@ -387,12 +389,13 @@ | ||
| 387 | 389 | test_dict_keys json-timeline-checkin-$i $t {type uuid timestamp comment user isLeaf tags} {} |
| 388 | 390 | incr i |
| 389 | 391 | } |
| 390 | 392 | |
| 391 | 393 | # 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 | |
| 394 | 397 | #test_json_payload json-timeline-ci {limit timeline} {} |
| 395 | 398 | |
| 396 | 399 | # json timeline ticket |
| 397 | 400 | fossil_json timeline ticket |
| 398 | 401 | test_json_envelope_ok json-timeline-ticket-env |
| 399 | 402 |
| --- 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 |