Fossil SCM

fossil-scm / test / config.test
Blame History Raw 1588 lines
1
#
2
# Copyright (c) 2026 Dan Mestas
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the Simplified BSD License (also
6
# known as the "2-Clause License" or "FreeBSD License".)
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but without any warranty; without even the implied warranty of
10
# merchantability or fitness for a particular purpose.
11
#
12
############################################################################
13
#
14
# Tests of "fossil configuration": the methods export, import, merge and
15
# reset on every configuration area, the files they write and read, the
16
# files they refuse, and the configuration that push, pull and sync carry
17
# between repositories, with and without the capabilities the other side
18
# asks for. After each command the configuration of the area must be what
19
# the command is documented to leave, and the rest of the repository must
20
# be as it was.
21
#
22
23
# The first sections run at every level, and the rest need
24
# -assurance ci or stress.
25
require_no_open_checkout
26
27
test_setup ""
28
set configDir [pwd]
29
set ::env(FOSSIL_USER) tester
30
31
###############################################################################
32
# Helpers.
33
34
# Run SQL in repository REPO and return its output without the final
35
# newline.
36
proc configSql {repo sql} {
37
return [fossil_sql $sql $repo]
38
}
39
40
# Make an empty repository FILE and give its settings a time long before
41
# any that the tests write, so that a test sees only what it set.
42
proc configNew {file} {
43
fossil new $file
44
fossil sql -R $file "UPDATE config SET mtime=1"
45
return $file
46
}
47
48
# Run "fossil" with ARGS and keep standard error in RESULT; CODE is the exit
49
# status.
50
proc configRun {args} {
51
fossil_raw -seconds 120 {*}$args
52
}
53
54
# The names, in each area, of the settings that sit in the CONFIG table.
55
# The settings that "th1-uri-regexp" names belong to the skin, ticket and
56
# transfer areas together.
57
set configNames(skin) {
58
css header mainmenu footer details js default-skin logo-mimetype
59
logo-image background-mimetype background-image icon-mimetype icon-image
60
timeline-date-format timeline-default-style timeline-dwelltime
61
timeline-closetime timeline-hard-newlines timeline-max-comment
62
timeline-plaintext timeline-truncate-at-blank timeline-tslink-info
63
timeline-utc adunit adunit-omit-if-admin adunit-omit-if-user default-csp
64
sitemap-extra safe-html th1-uri-regexp
65
}
66
set configNames(css) {css}
67
set configNames(project) {
68
project-name short-project-name project-description index-page manifest
69
binary-glob clean-glob ignore-glob keep-glob crlf-glob crnl-glob
70
encoding-glob empty-dirs dotfiles parent-project-code parent-project-name
71
hash-policy comment-format mimetypes forbid-delta-manifests mv-rm-files
72
forum-statuses path-to-tag
73
}
74
set configNames(ticket) {
75
ticket-table ticket-common ticket-change ticket-newpage ticket-viewpage
76
ticket-editpage ticket-reportlist ticket-report-template
77
ticket-key-template ticket-title-expr ticket-closed-expr th1-uri-regexp
78
}
79
set configNames(user) {user-color-map}
80
set configNames(xfer) {
81
xfer-common-script xfer-push-script xfer-commit-script xfer-ticket-script
82
th1-uri-regexp
83
}
84
85
# The tables each area holds besides settings: rpt is the ticket
86
# reports, usr the users, cnc the concealed email addresses, shn the shunned
87
# artifacts, sub the subscribers. alias and interwiki are settings whose
88
# names have a fixed beginning.
89
set configTables(skin) {}
90
set configTables(css) {}
91
set configTables(project) {}
92
set configTables(ticket) rpt
93
set configTables(user) usr
94
set configTables(email) cnc
95
set configTables(shun) shn
96
set configTables(xfer) {}
97
set configTables(alias) {}
98
set configTables(interwiki) {}
99
set configTables(subscriber) sub
100
set configTables(all) {rpt usr cnc shn sub}
101
set configAreas {skin css project ticket user email shun xfer alias interwiki
102
subscriber all}
103
104
# The SQL condition that selects the settings of AREA by name.
105
proc configCond {area} {
106
global configNames
107
set parts {}
108
switch -- $area {
109
all {
110
foreach a {skin project ticket user xfer} {
111
lappend parts [configCond $a]
112
}
113
lappend parts [configCond alias] [configCond interwiki]
114
}
115
alias {lappend parts "name GLOB 'walias:/*'"}
116
interwiki {lappend parts "name GLOB 'interwiki:*'"}
117
email - shun - subscriber {lappend parts 0}
118
default {
119
lappend parts "name IN ('[join $configNames($area) {','}]')"
120
}
121
}
122
return "([join $parts { OR }])"
123
}
124
125
# A setting that is empty or absent has no time that a test can know: the
126
# repository makes a new "hash-policy" when it is opened. MASK hides its time.
127
# The SQL that lists what repository holds in the tables TABLES. With
128
# EXPORTED set, only the rows that an export sends: those with a time of
129
# last change, and the verified subscribers. A repository that has no
130
# SUBSCRIBER table has no subscribers: the statement then reads an empty
131
# table of that name in a database attached after the repository.
132
proc configTableSql {tables exported} {
133
set m [expr {$exported ? "WHERE mtime IS NOT NULL" : ""}]
134
set sql ""
135
if {"sub" in $tables} {
136
append sql "ATTACH ':memory:' AS nosub;
137
CREATE TABLE nosub.subscriber(semail, suname, sdigest, sdonotcall,
138
ssub, sctime, smip, mtime, sverified);"
139
}
140
foreach t $tables {
141
switch -- $t {
142
rpt {append sql "SELECT 'rpt', owner, title, mtime, quote(cols),
143
quote(sqlcode), quote(ifnull(jx,'{}')) FROM reportfmt $m ORDER BY title;"}
144
usr {append sql "SELECT 'usr', login, quote(pw), quote(cap),
145
quote(info), quote(photo), quote(ifnull(jx,'{}')), mtime FROM user $m
146
ORDER BY login;"}
147
cnc {append sql "SELECT 'cnc', hash, quote(content), mtime
148
FROM concealed $m ORDER BY hash;"}
149
shn {append sql "SELECT 'shn', uuid, quote(scom), mtime
150
FROM shun $m ORDER BY uuid;"}
151
sub {
152
append sql "SELECT 'sub', semail, quote(suname), quote(sdigest),
153
quote(sdonotcall), quote(ssub), quote(sctime), quote(smip), mtime
154
FROM subscriber WHERE sverified [expr {$exported ? {AND mtime
155
IS NOT NULL} : {}}] ORDER BY semail;"
156
}
157
}
158
}
159
return $sql
160
}
161
162
# What REPO holds for AREA: the settings and the tables.
163
proc configState {repo area {exported 0} {mask 0}} {
164
global configTables
165
set t [expr {$mask ? "CASE WHEN name='hash-policy' THEN 0 ELSE mtime END"
166
: "mtime"}]
167
set sql "SELECT 'cfg', name, quote(value), $t FROM config
168
WHERE [configCond $area] ORDER BY name;"
169
append sql [configTableSql $configTables($area) $exported]
170
return [configSql $repo $sql]
171
}
172
173
# What REPO holds outside AREA, to see that a command left it alone.
174
proc configOutside {repo area} {
175
global configTables
176
set sql "SELECT 'cfg', name, quote(value), mtime FROM config
177
WHERE NOT [configCond $area] ORDER BY name;"
178
set tables {}
179
foreach t {rpt usr cnc shn sub} {
180
if {$t ni $configTables($area)} {lappend tables $t}
181
}
182
append sql [configTableSql $tables 0]
183
return [configSql $repo $sql]
184
}
185
186
# The kinds of card that an export file holds, in order and without
187
# repeats.
188
proc configKinds {file} {
189
set kinds {}
190
foreach line [split [read_file $file] \n] {
191
if {[regexp {^config (/[a-z]+) [0-9]+$} $line -> kind]} {
192
lappend kinds $kind
193
}
194
}
195
return [lsort -unique $kinds]
196
}
197
198
# Insert settings into REPO. ROWS is a list of names and SQL expressions;
199
# the times of last change count up from MTIME.
200
proc configPut {repo rows mtime} {
201
set sql ""
202
foreach {name expr} $rows {
203
append sql "INSERT OR REPLACE INTO config(name,value,mtime)
204
VALUES('$name',$expr,$mtime);"
205
incr mtime
206
}
207
fossil sql -R $repo $sql
208
}
209
210
###############################################################################
211
# The repository whose configuration the tests export: every area has
212
# something in it, with the awkward values that a configuration holds:
213
# quotes, line ends, characters beyond ASCII and binary content.
214
215
set configSkin {
216
css {'body { color: #123; }'}
217
header {'<html>
218
<head><title>It''s "quoted"</title></head>
219
'}
220
mainmenu {'[["Home","/home"]]'}
221
footer {'caf' || char(233) || ' ' || char(8364)}
222
details {''}
223
js {'var a = ''b'';'}
224
default-skin {'plain'}
225
logo-mimetype {'image/png'}
226
logo-image {x'89504e470d0a1a0a0000'}
227
background-mimetype {'image/jpeg'}
228
background-image {x'ffd8ffe000104a46'}
229
icon-mimetype {'image/x-icon'}
230
icon-image {x'00000100'}
231
timeline-date-format {'2'}
232
timeline-default-style {'compact'}
233
timeline-dwelltime {'8'}
234
timeline-closetime {'9'}
235
timeline-hard-newlines {'1'}
236
timeline-max-comment {'77'}
237
timeline-plaintext {'1'}
238
timeline-truncate-at-blank {'1'}
239
timeline-tslink-info {'1'}
240
timeline-utc {'0'}
241
adunit {'<b>an ad</b>'}
242
adunit-omit-if-admin {'1'}
243
adunit-omit-if-user {'1'}
244
default-csp {'default-src ''self'''}
245
sitemap-extra {'3'}
246
safe-html {'1'}
247
th1-uri-regexp {'/ok/*'}
248
}
249
set configProject {
250
project-name {'Alpha'}
251
short-project-name {'AP'}
252
project-description {'The first line.
253
The second line.'}
254
index-page {'/home'}
255
manifest {'on'}
256
binary-glob {'*.bin,*.dat'}
257
clean-glob {'*.o'}
258
ignore-glob {'*.tmp'}
259
keep-glob {'keep/*'}
260
crlf-glob {'*.bat'}
261
crnl-glob {'*.cmd'}
262
encoding-glob {'*.txt'}
263
empty-dirs {'docs'}
264
dotfiles {'1'}
265
parent-project-code {'0123456789abcdef0123456789abcdef01234567'}
266
parent-project-name {'Parent'}
267
comment-format {'1'}
268
mimetypes {'*.x=text/x-x'}
269
forbid-delta-manifests {'1'}
270
mv-rm-files {'1'}
271
forum-statuses {'open,closed'}
272
path-to-tag {'1'}
273
}
274
set configXfer {
275
xfer-common-script {'proc common {} {return 1}'}
276
xfer-push-script {'proc push {} {return 2}'}
277
xfer-commit-script {'proc commit {} {return 3}'}
278
xfer-ticket-script {'proc ticket {} {return 4}'}
279
}
280
set configAlias {
281
walias:/docs {'/doc/trunk/www/index.wiki'}
282
walias:/news {'/forum'}
283
}
284
set configInterwiki {
285
interwiki:wp {'https://en.wikipedia.org/wiki/%s'}
286
interwiki:gh {'https://github.com/%s'}
287
}
288
289
# The ticket configuration needs a ticket table that works: the default
290
# one with a column added.
291
proc configTicketTable {repo} {
292
set sql [configSql $repo "SELECT group_concat(sql,';') FROM sqlite_schema
293
WHERE tbl_name IN ('ticket','ticketchng') AND sql IS NOT NULL"]
294
return [string map {"comment TEXT\n)" "comment TEXT,\n zzz TEXT\n)"} $sql]
295
}
296
297
proc configFill {repo} {
298
global configSkin configProject configXfer configAlias configInterwiki
299
configPut $repo $configSkin 1700000000
300
configPut $repo $configProject 1700001000
301
configPut $repo $configXfer 1700002000
302
configPut $repo $configAlias 1700003000
303
configPut $repo $configInterwiki 1700004000
304
set table [string map {' ''} [configTicketTable $repo]]
305
configPut $repo [list \
306
ticket-table "'$table'" \
307
ticket-common {'set a 1'} \
308
ticket-change {'set b "x"'} \
309
ticket-newpage {'<h1>New</h1>'} \
310
ticket-viewpage {'<h1>View</h1>'} \
311
ticket-editpage {'<h1>Edit</h1>'} \
312
ticket-reportlist {'1'} \
313
ticket-report-template {'$a'} \
314
ticket-key-template {'k-%s'} \
315
ticket-title-expr {'title'} \
316
ticket-closed-expr {'status=''Closed'''} \
317
user-color-map {'alice=#ff0000'} \
318
] 1700005000
319
fossil sql -R $repo "
320
UPDATE user SET mtime=1700006000 WHERE login='tester';
321
INSERT INTO user(login,pw,cap,info,photo,jx,mtime)
322
VALUES('alice','pw-alice','oj','Alice <[email protected]>',
323
x'ffd8ffe0','{\"k\":1}',1700006001);
324
INSERT INTO user(login,pw,cap,info,photo,jx,mtime)
325
VALUES('bob',NULL,NULL,NULL,NULL,NULL,1700006002);
326
INSERT INTO shun(uuid,mtime,scom) VALUES
327
('0123456789abcdef0123456789abcdef01234567',1700007000,'it''s spam'),
328
('fedcba9876543210fedcba9876543210fedcba98',1700007001,NULL);
329
INSERT INTO concealed(hash,mtime,content) VALUES
330
('aaaa1111',1700008000,'[email protected]'),
331
('bbbb2222',1700008001,'[email protected]');
332
UPDATE reportfmt SET mtime=2440588 WHERE title='All Tickets';
333
INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode,jx) VALUES
334
('alice','Mine',2460000,'#ffffff Key:','SELECT 1 AS ''x''',
335
'{\"a\":2}'),
336
(NULL,'Theirs',2460001,NULL,'SELECT 2',NULL),
337
(NULL,'Bare',2460002,NULL,NULL,NULL);
338
"
339
# The subscribers arrive as cards, which create the table.
340
set card "1700009000 '[email protected]' suname 'alice' sdigest 0\
341
sdonotcall 0 ssub 'a' sctime 1700000000 smip '10.0.0.1'"
342
set card2 "1700009001 '[email protected]' suname NULL sdigest 1\
343
sdonotcall 1 ssub 'ctw' sctime 1700000001 smip NULL"
344
write_file subscribers.cfg "config /subscriber [string length $card]\n$card\n\
345
config /subscriber [string length $card2]\n$card2\n"
346
fossil config merge subscribers.cfg -R $repo
347
fossil sql -R $repo "INSERT INTO subscriber(semail,mtime,sverified)
348
VALUES('[email protected]',1700009002,0)"
349
}
350
351
configNew a.fossil
352
configFill a.fossil
353
fossil sql -R a.fossil "UPDATE config SET mtime=1700010000
354
WHERE name IN ('project-code')"
355
test config-fill-complete {[configSql a.fossil "SELECT count(*) FROM config
356
WHERE name IN ('header','project-name','ticket-table','xfer-push-script',
357
'walias:/docs','interwiki:wp','user-color-map')"] == 7}
358
test config-fill-subscribers {[configSql a.fossil "SELECT count(*) FROM
359
subscriber"] == 3}
360
361
###############################################################################
362
# Export: each area writes a file that starts with a comment naming the area
363
# and the repository, holds cards for that area only, and changes nothing.
364
365
set configKindsOf(skin) /config
366
set configKindsOf(css) /config
367
set configKindsOf(project) /config
368
set configKindsOf(ticket) {/config /reportfmt}
369
set configKindsOf(user) {/config /user}
370
set configKindsOf(email) /concealed
371
set configKindsOf(shun) /shun
372
set configKindsOf(xfer) /config
373
set configKindsOf(alias) /config
374
set configKindsOf(interwiki) /config
375
set configKindsOf(subscriber) /subscriber
376
set configKindsOf(all) {/concealed /config /reportfmt /shun /subscriber /user}
377
378
set configBefore [configSql a.fossil "SELECT 'c',name,mtime FROM config
379
ORDER BY name"]
380
foreach configArea $configAreas {
381
set configFile export-$configArea.cfg
382
configRun configuration export $configArea $configFile -R a.fossil
383
test config-export-$configArea {$CODE == 0 && $RESULT eq ""}
384
set configText [read_file $configFile]
385
test_match config-export-$configArea-header $configText \
386
[join [list \
387
"^# The \"$configArea\" configuration exported from\n" \
388
"# repository \"a.fossil\"\n# on \[0-9-\]+ \[0-9:\]+\n"] ""]
389
test_eq config-export-$configArea-cards [configKinds $configFile] \
390
[lsort $configKindsOf($configArea)]
391
}
392
test_eq config-export-changes-nothing [configSql a.fossil "SELECT 'c',name,mtime
393
FROM config ORDER BY name"] $configBefore
394
395
if {[test_assurance] eq "smoke"} {
396
test_skip "the tests after the first sections need -assurance ci or stress"
397
}
398
399
###############################################################################
400
# Import: an area exported from one repository and imported into another
401
# makes the second hold what the first holds, in that area, with the times
402
# of last change. The tables of the area are replaced, so that a row that
403
# only the importing side held is gone. Nothing outside the area changes.
404
# Reset: the area is back at its defaults, the command names a file that
405
# restores what was there, and importing that file does so.
406
407
# What an area has once it is reset.
408
proc configDefaults {area} {
409
global configDefault
410
if {![info exists configDefault]} {
411
configNew defaults.fossil
412
foreach a {skin css project ticket user email shun xfer alias interwiki
413
subscriber all} {
414
set configDefault($a) [configState defaults.fossil $a 0 1]
415
}
416
}
417
return $configDefault($area)
418
}
419
420
# A row in the tables of AREA that the exporting repository lacks, for the
421
# importing one.
422
proc configDecoy {repo area} {
423
switch -- $area {
424
ticket {fossil sql -R $repo "INSERT INTO reportfmt(owner,title,mtime)
425
VALUES('x','Decoy',2450000)"}
426
user {fossil sql -R $repo "INSERT INTO user(login,cap,mtime)
427
VALUES('decoy','o',5)"}
428
email {fossil sql -R $repo "INSERT INTO concealed(hash,mtime,content)
429
VALUES('decoy',5,'[email protected]')"}
430
shun {fossil sql -R $repo "INSERT INTO shun(uuid,mtime,scom)
431
VALUES('decoy',5,'x')"}
432
subscriber {fossil sql -R $repo "INSERT INTO subscriber(semail,mtime)
433
VALUES('[email protected]',5)"}
434
all {
435
foreach a {ticket user email shun subscriber} {configDecoy $repo $a}
436
}
437
}
438
}
439
440
foreach configArea $configAreas {
441
set configB b-$configArea.fossil
442
configNew $configB
443
if {$configArea eq "subscriber" || $configArea eq "all"} {
444
# A table that is there already, with a row only this side holds.
445
fossil config merge subscribers.cfg -R $configB
446
fossil sql -R $configB "DELETE FROM subscriber"
447
}
448
configDecoy $configB $configArea
449
set configOut [configOutside $configB $configArea]
450
set configExp [configState a.fossil $configArea 1]
451
test config-$configArea-has-content {$configExp ne ""}
452
453
configRun configuration import export-$configArea.cfg -R $configB
454
test config-import-$configArea {$CODE == 0 && $RESULT eq ""}
455
test_eq config-import-$configArea-same [configState $configB $configArea] \
456
$configExp
457
test_eq config-import-$configArea-outside \
458
[configOutside $configB $configArea] $configOut
459
if {$configArea eq "ticket" || $configArea eq "all"} {
460
# The ticket tables are rebuilt from the imported ticket-table.
461
test_eq config-import-$configArea-ticket-table [configSql $configB "SELECT
462
count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 1
463
}
464
fossil test-integrity -R $configB
465
test config-import-$configArea-integrity {$CODE == 0}
466
467
# Reset.
468
set configPre [configState $configB $configArea]
469
set configOut [configOutside $configB $configArea]
470
configRun configuration reset $configArea -R $configB
471
test config-reset-$configArea {$CODE == 0 &&
472
[string first "Configuration reset to factory defaults." $RESULT] >= 0}
473
set configResetOut $RESULT
474
test_eq config-reset-$configArea-outside \
475
[configOutside $configB $configArea] $configOut
476
unset -nocomplain configBackup
477
regexp {import (config-backup-[0-9.]+)} $configResetOut -> configBackup
478
test config-reset-$configArea-backup {[info exists configBackup] &&
479
[file exists $configBackup]}
480
if {$configArea eq "user" || $configArea eq "all"} {
481
# The default users come back, and the user who ran the command is
482
# their administrator.
483
test_eq config-reset-$configArea-users \
484
[configSql $configB "SELECT login, cap, mtime
485
FROM user ORDER BY login"] \
486
"anonymous|hz|\ndeveloper|ei|\nnobody|gjorz|\nreader|kptw|\ntester|s|"
487
}
488
if {$configArea ni {alias interwiki all user}} {
489
test_eq config-reset-$configArea-state \
490
[configState $configB $configArea 0 1] \
491
[configDefaults $configArea]
492
}
493
if {$configArea eq "ticket" || $configArea eq "all"} {
494
test_eq config-reset-$configArea-ticket-table [configSql $configB "SELECT
495
count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 0
496
}
497
if {$configArea eq "subscriber" || $configArea eq "all"} {
498
test_eq config-reset-$configArea-subscribers \
499
[configSql $configB "SELECT count(*)
500
FROM subscriber"] 0
501
}
502
configRun configuration import $configBackup -R $configB
503
test config-reset-$configArea-recover {$CODE == 0}
504
test_eq config-reset-$configArea-recovered \
505
[configState $configB $configArea] $configPre
506
test_eq config-reset-$configArea-recovered-outside \
507
[configOutside $configB $configArea] \
508
$configOut
509
}
510
511
512
###############################################################################
513
# Reset removes the URL aliases and the inter-wiki prefixes with their areas.
514
515
foreach configArea {alias interwiki} {
516
configNew r-$configArea.fossil
517
configFill r-$configArea.fossil
518
configRun configuration reset $configArea -R r-$configArea.fossil
519
test_eq config-reset-$configArea-removes \
520
[configState r-$configArea.fossil $configArea 0 1] \
521
[configDefaults $configArea]
522
}
523
configNew r-all.fossil
524
configFill r-all.fossil
525
configRun configuration reset all -R r-all.fossil
526
test config-reset-all-removes-aliases {[configSql r-all.fossil "SELECT count(*)
527
FROM config WHERE name GLOB 'walias:/*' OR name GLOB 'interwiki:*'"] == 0}
528
test_eq config-reset-all-settings [configSql r-all.fossil "SELECT group_concat(
529
name) FROM (SELECT name FROM config WHERE NOT name GLOB 'walias:/*' AND
530
NOT name GLOB 'interwiki:*' ORDER BY name)"] \
531
"aux-schema,content-schema,hash-policy,project-code,rebuilt,server-code"
532
533
# Reset on a repository that has no subscriber table is no error.
534
configNew r-empty.fossil
535
configRun configuration reset subscriber -R r-empty.fossil
536
test config-reset-no-subscriber-table {$CODE == 0}
537
configRun configuration reset all -R r-empty.fossil
538
test config-reset-all-empty {$CODE == 0}
539
foreach configPart {skin project ticket xfer alias interwiki email shun
540
subscriber} {
541
test_eq config-reset-all-empty-$configPart \
542
[configState r-empty.fossil $configPart 0 1] [configDefaults $configPart]
543
}
544
test_eq config-reset-all-empty-users [configSql r-empty.fossil "SELECT
545
group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] \
546
"anonymous,developer,nobody,reader,tester"
547
test_eq config-reset-all-empty-reports [configSql r-empty.fossil "SELECT
548
group_concat(title) FROM reportfmt"] "All Tickets"
549
configRun configuration export all r-empty.cfg -R r-empty.fossil
550
test config-export-all-empty {$CODE == 0 &&
551
[configKinds r-empty.cfg] eq "/config /reportfmt"}
552
configRun configuration export subscriber r-empty-sub.cfg -R r-empty.fossil
553
test config-export-subscriber-no-table {$CODE == 0 &&
554
[configKinds r-empty-sub.cfg] eq ""}
555
556
###############################################################################
557
# A ticket report whose time of change has a fraction, as the time of the
558
# default report has, comes back from an export.
559
# knownBug: the card of such a report is refused, because its first token
560
# must be a whole number.
561
562
configNew f-a.fossil
563
configNew f-b.fossil
564
fossil sql -R f-a.fossil "INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode)
565
VALUES('o','Fractional',julianday('now'),'','SELECT 1')"
566
configRun configuration export ticket f-a.cfg -R f-a.fossil
567
configRun configuration merge f-a.cfg -R f-b.fossil
568
test config-merge-report-fraction {[configSql f-b.fossil "SELECT count(*)
569
FROM reportfmt WHERE title='Fractional'"] == 1} knownBug
570
configRun configuration import f-a.cfg -R f-b.fossil
571
test config-import-report-fraction {[configSql f-b.fossil "SELECT count(*)
572
FROM reportfmt WHERE title='Fractional'"] == 1} knownBug
573
574
###############################################################################
575
# Export of changes since a time: only what changed since then is written.
576
577
configRun configuration export project since.cfg --since 2099-01-01 \
578
-R a.fossil
579
test config-export-since-future {$CODE == 0 && [configKinds since.cfg] eq ""}
580
configRun configuration export project since2.cfg --since 2000-01-01 \
581
-R a.fossil
582
test config-export-since-past {$CODE == 0 &&
583
[configKinds since2.cfg] eq "/config"}
584
585
###############################################################################
586
# Names of areas and methods: an abbreviation that starts the name is
587
# enough. An unknown area lists the areas and writes nothing.
588
589
foreach {configAbbrev configArea} \
590
{sk skin pro project t ticket u user e email sh shun
591
a alias al alias all all su subscriber i interwiki
592
x xfer c css} {
593
file delete abbrev.cfg
594
configRun configuration export $configAbbrev abbrev.cfg -R a.fossil
595
test config-area-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]}
596
# Everything after the header, which names the area and the time.
597
test_eq config-area-abbrev-$configAbbrev-same \
598
[lrange [split [read_file abbrev.cfg] \n] 3 end] \
599
[lrange [split [read_file export-$configArea.cfg] \n] 3 end]
600
}
601
file delete abbrev.cfg
602
foreach configBad {nosuch skinx ALL Skin} {
603
configRun configuration export $configBad abbrev.cfg -R a.fossil
604
test config-area-unknown-$configBad {$CODE == 1 &&
605
[holds_strings $RESULT [list \
606
"no such configuration area: \"$configBad\"" \
607
"Available configuration areas:" \
608
" skin Web interface appearance settings"]] &&
609
![file exists abbrev.cfg]}
610
}
611
foreach configMethod {reset pull push sync} {
612
configRun configuration $configMethod nosuch -R a.fossil
613
test config-area-unknown-$configMethod {$CODE == 1 &&
614
[string first "no such configuration area: \"nosuch\"" $RESULT] >= 0}
615
}
616
617
# The methods accept abbreviations too.
618
foreach {configAbbrev configFull} {exp export e export ex export} {
619
file delete abbrev.cfg
620
configRun configuration $configAbbrev skin abbrev.cfg -R a.fossil
621
test config-method-abbrev-$configAbbrev \
622
{$CODE == 0 && [file exists abbrev.cfg]}
623
}
624
configNew m-abbrev.fossil
625
foreach {configAbbrev configTag} \
626
{i import im import imp import m merge me merge mer merge} {
627
configRun configuration $configAbbrev export-skin.cfg -R m-abbrev.fossil
628
test config-method-abbrev-$configAbbrev {$CODE == 0 &&
629
[configSql m-abbrev.fossil "SELECT value FROM config
630
WHERE name='css'"] eq "body { color: #123; }"}
631
fossil sql -R m-abbrev.fossil "DELETE FROM config WHERE name='css'"
632
}
633
configRun configuration res skin -R m-abbrev.fossil
634
test config-method-abbrev-res {$CODE == 0 &&
635
[string first "Configuration reset" $RESULT] >= 0}
636
configRun configuration r skin -R m-abbrev.fossil
637
test config-method-abbrev-r {$CODE == 0 &&
638
[string first "Configuration reset" $RESULT] >= 0}
639
640
# Wrong numbers of arguments and unknown methods.
641
foreach {configNm configArgs} {
642
none {}
643
export-no-file {export skin}
644
export-too-many {export skin x.cfg y}
645
export-none {export}
646
import-none {import}
647
import-too-many {import a b}
648
merge-none {merge}
649
merge-too-many {merge a b}
650
reset-none {reset}
651
reset-too-many {reset skin skin}
652
pull-none {pull}
653
pull-too-many {pull skin a b}
654
push-none {push}
655
sync-none {sync}
656
} {
657
configRun configuration {*}$configArgs -R a.fossil
658
test config-usage-$configNm \
659
{$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
660
}
661
configRun configuration frobnicate -R a.fossil
662
test config-method-unknown {$CODE == 1 &&
663
[string first \
664
"METHOD should be one of: export import merge pull push reset"\
665
$RESULT] >= 0}
666
configRun configuration import nosuchfile.cfg -R a.fossil
667
test config-import-no-file {$CODE == 1}
668
669
670
###############################################################################
671
# Merge: a value that the file has is taken where the repository has none
672
# or an older one; a value that the repository changed at the same time or
673
# later is kept. Nothing is removed.
674
675
# A card for TABLE with TEXT as its content.
676
proc configCard {table text} {
677
return "config /$table [string length $text]\n$text\n"
678
}
679
680
configNew m.fossil
681
fossil config merge subscribers.cfg -R m.fossil
682
fossil sql -R m.fossil "
683
INSERT INTO config(name,value,mtime) VALUES
684
('css','local-css',1800000000),
685
('header','local-header',5),
686
('mainmenu','local-menu',1700000002),
687
('walias:/docs','local-alias',1800000000),
688
('walias:/only','only-here',5);
689
INSERT INTO user(login,pw,cap,info,mtime) VALUES
690
('alice','local-pw','x','local',1800000000),
691
('only','p','o','',5);
692
UPDATE user SET cap='o' WHERE login='tester';
693
INSERT INTO shun(uuid,mtime,scom) VALUES
694
('0123456789abcdef0123456789abcdef01234567',5,'old'),
695
('only',5,'only here');
696
INSERT INTO concealed(hash,mtime,content) VALUES
697
('aaaa1111',1800000000,'[email protected]'),
698
('only',5,'[email protected]');
699
INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode) VALUES
700
('local','Mine',2400000,'','SELECT 0'),
701
('local','Only',2400000,'','SELECT 0');
702
UPDATE subscriber SET suname='local', mtime=1800000000
703
WHERE semail='[email protected]';
704
INSERT INTO subscriber(semail,mtime) VALUES('[email protected]',5);
705
"
706
configRun configuration merge export-all.cfg -R m.fossil
707
test config-merge {$CODE == 0 && $RESULT eq ""}
708
proc configMergeCheck {name sql expected} {
709
test_eq config-merge-$name [configSql m.fossil $sql] $expected
710
}
711
configMergeCheck newer-local-kept "SELECT value FROM config WHERE name='css'" \
712
local-css
713
configMergeCheck older-local-replaced "SELECT value||'|'||mtime FROM config
714
WHERE name='header'" \
715
"<html>\n<head><title>It's \"quoted\"</title></head>\n|1700000001"
716
configMergeCheck equal-time-local-kept "SELECT value FROM config
717
WHERE name='mainmenu'" local-menu
718
configMergeCheck absent-added "SELECT value FROM config WHERE name='js'" \
719
"var a = 'b';"
720
configMergeCheck alias-newer-local-kept "SELECT value FROM config
721
WHERE name='walias:/docs'" local-alias
722
configMergeCheck alias-absent-added "SELECT value FROM config
723
WHERE name='walias:/news'" /forum
724
configMergeCheck interwiki-added "SELECT value FROM config
725
WHERE name='interwiki:wp'" "https://en.wikipedia.org/wiki/%s"
726
configMergeCheck local-only-alias-kept "SELECT value FROM config
727
WHERE name='walias:/only'" only-here
728
configMergeCheck user-newer-local-kept "SELECT pw||cap||info FROM user
729
WHERE login='alice'" "local-pwxlocal"
730
configMergeCheck user-absent-added "SELECT count(*) FROM user
731
WHERE login='bob' AND mtime=1700006002" 1
732
configMergeCheck user-local-only-kept "SELECT count(*) FROM user
733
WHERE login='only'" 1
734
configMergeCheck shun-older-local-replaced "SELECT scom||'|'||mtime FROM shun
735
WHERE uuid='0123456789abcdef0123456789abcdef01234567'" \
736
"it's spam|1700007000"
737
configMergeCheck shun-absent-added "SELECT count(*) FROM shun
738
WHERE uuid='fedcba9876543210fedcba9876543210fedcba98' AND scom IS NULL" 1
739
configMergeCheck shun-local-only-kept "SELECT count(*) FROM shun
740
WHERE uuid='only'" 1
741
configMergeCheck concealed-newer-local-kept "SELECT content FROM concealed
742
WHERE hash='aaaa1111'" [email protected]
743
configMergeCheck concealed-absent-added "SELECT content FROM concealed
744
WHERE hash='bbbb2222'" [email protected]
745
configMergeCheck concealed-local-only-kept "SELECT count(*) FROM concealed
746
WHERE hash='only'" 1
747
configMergeCheck report-older-local-replaced "SELECT owner||'|'||sqlcode FROM
748
reportfmt WHERE title='Mine'" "alice|SELECT 1 AS 'x'"
749
configMergeCheck report-absent-added "SELECT count(*) FROM reportfmt
750
WHERE title='Theirs'" 1
751
configMergeCheck report-local-only-kept "SELECT count(*) FROM reportfmt
752
WHERE title='Only'" 1
753
configMergeCheck subscriber-newer-local-kept "SELECT suname FROM subscriber
754
WHERE semail='[email protected]'" local
755
configMergeCheck subscriber-absent-added "SELECT ssub FROM subscriber
756
WHERE semail='[email protected]'" ctw
757
configMergeCheck subscriber-local-only-kept "SELECT count(*) FROM subscriber
758
WHERE semail='[email protected]'" 1
759
fossil test-integrity -R m.fossil
760
test config-merge-integrity {$CODE == 0}
761
762
# The same file merged again changes nothing.
763
set configMerged [configState m.fossil all]
764
configRun configuration merge export-all.cfg -R m.fossil
765
test_eq config-merge-twice [configState m.fossil all] $configMerged
766
767
# Merge into an empty repository is import.
768
configNew m2.fossil
769
configRun configuration merge export-all.cfg -R m2.fossil
770
foreach configArea {skin project ticket xfer alias interwiki email shun
771
subscriber} {
772
test_eq config-merge-empty-$configArea [configState m2.fossil $configArea] \
773
[configState a.fossil $configArea 1]
774
}
775
776
# Import and merge write only inside one transaction: a file that stops the
777
# command leaves the repository as it was. A file with a card that SQLite
778
# cannot take (a repeated column) is such a file.
779
configNew t.fossil
780
configPut t.fossil {css {'kept'}} 1700000000
781
set configTxCard2 \
782
"1700000100 'alice' pw 'a' pw 'b' pw 'c' pw 'd' pw 'e' pw 'f' pw 'g'
783
pw 'h' pw 'i' pw 'j' pw 'k' pw 'l' pw 'm' pw 'n'"
784
write_file tx.cfg "[configCard config "1700000100 'css' value 'changed'"]\
785
[configCard user $configTxCard2]"
786
configRun configuration merge tx.cfg -R t.fossil
787
set configTxCode $CODE
788
test config-card-many-fields {$configTxCode == 0 || $configTxCode == 1}
789
fossil test-integrity -R t.fossil
790
test config-card-many-fields-integrity {$CODE == 0}
791
792
###############################################################################
793
# The literals of a card. A value is a string, a blob in hexadecimal, an
794
# integer or NULL; anything else is refused and the card does nothing.
795
796
configNew l.fossil
797
proc configLiteral {name value expected} {
798
fossil sql -R l.fossil "DELETE FROM config WHERE name='header'"
799
write_file lit.cfg [configCard config "1700000000 'header' value $value"]
800
configRun configuration merge lit.cfg -R l.fossil
801
set got [configSql l.fossil "SELECT quote(value) FROM config
802
WHERE name='header'"]
803
test_eq config-literal-$name $got $expected
804
test config-literal-$name-exit {$::CODE == 0}
805
}
806
configLiteral string {'plain'} {'plain'}
807
configLiteral string-empty {''} {''}
808
configLiteral string-quote {'it''s'} {'it''s'}
809
configLiteral string-newline "'a\nb'" "'a\nb'"
810
configLiteral blob {x'41424344'} {X'41424344'}
811
configLiteral blob-upper {X'4a4B'} {X'4A4B'}
812
configLiteral blob-empty {x''} {X''}
813
configLiteral integer {12} {'12'}
814
# Text after the closing quote of a string is a token of its own, which is
815
# no field name, so it is skipped and the string stays the value.
816
configLiteral string-trailing {'a'b'} {'a'}
817
configLiteral string-concat {'a'||'b'} {'a'}
818
configLiteral null {NULL} {NULL}
819
configLiteral null-lower {null} {NULL}
820
configLiteral null-mixed {NuLl} {NULL}
821
foreach {configNm configValue} {
822
bare-word hello
823
float 1.5
824
negative -5
825
digits-letters 12ab
826
expression {1+1}
827
blob-odd {x'abc'}
828
blob-not-hex {x'zz'}
829
blob-open {x'ab}
830
blob-no-quote {xab}
831
blob-upper-no-quote {Xab}
832
blob-short {x'}
833
string-open {'abc}
834
string-open-doubled {'abc''}
835
string-lone {'}
836
null-prefix {NULLx}
837
not-null {NUL}
838
} {
839
fossil sql -R l.fossil "DELETE FROM config WHERE name='header'"
840
write_file lit.cfg [configCard config \
841
"1700000000 'header' value $configValue"]
842
configRun configuration merge lit.cfg -R l.fossil
843
test config-literal-refused-$configNm {$CODE == 0 &&
844
[configSql l.fossil "SELECT count(*) FROM config
845
WHERE name='header'"] == 0}
846
}
847
848
849
###############################################################################
850
# Files that are not well formed. A line that is no card is skipped; a card
851
# that is not well formed does nothing, and the cards after it are read as
852
# if it were not there. Nothing is written that the card did not name.
853
854
# Everything that REPO holds, settings and tables, except the two settings
855
# that a server of the repository writes for its own use.
856
proc configDump {repo} {
857
set sql "SELECT 'cfg', name, quote(value), mtime FROM config
858
WHERE name<>'backoffice' AND name NOT GLOB 'baseurl:*'
859
ORDER BY name;"
860
append sql [configTableSql {rpt usr cnc shn sub} 0]
861
return [configSql $repo $sql]
862
}
863
864
configNew c.fossil
865
configPut c.fossil {css {'old'} js {'old'}} 1700000000
866
set configStart [configDump c.fossil]
867
set configGood [configCard config "1700000500 'footer' value 'good'"]
868
869
# Run import and merge of TEXT into a copy of c.fossil. Both must leave
870
# the repository as it was, except that the card "footer" at the end of the
871
# file, when GOOD is true, is read.
872
proc configMalformed {name text good {code 0}} {
873
global configGood configStart
874
foreach method {merge import} {
875
set repo c-$method.fossil
876
file copy -force c.fossil $repo
877
write_file bad.cfg [expr {$good ? "$text$configGood" : $text}]
878
configRun configuration $method bad.cfg -R $repo
879
test config-malformed-$name-$method-exit {$::CODE == $code}
880
if {$good} {
881
set want [configSql $repo "SELECT value FROM config WHERE name='footer';
882
DELETE FROM config WHERE name='footer'"]
883
test_eq config-malformed-$name-$method-next-card $want good
884
}
885
test_eq config-malformed-$name-$method-unchanged [configDump $repo] \
886
$configStart
887
}
888
}
889
set configBody "1700000600 'css' value 'new'\n"
890
set configLen [string length $configBody]
891
892
configMalformed empty-file "" 0
893
configMalformed only-comments "# one\n# two\n\n\n" 0
894
configMalformed junk-first-line "this is not a configuration file\n" 1
895
configMalformed binary-junk "\x01\x02\x03\n\xff\xfe\n" 1
896
configMalformed no-final-newline "config /config" 0
897
configMalformed old-format "config css 5\nhello\n" 1
898
configMalformed unknown-kind "config /nosuch $configLen\n$configBody\n" 1
899
configMalformed upper-case "CONFIG /config $configLen\n$configBody\n" 1
900
configMalformed first-char-of-kind "config Xconfig $configLen\n$configBody\n" 1
901
configMalformed no-size "config /config\n$configBody\n" 1
902
configMalformed no-kind "config\n$configBody\n" 1
903
configMalformed negative-size "config /config -5\n$configBody\n" 1
904
configMalformed size-letters "config /config 12ab\n$configBody\n" 1
905
configMalformed size-plus "config /config +$configLen\n$configBody\n" 1
906
configMalformed size-hex "config /config 0x10\n$configBody\n" 1
907
configMalformed size-float "config /config 1.5\n$configBody\n" 1
908
configMalformed size-too-big-for-int \
909
"config /config 99999999999\n$configBody\n" 1
910
configMalformed size-extra-token \
911
"config /config $configLen extra\n$configBody\n" 1
912
configMalformed size-zero "config /config 0\n\n" 1
913
configMalformed size-short "config /config 10\n$configBody\n" 1
914
configMalformed truncated-key "config /config 40\n1700000600 'cs" 0
915
configMalformed truncated-literal \
916
"config /config 40\n1700000600 'css' value 'ne\n" 0
917
foreach {configNm configCardBody} {
918
missing-mtime "'css' value 'x'\n"
919
bare-name "1700000600 css value 'x'\n"
920
name-only "1700000600\n"
921
empty-card "\n"
922
unknown-name "1700000600 'nosuch' value 'x'\n"
923
zero-byte-time "\0001700000600 'css' value 'x'\n"
924
zero-byte-name "1700000600 \000'css' value 'x'\n"
925
} {
926
configMalformed $configNm [configCard config $configCardBody] 1
927
}
928
foreach {configNm configMtime} \
929
{letters abc fraction 1.5 negative -5 hex 0x10 blank-sign +5
930
exponent 1e3 quoted '5'} {
931
set configCardBody "$configMtime 'css' value 'new'\n"
932
configMalformed mtime-$configNm \
933
"config /config [string length $configCardBody]\n$configCardBody\n" 1
934
}
935
936
# A size that is larger than the rest of the file takes the rest.
937
foreach configMethod {merge import} {
938
file copy -force c.fossil c-$configMethod.fossil
939
write_file big.cfg "config /config 100000\n$configBody"
940
configRun configuration $configMethod big.cfg -R c-$configMethod.fossil
941
test config-size-large-$configMethod {$CODE == 0 &&
942
[configSql c-$configMethod.fossil "SELECT value FROM config
943
WHERE name='css'"] eq "new"}
944
}
945
946
# A field that is not a column of the table is skipped; one that would
947
# set a column that nothing outside may set is among them.
948
configNew k.fossil
949
fossil sql -R k.fossil "INSERT INTO user(login,pw,cap,mtime)
950
VALUES('carol','pw','o',5)"
951
set configCardBody \
952
"1700000600 'carol' cap 'oj' cookie 'stolen' ipaddr '1.2.3.4'\
953
cexpire 1 uid 77 login 'mallory' bogus 'x' info 'Carol'\n"
954
write_file fields.cfg [configCard user $configCardBody]
955
configRun configuration merge fields.cfg -R k.fossil
956
test config-field-skipped {$CODE == 0}
957
test_eq config-field-skipped-row [configSql k.fossil "SELECT login, cap, info,
958
quote(cookie), quote(ipaddr), quote(cexpire), mtime FROM user
959
WHERE login IN ('carol','mallory')"] \
960
"carol|oj|Carol|NULL|NULL|NULL|1700000600"
961
test_eq config-field-skipped-uid [configSql k.fossil "SELECT count(*) FROM user
962
WHERE uid=77"] 0
963
964
# A card that holds more field pairs than the command keeps is read up to
965
# the eleventh field, and the later ones are dropped.
966
set configCardBody "1700000600 'carol'"
967
for {set configI 0} {$configI < 14} {incr configI} \
968
{append configCardBody " info 'v$configI'"}
969
write_file many.cfg [configCard user "$configCardBody\n"]
970
configRun configuration merge many.cfg -R k.fossil
971
test config-fields-many {$CODE == 0 &&
972
[configSql k.fossil "SELECT info FROM user WHERE login='carol'"] eq "Carol"}
973
fossil sql -R k.fossil "UPDATE user SET mtime=5 WHERE login='carol'"
974
configRun configuration merge many.cfg -R k.fossil
975
test_eq config-fields-many-kept [configSql k.fossil "SELECT info FROM user
976
WHERE login='carol'"] v10
977
978
# A card whose key or value is no literal does not reach the database.
979
foreach {configNm configText} {
980
semicolon {'x'; DROP TABLE shun; --}
981
quote-break {'x'');DELETE FROM user;--'}
982
subquery {(SELECT 1)}
983
function {char(65)}
984
} {
985
set configCardBody "1700000600 $configText\n"
986
write_file inj.cfg "[configCard shun $configCardBody]"
987
configRun configuration merge inj.cfg -R k.fossil
988
test config-literal-no-sql-$configNm {$CODE == 0 &&
989
[configSql k.fossil "SELECT count(*) FROM sqlite_schema
990
WHERE name IN ('shun','user')"] == 2}
991
}
992
993
###############################################################################
994
# Settings that the file may not set: the ones that no area holds (the
995
# identity of the repository and its schema), and those that carry commands
996
# and are never exported.
997
998
configNew n.fossil
999
set configNBefore [configDump n.fossil]
1000
foreach configNm {project-code server-code content-schema aux-schema rebuilt
1001
th1-setup tcl-setup email-send-command diff-command editor
1002
ssh-command nosuch head headers Header walias:docs interwiki
1003
ticket_table} {
1004
set configCardBody "1700000600 '$configNm' value 'x'\n"
1005
write_file ne.cfg [configCard config $configCardBody]
1006
configRun configuration import ne.cfg -R n.fossil
1007
test config-not-exportable-$configNm {$CODE == 0 &&
1008
[string first "Skipping non-exportable setting: '$configNm' = 'x'" \
1009
$RESULT] >= 0}
1010
test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \
1011
$configNBefore
1012
}
1013
foreach {configNm configCardBody} {
1014
number "1700000600 12 value 'x'\n"
1015
empty "1700000600 '' value 'x'\n"
1016
blob "1700000600 x'6373' value 'x'\n"
1017
null "1700000600 NULL value 'x'\n"
1018
no-value "1700000600 'nosuch'\n"
1019
} {
1020
write_file ne.cfg [configCard config $configCardBody]
1021
configRun configuration merge ne.cfg -R n.fossil
1022
test config-not-exportable-$configNm {$CODE == 0 &&
1023
[string first "Skipping non-exportable setting: " $RESULT] >= 0}
1024
if {$configNm eq "no-value"} {
1025
test config-not-exportable-no-value-said {[string first "= ?" $RESULT] >= 0}
1026
}
1027
test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \
1028
$configNBefore
1029
}
1030
1031
# Names quoted as a literal are read without the quotes; a name that holds
1032
# a quote can still be a setting of an area.
1033
set configCardBody "1700000600 'walias:/it''s' value '/x'\n"
1034
write_file ne.cfg [configCard config $configCardBody]
1035
configRun configuration merge ne.cfg -R n.fossil
1036
test_eq config-name-quoted [configSql n.fossil "SELECT value FROM config
1037
WHERE name='walias:/it''s'"] /x
1038
1039
1040
###############################################################################
1041
# Push, pull and sync with a repository named by its file: the client starts
1042
# "fossil http" on the file, so both sides speak the whole protocol and the
1043
# other side grants everything. Each area that is pulled arrives as the
1044
# other side holds it, each that is pushed is there afterwards, and nothing
1045
# outside the area changes. The users are left out of the comparison:
1046
# those that a repository made for itself have no time of change, and a
1047
# merge does not replace them.
1048
1049
set configSrv [file join $configDir a.fossil]
1050
1051
# The parts of AREA that a comparison looks at.
1052
proc configParts {area} {
1053
if {$area eq "all"} {
1054
return {skin project ticket xfer alias interwiki email shun subscriber
1055
user}
1056
}
1057
return $area
1058
}
1059
1060
# Test that REPO holds what EXPECTED holds, as an export of it, for AREA.
1061
proc configSameAs {name repo area expected} {
1062
foreach part [configParts $area] {
1063
if {$part eq "user"} {
1064
set sql "SELECT name, value, mtime FROM config
1065
WHERE name='user-color-map';
1066
SELECT login,quote(pw),cap,info,quote(photo),mtime FROM user
1067
WHERE login IN ('alice','bob') ORDER BY login"
1068
test_eq $name-$part [configSql $repo $sql] [configSql $expected $sql]
1069
} else {
1070
test_eq $name-$part [configState $repo $part] \
1071
[configState $expected $part 1]
1072
}
1073
}
1074
}
1075
1076
foreach configArea $configAreas {
1077
# Pull.
1078
set configC cl-pull-$configArea.fossil
1079
configNew $configC
1080
set configOut [configOutside $configC $configArea]
1081
set configPre [configDump $configC]
1082
configRun configuration pull $configArea $configSrv -R $configC
1083
test config-pull-$configArea {$CODE == 0}
1084
test config-pull-$configArea-changed {[configDump $configC] ne $configPre}
1085
test_eq config-pull-$configArea-outside [configOutside $configC $configArea] \
1086
$configOut
1087
configSameAs config-pull-$configArea-same $configC $configArea a.fossil
1088
fossil test-integrity -R $configC
1089
test config-pull-$configArea-integrity {$CODE == 0}
1090
1091
# Push.
1092
set configD srv-push-$configArea.fossil
1093
configNew $configD
1094
set configOut [configOutside $configD $configArea]
1095
set configPre [configDump $configD]
1096
configRun configuration push $configArea [file join $configDir $configD] \
1097
-R a.fossil
1098
test config-push-$configArea {$CODE == 0}
1099
test config-push-$configArea-changed {[configDump $configD] ne $configPre}
1100
test_eq config-push-$configArea-outside [configOutside $configD $configArea] \
1101
$configOut
1102
configSameAs config-push-$configArea-same $configD $configArea a.fossil
1103
fossil test-integrity -R $configD
1104
test config-push-$configArea-integrity {$CODE == 0}
1105
}
1106
1107
1108
# Sync sends and receives. Each side gets what only the other has, and for
1109
# a value that both have, the one changed last wins on both.
1110
configNew s1.fossil
1111
configNew s2.fossil
1112
configPut s1.fossil {walias:/only1 {'one'} walias:/both {'old-1'}
1113
walias:/tie {'tie-1'}} 1700000000
1114
fossil sql -R s1.fossil "UPDATE config SET mtime=1700000100
1115
WHERE name='walias:/both'"
1116
fossil sql -R s1.fossil "UPDATE config SET mtime=1700000300
1117
WHERE name='walias:/tie'"
1118
configPut s2.fossil {walias:/only2 {'two'} walias:/both {'new-2'}
1119
walias:/tie {'tie-2'}} 1700000000
1120
fossil sql -R s2.fossil "UPDATE config SET mtime=1700000200
1121
WHERE name='walias:/both'"
1122
fossil sql -R s2.fossil "UPDATE config SET mtime=1700000300
1123
WHERE name='walias:/tie'"
1124
configRun configuration sync alias [file join $configDir s2.fossil] -R s1.fossil
1125
test config-sync {$CODE == 0}
1126
set configAliasSql "SELECT name,value,mtime FROM config
1127
WHERE name GLOB 'walias:/*' ORDER BY name"
1128
# A value with the same time on both sides stays as each side has it.
1129
test_eq config-sync-same [configSql s1.fossil $configAliasSql] \
1130
[join [list \
1131
"walias:/both|new-2|1700000200\n" \
1132
"walias:/only1|one|1700000000\nwalias:/only2|two|1700000000\n" \
1133
"walias:/tie|tie-1|1700000300"] ""]
1134
test_eq config-sync-same-other [configSql s2.fossil $configAliasSql] \
1135
[join [list \
1136
"walias:/both|new-2|1700000200\n" \
1137
"walias:/only1|one|1700000000\nwalias:/only2|two|1700000000\n" \
1138
"walias:/tie|tie-2|1700000300"] ""]
1139
1140
# Pull with --overwrite replaces the tables of the area, so a user that only
1141
# this side has is gone; without it the user stays.
1142
configNew o1.fossil
1143
configNew o2.fossil
1144
fossil sql -R o1.fossil \
1145
"INSERT INTO user(login,cap,mtime) VALUES('local','o',7)"
1146
fossil sql -R o2.fossil \
1147
"INSERT INTO user(login,cap,mtime) VALUES('remote','o',8)"
1148
fossil sql -R o1.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x1',7,'l')"
1149
fossil sql -R o2.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x2',8,'r')"
1150
configRun configuration pull shun [file join $configDir o2.fossil] -R o1.fossil
1151
test_eq config-pull-keeps-rows [configSql o1.fossil "SELECT group_concat(uuid)
1152
FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x1,x2"
1153
configRun configuration pull shun --overwrite [file join $configDir o2.fossil] \
1154
-R o1.fossil
1155
test config-pull-overwrite {$CODE == 0}
1156
test_eq config-pull-overwrite-shun \
1157
[configSql o1.fossil "SELECT group_concat(uuid)
1158
FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x2"
1159
configRun configuration pull user --overwrite [file join $configDir o2.fossil] \
1160
-R o1.fossil
1161
test config-pull-overwrite-user {$CODE == 0 && [configSql o1.fossil "SELECT
1162
group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] ne ""}
1163
test_eq config-pull-overwrite-user-local-gone [configSql o1.fossil "SELECT
1164
count(*) FROM user WHERE login='local'"] 0
1165
test_eq config-pull-overwrite-user-remote [configSql o1.fossil "SELECT
1166
count(*) FROM user WHERE login='remote'"] 1
1167
1168
# --overwrite is an option of pull only.
1169
configRun configuration push shun --overwrite [file join $configDir o2.fossil] \
1170
-R o1.fossil
1171
test config-push-overwrite {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1172
configRun configuration sync shun --overwrite [file join $configDir o2.fossil] \
1173
-R o1.fossil
1174
test config-sync-overwrite {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1175
1176
# Without a URL the command uses the default server; with none it stops.
1177
configNew u1.fossil
1178
configRun configuration pull skin -R u1.fossil
1179
test config-pull-no-server {$CODE == 1 &&
1180
[string first "no server URL specified" $RESULT] >= 0}
1181
configRun configuration push skin -R u1.fossil
1182
test config-push-no-server {$CODE == 1}
1183
configRun configuration sync skin -R u1.fossil
1184
test config-sync-no-server {$CODE == 1}
1185
fossil remote file://[file join $configDir a.fossil] -R u1.fossil
1186
configRun configuration pull skin -R u1.fossil
1187
test config-pull-default-server {$CODE == 0 &&
1188
[configSql u1.fossil "SELECT value FROM config WHERE name='css'"] eq
1189
"body { color: #123; }"}
1190
configRun configuration pull project --proxy off \
1191
[file join $configDir a.fossil] \
1192
-R u1.fossil
1193
test config-pull-proxy-off {$CODE == 0 &&
1194
[configSql u1.fossil "SELECT value FROM config
1195
WHERE name='project-name'"] eq "Alpha"}
1196
configRun configuration pull skin [file join $configDir nosuch.fossil] \
1197
-R u1.fossil
1198
test config-pull-no-such-repository {$CODE == 1}
1199
1200
1201
###############################################################################################################################################
1202
# The configuration that a server sends on request: an area it does not know
1203
# is answered with nothing, and an area it knows with its cards.
1204
1205
configNew sv.fossil
1206
configPut sv.fossil {css {'hello'} header {'h'}} 1700000000
1207
write_file req.txt "$CLIENT_VERSION_CARD\
1208
reqconfig /nosuch\nreqconfig /css\nreqconfig css\nreqconfig /nosuch2\n"
1209
fossil_raw test-xfer -R sv.fossil req.txt
1210
test config-request {$CODE == 0 && [regexp -all {config /config } $RESULT] == 1
1211
&&
1212
[holds_strings $RESULT {"'css' value 'hello'" !'header' "errors 0"}]}
1213
1214
###############################################################################
1215
# A repository whose user and ticket report tables do not have the column
1216
# for JSON data exports them without it, and takes the cards that have no
1217
# such field.
1218
1219
configNew old.fossil
1220
fossil sql -R old.fossil "ALTER TABLE user DROP COLUMN jx;
1221
ALTER TABLE reportfmt DROP COLUMN jx;
1222
UPDATE user SET mtime=5"
1223
configRun configuration export all old.cfg -R old.fossil
1224
test config-export-old-schema {$CODE == 0 &&
1225
[string first " jx " [read_file old.cfg]] < 0 &&
1226
[configKinds old.cfg] eq "/config /reportfmt /user"}
1227
configNew old2.fossil
1228
configRun configuration import old.cfg -R old2.fossil
1229
test config-import-old-schema {$CODE == 0 &&
1230
[configSql old2.fossil "SELECT login FROM user WHERE login='tester'"] eq
1231
"tester"}
1232
1233
###############################################################################
1234
# The settings table by hand: test-var-set, test-var-get and test-var-list.
1235
1236
configNew v.fossil
1237
fossil test-var-set alpha hello -R v.fossil
1238
test config-var-set {$CODE == 0}
1239
fossil test-var-get alpha -R v.fossil
1240
test_eq config-var-get $RESULT hello
1241
fossil test-var-get alpha out.txt -R v.fossil
1242
test_eq config-var-get-file [read_file out.txt] hello
1243
fossil test-var-get alpha - -R v.fossil
1244
test_eq config-var-get-stdout $RESULT hello
1245
write_file in.txt "from a file\nwith two lines\n"
1246
fossil test-var-set beta --file in.txt -R v.fossil
1247
fossil test-var-get beta -R v.fossil
1248
test_eq config-var-set-file $RESULT "from a file\nwith two lines"
1249
fossil test-var-get beta out2.txt -R v.fossil
1250
test_eq config-var-set-file-exact [read_file out2.txt] \
1251
"from a file\nwith two lines\n"
1252
set configBlob "\x00\x01\xff\xfe\x80binary"
1253
write_file blob.bin $configBlob
1254
fossil test-var-set gamma --blob blob.bin -R v.fossil
1255
fossil test-var-get gamma out3.bin -R v.fossil
1256
test_eq config-var-set-blob [read_file out3.bin] $configBlob
1257
test_eq config-var-set-blob-type [configSql v.fossil "SELECT typeof(value) FROM
1258
config WHERE name='gamma'"] blob
1259
fossil_raw -input "piped in\n" test-var-set delta --file - -R v.fossil
1260
test config-var-set-stdin {$CODE == 0}
1261
test_eq config-var-set-stdin-value [configSql v.fossil "SELECT length(value)
1262
FROM config WHERE name='delta'"] 9
1263
fossil_raw test-var-set -R v.fossil
1264
test config-var-set-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1265
fossil_raw test-var-set epsilon -R v.fossil
1266
test config-var-set-no-value \
1267
{$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1268
fossil_raw test-var-set epsilon --file in.txt --blob blob.bin -R v.fossil
1269
test config-var-set-both {$CODE == 1 &&
1270
[string first "cannot do both" $RESULT] >= 0}
1271
fossil_raw test-var-set epsilon --file nosuch.txt -R v.fossil
1272
test config-var-set-no-file {$CODE == 1}
1273
test_eq config-var-set-none-made [configSql v.fossil "SELECT count(*) FROM
1274
config WHERE name='epsilon'"] 0
1275
fossil_raw test-var-get nosuch -R v.fossil
1276
test config-var-get-none {$CODE == 1 && [string first "no match for" $RESULT] >=
1277
0}
1278
fossil_raw test-var-get {[abg]*} -R v.fossil
1279
test config-var-get-many {$CODE == 1 &&
1280
[holds_strings $RESULT {"multiple matches:" 'alpha' 'beta'}]}
1281
fossil_raw test-var-get -R v.fossil
1282
test config-var-get-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1283
fossil test-var-get {alph?} -R v.fossil
1284
test_eq config-var-get-glob $RESULT hello
1285
1286
# The list: names and values in two columns, control characters written as
1287
# escapes, long values cut with the count of what is left, long names on a
1288
# line of their own.
1289
set configLongValue [string repeat abcdefghij 6]
1290
set configLongName1 a-name-that-is-long-but-with-a-short-value
1291
set configLongName2 a-name-that-is-long-with-a-value-that-is-long-too-and-so-on
1292
set configMidName a-name-that-is-between-the-two-lengths
1293
configNew w.fossil
1294
fossil sql -R w.fossil "DELETE FROM config WHERE NOT name GLOB 'a*';
1295
INSERT INTO config(name,value,mtime) VALUES
1296
('a-short','plain',1700000000),
1297
('a-ctl','x'||char(10)||char(13)||char(9)||char(1)||'y',1700000001),
1298
('a-long','$configLongValue',1700000002),
1299
('$configLongName1','v',1700000003),
1300
('$configLongName2','a value that has more than ten characters',
1301
1700000004),
1302
('$configMidName','x',1700000005),
1303
('$configMidName-long','a value that has more than ten characters',
1304
1700000006),
1305
('a-high','caf'||char(233)||char(127),1700000007)"
1306
# A line for NAME that has its value in the column that NAME's length gives.
1307
proc configListLine {name value pad} {
1308
return "$name:[string repeat { } [expr {$pad - [string length $name]}]]$value"
1309
}
1310
configRun test-var-list -R w.fossil
1311
set configList $RESULT
1312
test config-var-list-short \
1313
{[string first "[configListLine a-short plain 27]\n" \
1314
$configList] >= 0}
1315
test config-var-list-escapes {[string first \
1316
"[configListLine a-ctl {x\n\r\t\001y} 27]\n" $configList] >= 0}
1317
test config-var-list-long-value {[string first \
1318
"[configListLine a-long [string range $configLongValue 0 39]...+20 27]\n" \
1319
$configList] >= 0}
1320
test config-var-list-long-name-short-value {[string first \
1321
"[configListLine $configLongName1 v 59]\n" $configList] >= 0}
1322
test config-var-list-long-name-long-value {[string first \
1323
"$configLongName2:\n[string repeat { } 28]a value that has more than ten\
1324
character...+1\n" $configList] >= 0}
1325
test config-var-list-mid-name {[string first \
1326
"[configListLine $configMidName x 59]\n" $configList] >= 0}
1327
test config-var-list-mid-name-long-value {[string first \
1328
"$configMidName-long:\n[string repeat { } 28]a value that has more than ten\
1329
character...+1\n" $configList] >= 0}
1330
test config-var-list-high-bytes {[string first \
1331
"[configListLine a-high {caf\303\251\177} 27]\n" $configList] >= 0}
1332
configRun test-var-list "a-s*" -R w.fossil
1333
test_eq config-var-list-pattern [string trimright $RESULT] \
1334
[configListLine a-short plain 27]
1335
configRun test-var-list "a-s*" --mtime -R w.fossil
1336
test_eq config-var-list-mtime [string trimright $RESULT] \
1337
[configListLine a-short "2023-11-14 22:13:20" 58]
1338
configRun test-var-list nosuch -R w.fossil
1339
test_eq config-var-list-none $RESULT ""
1340
# Delete only on an answer of y, and only with a pattern.
1341
set configCount [configSql w.fossil "SELECT count(*) FROM config"]
1342
fossil_raw -input "n\n" test-var-list "a-s*" --unset -R w.fossil
1343
test config-var-unset-no {$CODE == 0 && [configSql w.fossil "SELECT count(*)
1344
FROM config WHERE name='a-short'"] == 1}
1345
fossil_raw -input "y\n" test-var-list --unset -R w.fossil
1346
test config-var-unset-no-pattern {[configSql w.fossil "SELECT count(*) FROM
1347
config"] == $configCount}
1348
fossil_raw -input "Y\n" test-var-list "a-s*" --unset -R w.fossil
1349
test config-var-unset-capital {[configSql w.fossil "SELECT count(*) FROM config
1350
WHERE name='a-short'"] == 0}
1351
fossil_raw -input "y\n" test-var-list "a-s*" --unset -R w.fossil
1352
test config-var-unset-yes {$CODE == 0 && [configSql w.fossil "SELECT count(*)
1353
FROM config WHERE name='a-short'"] == 0}
1354
1355
###############################################################################
1356
# The rest of the file needs a TCP connection over the loopback interface.
1357
1358
if {![loopback_available]} {
1359
unset ::env(FOSSIL_USER)
1360
test_skip "no TCP connection over the loopback interface"
1361
}
1362
1363
###############################################################################
1364
# Pull and push to a server that checks the login card. What a pull brings
1365
# depends on the capabilities of the user on the server: every area comes
1366
# to anyone who may read, except the concealed email addresses (capability
1367
# e), the users and the subscribers (a). A push needs capability a; for a
1368
# user without it, the server refuses and holds what it held.
1369
1370
# Make a server repository FILE that has the configuration of a.fossil and
1371
# the users that these tests log in as, and return it.
1372
proc configServer {file} {
1373
file copy -force a.fossil $file
1374
fossil sql -R $file "
1375
INSERT INTO user(login,pw,cap) VALUES
1376
('rdr','pw','o'), ('eml','pw','oe'), ('adm','pw','a'), ('blind','pw','j');
1377
"
1378
return $file
1379
}
1380
1381
# Give REPO the project code of a.fossil: a client makes its login card from
1382
# its own project code, so it must be the server's.
1383
proc configShareProject {repo} {
1384
global configProjectCode
1385
if {![info exists configProjectCode]} {
1386
set configProjectCode [configSql a.fossil "SELECT value FROM config
1387
WHERE name='project-code'"]
1388
}
1389
fossil sql -R $repo "UPDATE config SET value='$configProjectCode'
1390
WHERE name='project-code'"
1391
}
1392
1393
# Run VERB on repository CLIENT against the server on PORT, logged in as
1394
# USER, who has the password "pw", or as nobody for an empty USER.
1395
proc configNetRun {verb area client port user} {
1396
set at [expr {$user eq "" ? "" : "$user:pw@"}]
1397
configRun configuration $verb $area http://${at}127.0.0.1:$port/ -R $client
1398
}
1399
1400
# Whether USER may pull PART of the configuration.
1401
proc configMayPull {user part} {
1402
switch -- $part {
1403
email {return [expr {$user in {eml adm}}]}
1404
user - subscriber {return [expr {$user eq "adm"}]}
1405
}
1406
return [expr {$user ne "blind"}]
1407
}
1408
1409
# Test that REPO holds PART as the server's repository does if WANT is true,
1410
# and as a new repository does if it is false.
1411
proc configHasPart {name repo part want} {
1412
if {$part eq "user"} {
1413
set sql "SELECT count(*) FROM user WHERE login IN ('alice','bob')
1414
AND mtime IS NOT NULL;
1415
SELECT count(*) FROM config WHERE name='user-color-map'"
1416
test_eq $name-$part [configSql $repo $sql] \
1417
[expr {$want ? "2\n1" : "0\n0"}]
1418
} elseif {$want} {
1419
test_eq $name-$part [configState $repo $part] \
1420
[configState a.fossil $part 1]
1421
} else {
1422
test_eq $name-$part [configState $repo $part 0 1] [configDefaults $part]
1423
}
1424
}
1425
1426
configServer ps.fossil
1427
set configServerProc [test_start_server ps.fossil configStop]
1428
set configPort [lindex $configServerProc 1]
1429
# Each pair is a user and an area to pull as that user.
1430
foreach {configUser configArea} {{} skin {} all eml email eml user adm all
1431
blind skin} {
1432
set configLabel [expr {$configUser eq "" ? "nobody" : $configUser}]
1433
if {$configUser eq "blind"} {
1434
# A user whose capabilities, with those of nobody, include no reading.
1435
fossil sql -R ps.fossil "UPDATE user SET cap='' WHERE login IN
1436
('nobody','anonymous')"
1437
}
1438
set configC cp-$configLabel-$configArea.fossil
1439
configNew $configC
1440
configShareProject $configC
1441
set configPre [configDump $configC]
1442
configNetRun pull $configArea $configC $configPort $configUser
1443
test config-pull-$configLabel-$configArea {$CODE == 0}
1444
foreach configPart [configParts $configArea] {
1445
configHasPart config-pull-$configLabel-$configArea-has $configC \
1446
$configPart \
1447
[configMayPull $configUser $configPart]
1448
}
1449
if {$configUser ne "blind" && $configLabel ne "nobody"} {
1450
test config-pull-$configLabel-$configArea-changed \
1451
{[configDump $configC] ne $configPre}
1452
}
1453
}
1454
test_stop_server $configStop [lindex $configServerProc 0] \
1455
[lindex $configServerProc 2]
1456
1457
configNew cs-base.fossil
1458
configShareProject cs-base.fossil
1459
fossil sql -R cs-base.fossil "INSERT INTO user(login,pw,cap) VALUES
1460
('rdr','pw','o'), ('eml','pw','oe'), ('adm','pw','a')"
1461
file copy -force cs-base.fossil cs.fossil
1462
set configServerProc [test_start_server cs.fossil configStop]
1463
set configPort [lindex $configServerProc 1]
1464
# Each pair is a user and an area to push as that user; only adm may push.
1465
foreach {configUser configArea} {{} skin adm email adm user adm all} {
1466
set configLabel [expr {$configUser eq "" ? "nobody" : $configUser}]
1467
file copy -force cs-base.fossil cs.fossil
1468
set configPre [configDump cs.fossil]
1469
configNetRun push $configArea a.fossil $configPort $configUser
1470
if {$configUser eq "adm"} {
1471
test config-push-$configLabel-$configArea {$CODE == 0}
1472
foreach configPart [configParts $configArea] {
1473
configHasPart config-push-$configLabel-$configArea-has cs.fossil \
1474
$configPart 1
1475
}
1476
} else {
1477
test config-push-$configLabel-$configArea-refused {
1478
[string first "not authorized to push configuration" $RESULT] >= 0}
1479
test config-push-refused-status {$CODE == 1}
1480
test_eq config-push-$configLabel-$configArea-unchanged \
1481
[configDump cs.fossil] $configPre
1482
}
1483
}
1484
test_stop_server $configStop [lindex $configServerProc 0] \
1485
[lindex $configServerProc 2]
1486
1487
###############################################################################
1488
# Cards that a server sends for configuration that was not asked for are
1489
# dropped by the client, those it asked for are kept. A server made here
1490
# answers the first request with a prepared reply and every later one with a
1491
# bare timestamp.
1492
1493
proc configFakeRead {chan request} {
1494
set end [string first "\r\n\r\n" $request]
1495
# The request is the text of the cards, after four bytes of size when it
1496
# is compressed.
1497
set body [string range $request [expr {$end+4}] end]
1498
if {[regexp -nocase {content-type:\s*application/x-fossil\s} $request]} {
1499
set body [zlib decompress [string range $body 4 end]]
1500
}
1501
lappend ::configFakeRequests $body
1502
if {[incr ::configFakeCount] == 1} {
1503
set reply $::configFakeReply
1504
} else {
1505
set reply "# timestamp 2026-01-01T00:00:00 errors 0\n"
1506
}
1507
catch {
1508
puts -nonewline $chan "HTTP/1.0 200 OK\r\nContent-Type:\
1509
application/x-fossil-uncompressed\r\nContent-Length:\
1510
[string length $reply]\r\n\r\n$reply"
1511
close $chan
1512
}
1513
}
1514
set configFakePort [test_listen configFakeRead]
1515
1516
proc configReply {verb area reply} {
1517
global configFakePort configFakeReply configFakeCount configFakeRequests
1518
set configFakeReply $reply
1519
set configFakeCount 0
1520
set configFakeRequests {}
1521
configRun configuration $verb $area http://127.0.0.1:$configFakePort/ \
1522
-R rp.fossil
1523
}
1524
1525
configNew rp.fossil
1526
set configRpReply [configCard config "1700000000 'header' value 'asked'"]
1527
append configRpReply [configCard config "1700000000 'project-name' value 'not'"]
1528
append configRpReply [configCard user "1700000000 'zed' cap 's'"]
1529
append configRpReply [configCard nosuch "1700000000 'zed' cap 's'"]
1530
append configRpReply [configCard config "1700000000 'adunit' value 'asked'"]
1531
configReply pull skin $configRpReply
1532
test config-reply-unasked {$CODE == 0}
1533
test_eq config-reply-asked [configSql rp.fossil "SELECT group_concat(name)
1534
FROM (SELECT name FROM config WHERE name IN ('header','adunit',
1535
'project-name') ORDER BY name)"] "adunit,header"
1536
test_eq config-reply-unasked-user [configSql rp.fossil "SELECT count(*) FROM
1537
user WHERE login='zed'"] 0
1538
test config-reply-request-skin \
1539
{[string first "reqconfig /skin\nreqconfig /css\n" \
1540
[lindex $configFakeRequests 0]] >= 0}
1541
configReply pull css $configRpReply
1542
test_eq config-reply-css-only [configSql rp.fossil "SELECT count(*) FROM
1543
config WHERE name='project-name'"] 0
1544
# How many "reqconfig" cards the first request holds.
1545
proc configAsked {} {
1546
return [regexp -all {reqconfig [^\n]*} [lindex $::configFakeRequests 0]]
1547
}
1548
# The style sheet is part of the skin, so both are asked for; only the style
1549
# sheet is taken.
1550
test config-reply-request-css {[configAsked] == 2 &&
1551
[string first "reqconfig /skin\nreqconfig /css\n" \
1552
[lindex $configFakeRequests 0]] >= 0}
1553
configReply pull all ""
1554
test config-reply-request-all {[configAsked] == 1 &&
1555
[string first "reqconfig /all\n" [lindex $configFakeRequests 0]] >= 0}
1556
configReply pull ticket ""
1557
test config-reply-request-ticket {[string first "reqconfig /ticket\n" \
1558
[lindex $configFakeRequests 0]] >= 0}
1559
configReply pull user "config /user 0\n\n"
1560
test config-reply-empty-card {$CODE == 0}
1561
test_listen_stop
1562
1563
###############################################################################
1564
# "fossil init --template" copies the settings of another repository,
1565
# those of every area and the aliases among them, and leaves out the names
1566
# of the project and any setting that belongs to no area.
1567
1568
configNew tpl.fossil
1569
fossil sql -R tpl.fossil "
1570
INSERT OR REPLACE INTO config(name,value,mtime) VALUES
1571
('css','from-template',1700000000),
1572
('ticket-title-expr','from-template',1700000000),
1573
('walias:/tpl','/timeline',1700000000),
1574
('project-name','Template Project',1700000000),
1575
('short-project-name','tpl',1700000000),
1576
('config-test-other','from-template',1700000000)"
1577
configRun init --template tpl.fossil fromtpl.fossil
1578
test config-init-template {$CODE == 0}
1579
test_eq config-init-template-copied [configSql fromtpl.fossil "
1580
SELECT group_concat(name||'='||value, ' ') FROM (SELECT name, value
1581
FROM config WHERE name IN ('css','ticket-title-expr','walias:/tpl',
1582
'project-name','short-project-name','config-test-other')
1583
ORDER BY name)"] \
1584
"css=from-template ticket-title-expr=from-template walias:/tpl=/timeline"
1585
1586
test_cleanup
1587
unset ::env(FOSSIL_USER)
1588

Keyboard Shortcuts

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