Fossil SCM
Added /json/whoami from CLI, changed /json/cap to only care that it worked from CLI since capabilities are sort of meaningless in CLI mode. Added checks for caps provided to each logged in user by /json/login from its own results. Starting on /json/branch/list. All tests pass except known bugs and TODOs.
Commit
bab84bd74237641cb7a2597945f575955786884e
Parent
9b8b051899ca59b…
1 file changed
+38
-8
+38
-8
| --- test/json.test | ||
| +++ test/json.test | ||
| @@ -131,11 +131,10 @@ | ||
| 131 | 131 | fossil_http_json /json/HAI |
| 132 | 132 | test_json_envelope_ok json-http-HAI |
| 133 | 133 | test_json_payload json-http-HAI $HAIfields {} |
| 134 | 134 | test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 135 | 135 | |
| 136 | - | |
| 137 | 136 | fossil_json version |
| 138 | 137 | test_json_envelope_ok json-version |
| 139 | 138 | test_json_payload json-version $HAIfields {} |
| 140 | 139 | test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 141 | 140 | |
| @@ -159,11 +158,11 @@ | ||
| 159 | 158 | test_json_envelope_ok json-artifact-file-env |
| 160 | 159 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| 161 | 160 | test_json_payload json-artifact [concat type uuid size checkins] {} |
| 162 | 161 | |
| 163 | 162 | # json artifact (wiki) |
| 164 | -fossil wiki create Empty <<"" | |
| 163 | +fossil wiki create Empty empty | |
| 165 | 164 | fossil_json wiki get Empty |
| 166 | 165 | test json-wiki-get {[dict get $JR payload name] eq "Empty"} |
| 167 | 166 | set uuid [dict get $JR payload uuid] |
| 168 | 167 | fossil_json artifact $uuid |
| 169 | 168 | test_json_envelope_ok json-artifact-wiki-env |
| @@ -194,10 +193,16 @@ | ||
| 194 | 193 | }] |
| 195 | 194 | fossil_json --json-input anon-1 |
| 196 | 195 | test_json_envelope_ok json-login-a-env |
| 197 | 196 | test_json_payload json-login-a {authToken name capabilities loginCookieName} {} |
| 198 | 197 | set AuthAnon [dict get $JR payload] |
| 198 | +proc test_hascaps {testname need caps} { | |
| 199 | + foreach n [split $need {}] { | |
| 200 | + test $testname-$n {[string first $n $caps] >= 0} | |
| 201 | + } | |
| 202 | +} | |
| 203 | +test_hascaps json-login-c "hmnc" [dict get $AuthAnon capabilities] | |
| 199 | 204 | |
| 200 | 205 | fossil user new U1 User-1 Uone |
| 201 | 206 | fossil user capabilities U1 s |
| 202 | 207 | write_file u1 { |
| 203 | 208 | { |
| @@ -210,25 +215,50 @@ | ||
| 210 | 215 | } |
| 211 | 216 | fossil_json --json-input u1 |
| 212 | 217 | test_json_envelope_ok json-login-u1-env |
| 213 | 218 | test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {} |
| 214 | 219 | set AuthU1 [dict get $JR payload] |
| 215 | -#puts $AuthAnon | |
| 216 | -#puts $AuthU1 | |
| 220 | +test_hascaps json-login-c "s" [dict get $AuthU1 capabilities] | |
| 217 | 221 | |
| 218 | 222 | # json cap |
| 219 | -# Bug? The CLI user has all rights, and no auth token affects that. | |
| 220 | -write_file u2 [subst { | |
| 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 { | |
| 221 | 229 | {"command":"cap", |
| 222 | 230 | "authToken":"[dict get $AuthAnon]" |
| 223 | 231 | } |
| 224 | 232 | }] |
| 225 | -fossil_json --json-input u2 | |
| 233 | +fossil_json --json-input anon-2 | |
| 226 | 234 | test_json_envelope_ok json-cap-env |
| 227 | -#puts [dict get $JR payload] | |
| 235 | +# No point checking any other flags, setup implies all, and all are | |
| 236 | +# moot from CLI. | |
| 237 | +test json-cap-CLI {[dict get $JR payload permissionFlags setup]} | |
| 238 | + | |
| 239 | +test TODO-JSON-POST-AUTHENTICATION false knownBug | |
| 240 | +#TODO: implement support for POST with JSON payload from file | |
| 241 | +#fossil_http_post_json /json anon-2 | |
| 242 | +#test_json_envelope_ok json-cap-http-env | |
| 243 | +#test json-cap-http {![dict get $JR payload permissionFlags setup]} | |
| 244 | + | |
| 245 | +# whoami | |
| 246 | +# via CLI with no auth token supplied | |
| 247 | +fossil_json whoami | |
| 248 | +test_json_envelope_ok json-whoami-cli-env | |
| 249 | +test_json_payload json-whoami-cli {name capabilities} {} | |
| 250 | +test json-whoami-cli-name {[dict get $JR payload name] eq "nobody"} | |
| 251 | +test_hascaps json-whoami-cli-cap "gjorz" [dict get $JR payload capabilities] | |
| 228 | 252 | |
| 229 | 253 | #### BRANCHES |
| 254 | +fossil_json branch list | |
| 255 | +test_json_envelope_ok json-branch-list-env | |
| 256 | +test_json_payload json-branch-list {range current branches} {} | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 230 | 260 | #### CONFIG |
| 231 | 261 | #### DIFFS |
| 232 | 262 | #### DIRECTORY LISTING |
| 233 | 263 | #### FILE INFO |
| 234 | 264 | #### QUERY |
| 235 | 265 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -131,11 +131,10 @@ | |
| 131 | fossil_http_json /json/HAI |
| 132 | test_json_envelope_ok json-http-HAI |
| 133 | test_json_payload json-http-HAI $HAIfields {} |
| 134 | test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 135 | |
| 136 | |
| 137 | fossil_json version |
| 138 | test_json_envelope_ok json-version |
| 139 | test_json_payload json-version $HAIfields {} |
| 140 | test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 141 | |
| @@ -159,11 +158,11 @@ | |
| 159 | test_json_envelope_ok json-artifact-file-env |
| 160 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| 161 | test_json_payload json-artifact [concat type uuid size checkins] {} |
| 162 | |
| 163 | # json artifact (wiki) |
| 164 | fossil wiki create Empty <<"" |
| 165 | fossil_json wiki get Empty |
| 166 | test json-wiki-get {[dict get $JR payload name] eq "Empty"} |
| 167 | set uuid [dict get $JR payload uuid] |
| 168 | fossil_json artifact $uuid |
| 169 | test_json_envelope_ok json-artifact-wiki-env |
| @@ -194,10 +193,16 @@ | |
| 194 | }] |
| 195 | fossil_json --json-input anon-1 |
| 196 | test_json_envelope_ok json-login-a-env |
| 197 | test_json_payload json-login-a {authToken name capabilities loginCookieName} {} |
| 198 | set AuthAnon [dict get $JR payload] |
| 199 | |
| 200 | fossil user new U1 User-1 Uone |
| 201 | fossil user capabilities U1 s |
| 202 | write_file u1 { |
| 203 | { |
| @@ -210,25 +215,50 @@ | |
| 210 | } |
| 211 | fossil_json --json-input u1 |
| 212 | test_json_envelope_ok json-login-u1-env |
| 213 | test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {} |
| 214 | set AuthU1 [dict get $JR payload] |
| 215 | #puts $AuthAnon |
| 216 | #puts $AuthU1 |
| 217 | |
| 218 | # json cap |
| 219 | # Bug? The CLI user has all rights, and no auth token affects that. |
| 220 | write_file u2 [subst { |
| 221 | {"command":"cap", |
| 222 | "authToken":"[dict get $AuthAnon]" |
| 223 | } |
| 224 | }] |
| 225 | fossil_json --json-input u2 |
| 226 | test_json_envelope_ok json-cap-env |
| 227 | #puts [dict get $JR payload] |
| 228 | |
| 229 | #### BRANCHES |
| 230 | #### CONFIG |
| 231 | #### DIFFS |
| 232 | #### DIRECTORY LISTING |
| 233 | #### FILE INFO |
| 234 | #### QUERY |
| 235 |
| --- test/json.test | |
| +++ test/json.test | |
| @@ -131,11 +131,10 @@ | |
| 131 | fossil_http_json /json/HAI |
| 132 | test_json_envelope_ok json-http-HAI |
| 133 | test_json_payload json-http-HAI $HAIfields {} |
| 134 | test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 135 | |
| 136 | fossil_json version |
| 137 | test_json_envelope_ok json-version |
| 138 | test_json_payload json-version $HAIfields {} |
| 139 | test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713} |
| 140 | |
| @@ -159,11 +158,11 @@ | |
| 158 | test_json_envelope_ok json-artifact-file-env |
| 159 | test json-artifact-file {[dict get $JR payload type] eq "file"} |
| 160 | test_json_payload json-artifact [concat type uuid size checkins] {} |
| 161 | |
| 162 | # json artifact (wiki) |
| 163 | fossil wiki create Empty empty |
| 164 | fossil_json wiki get Empty |
| 165 | test json-wiki-get {[dict get $JR payload name] eq "Empty"} |
| 166 | set uuid [dict get $JR payload uuid] |
| 167 | fossil_json artifact $uuid |
| 168 | test_json_envelope_ok json-artifact-wiki-env |
| @@ -194,10 +193,16 @@ | |
| 193 | }] |
| 194 | fossil_json --json-input anon-1 |
| 195 | test_json_envelope_ok json-login-a-env |
| 196 | test_json_payload json-login-a {authToken name capabilities loginCookieName} {} |
| 197 | set AuthAnon [dict get $JR payload] |
| 198 | proc test_hascaps {testname need caps} { |
| 199 | foreach n [split $need {}] { |
| 200 | test $testname-$n {[string first $n $caps] >= 0} |
| 201 | } |
| 202 | } |
| 203 | test_hascaps json-login-c "hmnc" [dict get $AuthAnon capabilities] |
| 204 | |
| 205 | fossil user new U1 User-1 Uone |
| 206 | fossil user capabilities U1 s |
| 207 | write_file u1 { |
| 208 | { |
| @@ -210,25 +215,50 @@ | |
| 215 | } |
| 216 | fossil_json --json-input u1 |
| 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 |
| 236 | # moot from CLI. |
| 237 | test json-cap-CLI {[dict get $JR payload permissionFlags setup]} |
| 238 | |
| 239 | test TODO-JSON-POST-AUTHENTICATION false knownBug |
| 240 | #TODO: implement support for POST with JSON payload from file |
| 241 | #fossil_http_post_json /json anon-2 |
| 242 | #test_json_envelope_ok json-cap-http-env |
| 243 | #test json-cap-http {![dict get $JR payload permissionFlags setup]} |
| 244 | |
| 245 | # whoami |
| 246 | # via CLI with no auth token supplied |
| 247 | fossil_json whoami |
| 248 | test_json_envelope_ok json-whoami-cli-env |
| 249 | test_json_payload json-whoami-cli {name capabilities} {} |
| 250 | test json-whoami-cli-name {[dict get $JR payload name] eq "nobody"} |
| 251 | test_hascaps json-whoami-cli-cap "gjorz" [dict get $JR payload capabilities] |
| 252 | |
| 253 | #### BRANCHES |
| 254 | fossil_json branch list |
| 255 | test_json_envelope_ok json-branch-list-env |
| 256 | test_json_payload json-branch-list {range current branches} {} |
| 257 | |
| 258 | |
| 259 | |
| 260 | #### CONFIG |
| 261 | #### DIFFS |
| 262 | #### DIRECTORY LISTING |
| 263 | #### FILE INFO |
| 264 | #### QUERY |
| 265 |