Fossil SCM
More JSON test adjustments.
Commit
ad0679cabf78e2bbada4a97fbc58936b52975dd1f4a032c2ea9922ee057cf05b
Parent
2e4238368ea5093…
1 file changed
+22
-9
+22
-9
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -75,11 +75,11 @@ | ||
| 75 | 75 | # Returns the status code from the HTTP header. |
| 76 | 76 | proc fossil_http_json {url {cookie "Muppet=Monster"} args} { |
| 77 | 77 | global RESULT JR |
| 78 | 78 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 79 | 79 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 80 | - set head ""; set status "--NO_MATCH--" | |
| 80 | + set head ""; set body ""; set status "--NO_MATCH--" | |
| 81 | 81 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 82 | 82 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 83 | 83 | if {$status eq "200"} { |
| 84 | 84 | set JR [json2dict $body] |
| 85 | 85 | } |
| @@ -119,10 +119,11 @@ | ||
| 119 | 119 | flush stdout |
| 120 | 120 | #exec $fossilexe |
| 121 | 121 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 122 | 122 | |
| 123 | 123 | # separate HTTP headers from body |
| 124 | + set head ""; set body ""; set status "--NO_MATCH--" | |
| 124 | 125 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 125 | 126 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 126 | 127 | if {$status eq "200"} { |
| 127 | 128 | if {[string length $body] > 0} { |
| 128 | 129 | set JR [json2dict $body] |
| @@ -311,28 +312,40 @@ | ||
| 311 | 312 | # json cap via POST with authToken in request envelope |
| 312 | 313 | set anon2 [read_file anon-2] |
| 313 | 314 | fossil_post_json "/json/cap" $anon2 |
| 314 | 315 | test json-cap-POSTenv-env-0 {[string length $JR] > 0} |
| 315 | 316 | test_json_envelope_ok json-cap-POSTenv-env |
| 316 | -test json-cap-POSTenv-name {[dict get $JR payload name] eq "anonymous"} knownBug | |
| 317 | +if {[catch {test json-cap-POSTenv-name \ | |
| 318 | + {[dict get $JR payload name] eq "anonymous"} knownBug} jerr]} then { | |
| 319 | + test json-cap-POSTenv-name-threw 0 | |
| 320 | + protOut "CAUGHT: $jerr" | |
| 321 | +} | |
| 317 | 322 | test json-cap-POSTenv-notsetup {![dict get $JR payload permissionFlags setup]} |
| 318 | 323 | |
| 319 | 324 | |
| 320 | 325 | # json cap via GET with authToken in Cookie header |
| 321 | 326 | fossil_post_json "/json/cap" {} $AnonCookie |
| 322 | 327 | test json-cap-GETcookie-env-0 {[string length $JR] > 0} |
| 323 | -test_json_envelope_ok json-cap-GETcookie-env | |
| 324 | -test json-cap-GETcookie-name {[dict get $JR payload name] eq "anonymous"} | |
| 325 | -test json-cap-GETcookie-notsetup {![dict get $JR payload permissionFlags setup]} | |
| 328 | +test_json_envelope_ok json-cap-GETcookie-env-0 | |
| 329 | +if {[catch {test json-cap-GETcookie-name-0 \ | |
| 330 | + {[dict get $JR payload name] eq "anonymous"}} jerr]} then { | |
| 331 | + test json-cap-GETcookie-name-0-threw 0 | |
| 332 | + protOut "CAUGHT: $jerr" | |
| 333 | +} | |
| 334 | +test json-cap-GETcookie-notsetup-0 {![dict get $JR payload permissionFlags setup]} | |
| 326 | 335 | |
| 327 | 336 | |
| 328 | 337 | # json cap via GET with authToken in a parameter |
| 329 | 338 | fossil_post_json "/json/cap?authToken=[dict get $AuthAnon authToken]" {} |
| 330 | -test json-cap-GETcookie-env-0 {[string length $JR] > 0} | |
| 331 | -test_json_envelope_ok json-cap-GETcookie-env | |
| 332 | -test json-cap-GETcookie-name {[dict get $JR payload name] eq "anonymous"} | |
| 333 | -test json-cap-GETcookie-notsetup {![dict get $JR payload permissionFlags setup]} | |
| 339 | +test json-cap-GETcookie-env-1 {[string length $JR] > 0} | |
| 340 | +test_json_envelope_ok json-cap-GETcookie-env-1 | |
| 341 | +if {[catch {test json-cap-GETcookie-name-1 \ | |
| 342 | + {[dict get $JR payload name] eq "anonymous"}} jerr]} then { | |
| 343 | + test json-cap-GETcookie-name-1-threw 0 | |
| 344 | + protOut "CAUGHT: $jerr" | |
| 345 | +} | |
| 346 | +test json-cap-GETcookie-notsetup-1 {![dict get $JR payload permissionFlags setup]} | |
| 334 | 347 | |
| 335 | 348 | |
| 336 | 349 | # whoami |
| 337 | 350 | # via CLI with no auth token supplied |
| 338 | 351 | fossil_json whoami |
| 339 | 352 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -75,11 +75,11 @@ | |
| 75 | # Returns the status code from the HTTP header. |
| 76 | proc fossil_http_json {url {cookie "Muppet=Monster"} args} { |
| 77 | global RESULT JR |
| 78 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 79 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 80 | set head ""; set status "--NO_MATCH--" |
| 81 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 82 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 83 | if {$status eq "200"} { |
| 84 | set JR [json2dict $body] |
| 85 | } |
| @@ -119,10 +119,11 @@ | |
| 119 | flush stdout |
| 120 | #exec $fossilexe |
| 121 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 122 | |
| 123 | # separate HTTP headers from body |
| 124 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 125 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 126 | if {$status eq "200"} { |
| 127 | if {[string length $body] > 0} { |
| 128 | set JR [json2dict $body] |
| @@ -311,28 +312,40 @@ | |
| 311 | # json cap via POST with authToken in request envelope |
| 312 | set anon2 [read_file anon-2] |
| 313 | fossil_post_json "/json/cap" $anon2 |
| 314 | test json-cap-POSTenv-env-0 {[string length $JR] > 0} |
| 315 | test_json_envelope_ok json-cap-POSTenv-env |
| 316 | test json-cap-POSTenv-name {[dict get $JR payload name] eq "anonymous"} knownBug |
| 317 | test json-cap-POSTenv-notsetup {![dict get $JR payload permissionFlags setup]} |
| 318 | |
| 319 | |
| 320 | # json cap via GET with authToken in Cookie header |
| 321 | fossil_post_json "/json/cap" {} $AnonCookie |
| 322 | test json-cap-GETcookie-env-0 {[string length $JR] > 0} |
| 323 | test_json_envelope_ok json-cap-GETcookie-env |
| 324 | test json-cap-GETcookie-name {[dict get $JR payload name] eq "anonymous"} |
| 325 | test json-cap-GETcookie-notsetup {![dict get $JR payload permissionFlags setup]} |
| 326 | |
| 327 | |
| 328 | # json cap via GET with authToken in a parameter |
| 329 | fossil_post_json "/json/cap?authToken=[dict get $AuthAnon authToken]" {} |
| 330 | test json-cap-GETcookie-env-0 {[string length $JR] > 0} |
| 331 | test_json_envelope_ok json-cap-GETcookie-env |
| 332 | test json-cap-GETcookie-name {[dict get $JR payload name] eq "anonymous"} |
| 333 | test json-cap-GETcookie-notsetup {![dict get $JR payload permissionFlags setup]} |
| 334 | |
| 335 | |
| 336 | # whoami |
| 337 | # via CLI with no auth token supplied |
| 338 | fossil_json whoami |
| 339 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -75,11 +75,11 @@ | |
| 75 | # Returns the status code from the HTTP header. |
| 76 | proc fossil_http_json {url {cookie "Muppet=Monster"} args} { |
| 77 | global RESULT JR |
| 78 | set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie" |
| 79 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 80 | set head ""; set body ""; set status "--NO_MATCH--" |
| 81 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 82 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 83 | if {$status eq "200"} { |
| 84 | set JR [json2dict $body] |
| 85 | } |
| @@ -119,10 +119,11 @@ | |
| 119 | flush stdout |
| 120 | #exec $fossilexe |
| 121 | set RESULT [fossil_maybe_answer $request http {*}$args] |
| 122 | |
| 123 | # separate HTTP headers from body |
| 124 | set head ""; set body ""; set status "--NO_MATCH--" |
| 125 | regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body |
| 126 | regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg |
| 127 | if {$status eq "200"} { |
| 128 | if {[string length $body] > 0} { |
| 129 | set JR [json2dict $body] |
| @@ -311,28 +312,40 @@ | |
| 312 | # json cap via POST with authToken in request envelope |
| 313 | set anon2 [read_file anon-2] |
| 314 | fossil_post_json "/json/cap" $anon2 |
| 315 | test json-cap-POSTenv-env-0 {[string length $JR] > 0} |
| 316 | test_json_envelope_ok json-cap-POSTenv-env |
| 317 | if {[catch {test json-cap-POSTenv-name \ |
| 318 | {[dict get $JR payload name] eq "anonymous"} knownBug} jerr]} then { |
| 319 | test json-cap-POSTenv-name-threw 0 |
| 320 | protOut "CAUGHT: $jerr" |
| 321 | } |
| 322 | test json-cap-POSTenv-notsetup {![dict get $JR payload permissionFlags setup]} |
| 323 | |
| 324 | |
| 325 | # json cap via GET with authToken in Cookie header |
| 326 | fossil_post_json "/json/cap" {} $AnonCookie |
| 327 | test json-cap-GETcookie-env-0 {[string length $JR] > 0} |
| 328 | test_json_envelope_ok json-cap-GETcookie-env-0 |
| 329 | if {[catch {test json-cap-GETcookie-name-0 \ |
| 330 | {[dict get $JR payload name] eq "anonymous"}} jerr]} then { |
| 331 | test json-cap-GETcookie-name-0-threw 0 |
| 332 | protOut "CAUGHT: $jerr" |
| 333 | } |
| 334 | test json-cap-GETcookie-notsetup-0 {![dict get $JR payload permissionFlags setup]} |
| 335 | |
| 336 | |
| 337 | # json cap via GET with authToken in a parameter |
| 338 | fossil_post_json "/json/cap?authToken=[dict get $AuthAnon authToken]" {} |
| 339 | test json-cap-GETcookie-env-1 {[string length $JR] > 0} |
| 340 | test_json_envelope_ok json-cap-GETcookie-env-1 |
| 341 | if {[catch {test json-cap-GETcookie-name-1 \ |
| 342 | {[dict get $JR payload name] eq "anonymous"}} jerr]} then { |
| 343 | test json-cap-GETcookie-name-1-threw 0 |
| 344 | protOut "CAUGHT: $jerr" |
| 345 | } |
| 346 | test json-cap-GETcookie-notsetup-1 {![dict get $JR payload permissionFlags setup]} |
| 347 | |
| 348 | |
| 349 | # whoami |
| 350 | # via CLI with no auth token supplied |
| 351 | fossil_json whoami |
| 352 |