Fossil SCM

More JSON test adjustments.

mistachkin 2020-06-11 23:06 jsonTestsPass
Commit ad0679cabf78e2bbada4a97fbc58936b52975dd1f4a032c2ea9922ee057cf05b
1 file changed +22 -9
+22 -9
--- test/json.test
+++ test/json.test
@@ -75,11 +75,11 @@
7575
# Returns the status code from the HTTP header.
7676
proc fossil_http_json {url {cookie "Muppet=Monster"} args} {
7777
global RESULT JR
7878
set request "GET $url HTTP/1.1\r\nHost: localhost\r\nUser-Agent: Fossil-http-json\r\nCookie: $cookie"
7979
set RESULT [fossil_maybe_answer $request http {*}$args]
80
- set head ""; set status "--NO_MATCH--"
80
+ set head ""; set body ""; set status "--NO_MATCH--"
8181
regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
8282
regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
8383
if {$status eq "200"} {
8484
set JR [json2dict $body]
8585
}
@@ -119,10 +119,11 @@
119119
flush stdout
120120
#exec $fossilexe
121121
set RESULT [fossil_maybe_answer $request http {*}$args]
122122
123123
# separate HTTP headers from body
124
+ set head ""; set body ""; set status "--NO_MATCH--"
124125
regexp {(?w)(.*)^\s*$(.*)} $RESULT dummy head body
125126
regexp {^HTTP\S+\s+(\d\d\d)\s+(.*)$} $head dummy status msg
126127
if {$status eq "200"} {
127128
if {[string length $body] > 0} {
128129
set JR [json2dict $body]
@@ -311,28 +312,40 @@
311312
# json cap via POST with authToken in request envelope
312313
set anon2 [read_file anon-2]
313314
fossil_post_json "/json/cap" $anon2
314315
test json-cap-POSTenv-env-0 {[string length $JR] > 0}
315316
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
+}
317322
test json-cap-POSTenv-notsetup {![dict get $JR payload permissionFlags setup]}
318323
319324
320325
# json cap via GET with authToken in Cookie header
321326
fossil_post_json "/json/cap" {} $AnonCookie
322327
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]}
326335
327336
328337
# json cap via GET with authToken in a parameter
329338
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]}
334347
335348
336349
# whoami
337350
# via CLI with no auth token supplied
338351
fossil_json whoami
339352
--- 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

Keyboard Shortcuts

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