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.

rberteig 2016-01-28 20:21 rberteig-json-test
Commit bab84bd74237641cb7a2597945f575955786884e
1 file changed +38 -8
+38 -8
--- test/json.test
+++ test/json.test
@@ -131,11 +131,10 @@
131131
fossil_http_json /json/HAI
132132
test_json_envelope_ok json-http-HAI
133133
test_json_payload json-http-HAI $HAIfields {}
134134
test json-http-HAI-api {[dict get $JR payload jsonApiVersion] >= 20120713}
135135
136
-
137136
fossil_json version
138137
test_json_envelope_ok json-version
139138
test_json_payload json-version $HAIfields {}
140139
test json-version-api {[dict get $JR payload jsonApiVersion] >= 20120713}
141140
@@ -159,11 +158,11 @@
159158
test_json_envelope_ok json-artifact-file-env
160159
test json-artifact-file {[dict get $JR payload type] eq "file"}
161160
test_json_payload json-artifact [concat type uuid size checkins] {}
162161
163162
# json artifact (wiki)
164
-fossil wiki create Empty <<""
163
+fossil wiki create Empty empty
165164
fossil_json wiki get Empty
166165
test json-wiki-get {[dict get $JR payload name] eq "Empty"}
167166
set uuid [dict get $JR payload uuid]
168167
fossil_json artifact $uuid
169168
test_json_envelope_ok json-artifact-wiki-env
@@ -194,10 +193,16 @@
194193
}]
195194
fossil_json --json-input anon-1
196195
test_json_envelope_ok json-login-a-env
197196
test_json_payload json-login-a {authToken name capabilities loginCookieName} {}
198197
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]
199204
200205
fossil user new U1 User-1 Uone
201206
fossil user capabilities U1 s
202207
write_file u1 {
203208
{
@@ -210,25 +215,50 @@
210215
}
211216
fossil_json --json-input u1
212217
test_json_envelope_ok json-login-u1-env
213218
test_json_payload json-login-u1 {authToken name capabilities loginCookieName} {}
214219
set AuthU1 [dict get $JR payload]
215
-#puts $AuthAnon
216
-#puts $AuthU1
220
+test_hascaps json-login-c "s" [dict get $AuthU1 capabilities]
217221
218222
# 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 {
221229
{"command":"cap",
222230
"authToken":"[dict get $AuthAnon]"
223231
}
224232
}]
225
-fossil_json --json-input u2
233
+fossil_json --json-input anon-2
226234
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]
228252
229253
#### 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
+
230260
#### CONFIG
231261
#### DIFFS
232262
#### DIRECTORY LISTING
233263
#### FILE INFO
234264
#### QUERY
235265
--- 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

Keyboard Shortcuts

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