forked from servalproject/serval-dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhizomeops
executable file
·1768 lines (1690 loc) · 63.5 KB
/
rhizomeops
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Tests for Serval rhizome command-line operations.
#
# Copyright 2012-2015 Serval Project, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
source "${0%/*}/../testdefs_rhizome.sh"
shopt -s extglob
setup_rhizome() {
[ -z "$A_IDENTITY_COUNT" ] && A_IDENTITY_COUNT=1
[ -z "$B_IDENTITY_COUNT" ] && B_IDENTITY_COUNT=0
>sids
if [ $A_IDENTITY_COUNT -ne 0 ]; then
set_instance +A
set_rhizome_config
if [ $A_IDENTITY_COUNT -eq 1 ]; then
create_single_identity
echo $SIDA >>sids
else
create_identities $A_IDENTITY_COUNT
for ((i=0; i!=A_IDENTITY_COUNT; ++i)); do
eval echo \"\$SIDA$i\" >>sids
done
fi
fi
if [ $B_IDENTITY_COUNT -ne 0 ]; then
set_instance +B
set_rhizome_config
create_identities $B_IDENTITY_COUNT
for ((i=0; i!=B_IDENTITY_COUNT; ++i)); do
eval echo \"\$SIDB$i\" >>sids
done
fi
assert [ $(sort sids | uniq | wc -l) -eq $((A_IDENTITY_COUNT + B_IDENTITY_COUNT)) ]
set_instance +A
}
set_rhizome_config() {
executeOk_servald config \
set debug.rhizome on \
set debug.rhizome_manifest on \
set debug.verbose on \
set log.console.level debug
}
doc_InitialEmptyList="Initial list is empty"
setup_InitialEmptyList() {
setup_servald
setup_rhizome
}
test_InitialEmptyList() {
executeOk_servald rhizome list
assert_rhizome_list
}
doc_AddNoAuthorNoManifest="Add with no author and no manifest file"
setup_AddNoAuthorNoManifest() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNoAuthorNoManifest() {
executeOk_servald rhizome add file '' file1
assert_stdout_add_file file1 !.author !BK
executeOk_servald rhizome add file '' "$PWD/file2"
assert_stdout_add_file file2 !.author !BK
}
doc_AddNoManifest="Add with no manifest file"
setup_AddNoManifest() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNoManifest() {
executeOk_servald rhizome add file $SIDA file1
assert_stdout_add_file file1
executeOk_servald rhizome add file $SIDA "$PWD/file2"
assert_stdout_add_file file2
}
doc_AddManifestFieldUnsupported="Add with unsupported manifest field"
setup_AddManifestFieldUnsupported() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
echo "bogus=one" >file1.manifest
}
test_AddManifestFieldUnsupported() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest
assert_stdout_add_file file1
tfw_cat -v file1.manifest
assert_manifest_complete file1.manifest
assert_manifest_fields file1.manifest bogus=one
}
doc_AddManifestFieldUnsupportedArgs="Add with unsupported manifest field argument"
setup_AddManifestFieldUnsupportedArgs() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddManifestFieldUnsupportedArgs() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest '' bogus=two
assert_stdout_add_file file1
tfw_cat -v file1.manifest
assert_manifest_complete file1.manifest
assert_manifest_fields file1.manifest bogus=two
}
doc_AddNoAuthor="Add with no author makes manifest without BK"
setup_AddNoAuthor() {
setup_servald
setup_rhizome
echo "A test file" >file1
}
test_AddNoAuthor() {
executeOk_servald rhizome add file '' file1 file1.manifest
assert_manifest_fields file1.manifest !BK
assert_stdout_add_file file1 !.author !BK
}
doc_AddInvalidAuthor="Add with invalid author fails"
setup_AddInvalidAuthor() {
setup_servald
setup_rhizome
echo "A test file" >file1
}
test_AddInvalidAuthor() {
execute $servald rhizome add file 'not_a_valid_SID' file1
assertExitStatus '==' 255
assertStderrGrep '^ERROR:.*[Ii]nvalid .*[Ss][Ii][Dd]'
}
doc_AddNoAuthorEncrypted="Add encrypted payload with no author"
setup_AddNoAuthorEncrypted() {
setup_servald
setup_rhizome
echo "A test file" >file1
echo "crypt=1" >file1.manifest
}
test_AddNoAuthorEncrypted() {
executeOk_servald rhizome add file '' file1 file1.manifest
tfw_cat --stdout --stderr -v file1.manifest
assert_manifest_fields file1.manifest !BK
assert_stdout_add_file file1 !.author !BK
extract_stdout_secret file1_secret
executeOk_servald rhizome extract file $re_manifestid file1x $file1_secret
tfw_cat --stdout --stderr
assert diff file1 file1x
}
doc_AddNonExistManifest="Add with non-existent manifest file"
setup_AddNonExistManifest() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddNonExistManifest() {
assert --error-on-fail [ ! -e file1.manifest ]
executeOk_servald rhizome add file $SIDA file1 file1.manifest
assert_stdout_add_file file1
assert [ -r file1.manifest ]
assert_manifest_complete file1.manifest
assert_manifest_fields file1.manifest service=file name=file1
assert --error-on-fail [ ! -e file2.manifest ]
executeOk_servald rhizome add file $SIDA "$PWD/file2" file2.manifest
assert_stdout_add_file file2
assert [ -r file2.manifest ]
assert_manifest_complete file2.manifest
assert_manifest_fields file2.manifest service=file name=file2
}
doc_AddManifest="Add with minimal manifest file"
setup_AddManifest() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo -e 'name=wah\ndate=12345' >file1.manifest
}
test_AddManifest() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest
tfw_cat --stdout --stderr -v file1.manifest
assert_stdout_add_file file1 name=wah
assert_manifest_complete file1.manifest
assert_manifest_fields file1.manifest service=file name=wah date=12345
}
doc_AddManifestArgs="Add with minimal manifest from arguments"
setup_AddManifestArgs() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
}
test_AddManifestArgs() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest '' name=wah date=12345
tfw_cat --stdout --stderr -v file1.manifest
assert_stdout_add_file file1 name=wah
assert_manifest_complete file1.manifest
assert_manifest_fields file1.manifest service=file name=wah date=12345
}
doc_AddEmpty="Add with empty payload"
setup_AddEmpty() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
}
test_AddEmpty() {
executeOk_servald rhizome add file $SIDA '' empty.manifest
tfw_cat --stdout --stderr -v empty.manifest
assert_stdout_add_file --manifest=empty.manifest ''
assert_manifest_complete empty.manifest
assert_manifest_fields empty.manifest service=file name= filesize=0
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA --manifest=empty.manifest ''
}
doc_AddMissing="Attempt to add a file and manifest that don't exist"
setup_AddMissing() {
setup_servald
setup_rhizome
}
test_AddMissing() {
execute $servald rhizome add file $SIDA 'file1' 'file1.manifest'
tfw_cat --stdout --stderr
assertExitStatus '==' 255
}
doc_AddThenList="List contains one file after one add"
setup_AddThenList() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
}
test_AddThenList() {
# Add first file
executeOk_servald rhizome add file $SIDA file1 file1.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1
# Add second file
executeOk_servald rhizome add file $SIDA file2 file2.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
}
doc_CleanVerify="Verify all bundles"
setup_CleanVerify() {
setup_servald
setup_rhizome
echo "File1" > file1
echo "File2" > file2
echo "File3" > file3
echo "File4" > file4
executeOk_servald rhizome add file '' file1 file1.manifest
assert_stdout_add_file file1 !.author !BK
executeOk_servald rhizome add file '' file2 file2.manifest
assert_stdout_add_file file2 !.author !BK
executeOk_servald rhizome add file '' file3 file3.manifest
assert_stdout_add_file file3 !.author !BK
executeOk_servald rhizome add file '' file4 file4.manifest
assert_stdout_add_file file4 !.author !BK
executeOk_servald rhizome list file
assert_rhizome_list file1 file2 file3 file4
}
test_CleanVerify() {
executeOk_servald rhizome clean verify
tfw_cat --stdout --stderr
executeOk_servald rhizome list file
assert_rhizome_list file1 file2 file3 file4
}
doc_ExtractManifestAfterAdd="Export manifest after one add"
setup_ExtractManifestAfterAdd() {
setup_servald
setup_rhizome
echo "A test file" >file1
executeOk_servald rhizome add file $SIDA file1 file1.manifest
extract_stdout_rowid rowid
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
extract_manifest_filehash filehash file1.manifest
extract_manifest_BK BK file1.manifest
extract_manifest_date date file1.manifest
}
test_ExtractManifestAfterAdd() {
executeOk_servald rhizome export manifest $manifestid file1x.manifest
tfw_cat --stdout --stderr
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --matches=1 "^version:$version\$"
assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^BK:$BK\$"
assertStdoutGrep --matches=1 "^date:$date\$"
assertStdoutGrep --matches=1 "^service:file\$"
assertStdoutGrep --matches=1 "^name:file1\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.author:$SIDA\$"
assertStdoutGrep --matches=1 "^\.rowid:$rowid\$"
assertStdoutGrep --matches=1 "^\.inserttime:$rexp_date\$"
assertStdoutLineCount '==' 13
assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest
}
doc_ExtractManifestFileAfterAdd="Export bundle after one add"
setup_ExtractManifestFileAfterAdd() {
setup_servald
setup_rhizome
echo "A test file" >file1
executeOk_servald rhizome add file $SIDA file1 file1.manifest
extract_stdout_rowid rowid
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
extract_manifest_filehash filehash file1.manifest
extract_manifest_BK BK file1.manifest
extract_manifest_date date file1.manifest
}
test_ExtractManifestFileAfterAdd() {
executeOk_servald rhizome export bundle $manifestid file1x.manifest file1x
tfw_cat --stdout --stderr
assertStdoutLineCount '==' 13
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --matches=1 "^version:$version\$"
assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^BK:$BK\$"
assertStdoutGrep --matches=1 "^date:$date\$"
assertStdoutGrep --matches=1 "^service:file\$"
assertStdoutGrep --matches=1 "^name:file1\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.author:$SIDA\$"
assertStdoutGrep --matches=1 "^\.rowid:$rowid\$"
assertStdoutGrep --matches=1 "^\.inserttime:$rexp_date\$"
assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest
assert [ -e file1x ]
assert diff file1 file1x
}
doc_ExtractManifestFileFromExtBlob="Export bundle from external blob"
setup_ExtractManifestFileFromExtBlob() {
setup_servald
setup_rhizome
executeOk_servald config set rhizome.max_blob_size 0
echo "A test file" >file1
executeOk_servald rhizome add file $SIDA file1 file1.manifest
extract_stdout_rowid rowid1
executeOk_servald config set rhizome.max_blob_size 1000
echo "Another test file" >file2
executeOk_servald rhizome add file $SIDA file2 file2.manifest
extract_stdout_rowid rowid2
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
extract_manifest_id manifestid1 file1.manifest
extract_manifest_version version1 file1.manifest
extract_manifest_filehash filehash1 file1.manifest
extract_manifest_BK BK1 file1.manifest
extract_manifest_date date1 file1.manifest
extract_manifest_id manifestid2 file2.manifest
extract_manifest_version version2 file2.manifest
extract_manifest_filehash filehash2 file2.manifest
extract_manifest_BK BK2 file2.manifest
extract_manifest_date date2 file2.manifest
}
test_ExtractManifestFileFromExtBlob() {
executeOk_servald rhizome export bundle $manifestid1 file1x.manifest file1x
tfw_cat --stdout --stderr
assertStdoutLineCount '==' 13
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^manifestid:$manifestid1\$"
assertStdoutGrep --matches=1 "^version:$version1\$"
assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^filehash:$filehash1\$"
assertStdoutGrep --matches=1 "^BK:$BK1\$"
assertStdoutGrep --matches=1 "^date:$date1\$"
assertStdoutGrep --matches=1 "^service:file\$"
assertStdoutGrep --matches=1 "^name:file1\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.author:$SIDA\$"
assertStdoutGrep --matches=1 "^\.rowid:$rowid1\$"
assertStdoutGrep --matches=1 "^\.inserttime:$rexp_date\$"
assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest
assert [ -e file1x ]
assert diff file1 file1x
executeOk_servald rhizome export bundle $manifestid2 file2x.manifest file2x
tfw_cat --stdout --stderr
assertStdoutLineCount '==' 13
local size=$(( $(cat file2 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^manifestid:$manifestid2\$"
assertStdoutGrep --matches=1 "^version:$version2\$"
assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^filehash:$filehash2\$"
assertStdoutGrep --matches=1 "^BK:$BK2\$"
assertStdoutGrep --matches=1 "^date:$date2\$"
assertStdoutGrep --matches=1 "^service:file\$"
assertStdoutGrep --matches=1 "^name:file2\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.author:$SIDA\$"
assertStdoutGrep --matches=1 "^\.rowid:$rowid2\$"
assertStdoutGrep --matches=1 "^\.inserttime:$rexp_date\$"
assert [ -e file2x.manifest ]
assert diff file2.manifest file2x.manifest
assert [ -e file2x ]
assert diff file2 file2x
}
doc_LargePayload="Export huge bundle after one add"
setup_LargePayload() {
setup_servald
setup_rhizome
executeOk_servald config set debug.rhizome_store on
}
test_LargePayload() {
rhizome_add_file file1 100000
executeOk_servald rhizome export bundle $BID file1x.manifest file1x
assert [ -e file1x.manifest ]
assert diff file1.manifest file1x.manifest
assert [ -e file1x ]
assert diff file1 file1x
}
doc_CorruptExternalBlob="Corrupted payload fails to export"
setup_CorruptExternalBlob() {
setup_servald
setup_rhizome
executeOk_servald config set rhizome.max_blob_size 0
echo "A test file" >file1
executeOk_servald rhizome add file $SIDA file1 file1.manifest
extract_manifest_id manifestid file1.manifest
extract_manifest_filehash filehash file1.manifest
assert cmp file1 "$SERVALINSTANCE_PATH/blob/$filehash"
echo "Replacement" >"$SERVALINSTANCE_PATH/blob/$filehash"
}
test_CorruptExternalBlob() {
execute --exit-status=255 $servald rhizome extract file $manifestid file1a
tfw_cat --stderr
}
doc_ExtractManifestToStdout="Export manifest to standard output"
setup_ExtractManifestToStdout() {
setup_servald
setup_rhizome
echo "A test file" >file1
executeOk_servald rhizome add file $SIDA file1 file1.manifest
extract_stdout_rowid rowid
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
extract_manifest_filehash filehash file1.manifest
extract_manifest_BK BK file1.manifest
extract_manifest_date date file1.manifest
}
test_ExtractManifestToStdout() {
executeOk_servald rhizome export manifest $manifestid -
assertStdoutLineCount '>=' 14
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --line=..13 --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --line=..13 --matches=1 "^version:$version\$"
assertStdoutGrep --line=..13 --matches=1 "^filesize:$size\$"
assertStdoutGrep --line=..13 --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --line=..13 --matches=1 "^BK:$BK\$"
assertStdoutGrep --line=..13 --matches=1 "^date:$date\$"
assertStdoutGrep --line=..13 --matches=1 "^service:file\$"
assertStdoutGrep --line=..13 --matches=1 "^name:file1\$"
assertStdoutGrep --line=..13 --matches=1 "^\.readonly:0\$"
assertStdoutGrep --line=..13 --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --line=..13 --matches=1 "^\.author:$SIDA\$"
assertStdoutGrep --line=..13 --matches=1 "^\.rowid:$rowid\$"
assertStdoutGrep --line=..13 --matches=1 "^\.inserttime:$rexp_date\$"
assertStdoutGrep --line=14 --matches=1 "^manifest:"
replayStdout | $SED -n '14s/^manifest://p' >file1x.manifest
replayStdout | $SED -n '15,$p' >>file1x.manifest
cat file1.manifest >file1n.manifest
echo >>file1n.manifest
tfw_cat file1n.manifest file1x.manifest
assert diff file1n.manifest file1x.manifest
}
doc_ExtractManifestAfterAddNoAuthor="Export manifest after one add with no author"
setup_ExtractManifestAfterAddNoAuthor() {
setup_servald
setup_rhizome
echo "A test file" >file1
executeOk_servald rhizome add file '' file1 file1.manifest
extract_stdout_rowid rowid
executeOk_servald rhizome list
assert_rhizome_list --fromhere=0 file1
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
extract_manifest_filehash filehash file1.manifest
extract_manifest_date date file1.manifest
}
test_ExtractManifestAfterAddNoAuthor() {
executeOk_servald rhizome export manifest $manifestid file1x.manifest
assert diff file1.manifest file1x.manifest
assertStdoutLineCount '==' 10
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --matches=1 "^version:$version\$"
assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^date:$date\$"
assertStdoutGrep --matches=1 "^service:file\$"
assertStdoutGrep --matches=1 "^name:file1\$"
assertStdoutGrep --matches=1 "^\.readonly:1\$"
assertStdoutGrep --matches=1 "^\.rowid:$rowid\$"
assertStdoutGrep --matches=1 "^\.inserttime:$rexp_date\$"
}
doc_ExtractManifestNonExistent="Export non-existent manifest"
setup_ExtractManifestNonExistent() {
setup_servald
setup_rhizome
manifestid=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
}
test_ExtractManifestNonExistent() {
execute --exit-status=1 $servald rhizome export manifest $manifestid foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
}
doc_ExtractManifestInvalidID="Export manifest using invalid ID"
setup_ExtractManifestInvalidID() {
setup_servald
setup_rhizome
}
test_ExtractManifestInvalidID() {
execute --exit-status=255 $servald rhizome export manifest 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
execute --exit-status=255 $servald rhizome export manifest 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
execute --exit-status=255 $servald rhizome export manifest foo.manifest
assertStdoutLineCount '==' 0
assert [ ! -e foo.manifest ]
}
doc_ExtractFileAfterAdd="Extract file after one add"
setup_ExtractFileAfterAdd() {
setup_servald
setup_rhizome
echo "A test file" >file1
executeOk_servald rhizome add file $SIDA file1 file1.manifest
tfw_cat --stderr
extract_stdout_rowid rowid
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1
extract_manifest_id manifestid file1.manifest
extract_manifest_version version file1.manifest
extract_manifest_filehash filehash file1.manifest
extract_manifest_BK BK file1.manifest
extract_manifest_date date file1.manifest
}
test_ExtractFileAfterAdd() {
executeOk_servald rhizome extract file $manifestid file1x
tfw_cat --stderr
assert diff file1 file1x
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutLineCount '==' 13
assertStdoutGrep --matches=1 "^manifestid:$manifestid\$"
assertStdoutGrep --matches=1 "^version:$version\$"
assertStdoutGrep --matches=1 "^filesize:$size\$"
assertStdoutGrep --matches=1 "^filehash:$filehash\$"
assertStdoutGrep --matches=1 "^BK:$BK\$"
assertStdoutGrep --matches=1 "^date:$date\$"
assertStdoutGrep --matches=1 "^service:file\$"
assertStdoutGrep --matches=1 "^name:file1\$"
assertStdoutGrep --matches=1 "^\.readonly:0\$"
assertStdoutGrep --matches=1 "^\.secret:$rexp_bundlesecret\$"
assertStdoutGrep --matches=1 "^\.author:$SIDA\$"
assertStdoutGrep --matches=1 "^\.rowid:$rowid\$"
assertStdoutGrep --matches=1 "^\.inserttime:$rexp_date\$"
}
doc_ExtractFileMissing="Extract and export non-existent file"
setup_ExtractFileMissing() {
setup_servald
setup_rhizome
BID=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
filehash=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
}
test_ExtractFileMissing() {
execute --exit-status=1 $servald rhizome extract file $BID foo
tfw_cat --stderr
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=1 $servald rhizome export file $filehash foo
tfw_cat --stderr
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
}
doc_ExtractFileInvalidID="Extract and export file using invalid ID"
setup_ExtractFileInvalidID() {
setup_servald
setup_rhizome
}
test_ExtractFileInvalidID() {
execute --exit-status=255 $servald rhizome extract file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $servald rhizome extract file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $servald rhizome extract file foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $servald rhizome export file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEx foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $servald rhizome export file 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDE foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
execute --exit-status=255 $servald rhizome export file foo
assertStdoutLineCount '==' 0
assert [ ! -e foo ]
}
doc_AddDeDuplicate="Add duplicate file does not create new bundle by default"
setup_AddDeDuplicate() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "Another test file" >file2
echo "A test file, second version" >file1_2
# Add first file
executeOk_servald rhizome add file $SIDA file1 file1.manifest
extract_stdout_secret file1_secret
# Add second file
executeOk_servald rhizome add file $SIDA file2 file2.manifest
extract_stdout_secret file2_secret
# Make sure they are both in the list.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
}
test_AddDeDuplicate() {
# Add first file again - should return a "duplicate" status code and nothing
# should change in its manifests.
execute --exit-status=2 --stderr --core-backtrace $servald rhizome add file $SIDA file1 file1.manifestA
assert [ -s file1.manifestA ]
assert_stdout_add_file file1
extract_stdout_secret file1_dup_secret
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
strip_signatures file1.manifest file1.manifestA
assert diff file1.manifest file1.manifestA
assert [ $file1_secret = $file1_dup_secret ]
# Repeat for second file.
execute --exit-status=2 --stderr $servald rhizome add file $SIDA file2 file2.manifestA
assert [ -s file2.manifestA ]
assert_stdout_add_file file2
extract_stdout_secret file2_dup_secret
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
strip_signatures file2.manifest file2.manifestA
assert diff file2.manifest file2.manifestA
assert [ $file2_secret = $file2_dup_secret ]
}
doc_AddForceDuplicate="Add duplicate file with --force-new option"
setup_AddForceDuplicate() {
setup_AddDeDuplicate
}
test_AddForceDuplicate() {
# Add first file again with the --force-new option. A new manifest
# should be created with a new ID.
executeOk_servald rhizome add file --force-new $SIDA file1 file1.manifestA
assert [ -s file1.manifestA ]
assert_stdout_add_file --manifest=file1.manifestA file1
extract_stdout_secret file1_dup_secret
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2 --manifest=file1.manifestA file1
strip_signatures file1.manifest file1.manifestA
assert ! diff file1.manifest file1.manifestA
assert [ $file1_secret != $file1_dup_secret ]
# Repeat for second file.
executeOk_servald rhizome add file --force-new $SIDA file2 file2.manifestA
assert [ -s file2.manifestA ]
assert_stdout_add_file --manifest=file2.manifestA file2
extract_stdout_secret file2_dup_secret
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2 --manifest=file1.manifestA file1 --manifest=file2.manifestA file2
strip_signatures file2.manifest file2.manifestA
assert ! diff file2.manifest file2.manifestA
assert [ $file2_secret != $file2_dup_secret ]
}
doc_AddMismatched="Add mismatched manifest/payload fails"
setup_AddMismatched() {
setup_AddDeDuplicate
}
test_AddMismatched() {
# Try to add another file using an existing manifest, should fail with status
# code indicating inconsistency.
cp file1.manifest file1_2.manifest
# Exit status 6 means manifest and payload do not match (filesize/filehash).
execute --exit-status=6 --stderr --core-backtrace $servald rhizome add file $SIDA file1_2 file1_2.manifest
tfw_cat file1.manifest file1_2.manifest
# Output manifest should be the same as the re-used manigfest
assert --stderr cmp file1.manifest file1_2.manifest
# And rhizome store should be unchanged.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
}
doc_AddUpdateSameVersion="Add new payload to existing manifest with same version fails"
setup_AddUpdateSameVersion() {
setup_AddDeDuplicate
cp file1.manifest file1_2.manifest
strip_signatures file1_2.manifest
$SED -i -e '/^date=/d;/^filehash=/d;/^filesize=/d' file1_2.manifest
tfw_cat -v file1_2.manifest
assert_manifest_fields file1_2.manifest !date !filehash !filesize version id
cp file1_2.manifest file1_2.manifest.orig
}
test_AddUpdateSameVersion() {
# Try to add another file using an existing manifest Id and Version, should
# fail and update the manifest file to show existing bundle's manifest.
tfw_cat -v file1_2.manifest
execute $servald rhizome add file $SIDA file1_2 file1_2.manifest
assertExitStatus --stderr '==' 1
tfw_cat -v file1_2.manifest file1.manifest
assert cmp file1_2.manifest file1.manifest
# And rhizome store should be unchanged.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1 file2
}
doc_AddUpdateNewVersion="Add new payload to existing manifest with new version"
setup_AddUpdateNewVersion() {
setup_AddUpdateSameVersion
extract_manifest_version version file1_2.manifest
let version=version+1
$SED -i -e "/^version=/s/=.*/=$version/" file1_2.manifest
assert_manifest_fields file1_2.manifest version="$version"
}
test_AddUpdateNewVersion() {
tfw_cat -v file1_2.manifest
executeOk_servald rhizome add file $SIDA file1_2 file1_2.manifest
tfw_cat --stderr
assert_stdout_add_file file1_2 name=file1
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1_2 file2
}
doc_AddUpdateDiscoverAuthor="Add new payload to manifest with author discovery"
setup_AddUpdateDiscoverAuthor() {
setup_AddUpdateNewVersion
}
test_AddUpdateDiscoverAuthor() {
tfw_cat -v file1_2.manifest
executeOk_servald rhizome add file '' file1_2 file1_2.manifest
tfw_cat --stderr
# Rhizome store contents have new payload.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 --author=$SIDA file1_2 file2
}
doc_AddUpdateNoAuthor="Cannot add new payload to authorless manifest"
setup_AddUpdateNoAuthor() {
setup_servald
setup_rhizome
executeOk_servald rhizome list
assert_rhizome_list
echo "A test file" >file1
echo "A test file, second version" >file1_2
# Add first file
executeOk_servald rhizome add file '' file1 file1.manifest
extract_stdout_secret file1_secret
assert_manifest_fields file1.manifest !BK
# Create second manifest
cp file1.manifest file1_2.manifest
strip_signatures file1_2.manifest
$SED -i -e '/^date=/d;/^filehash=/d;/^filesize=/d;/^version=/d' file1_2.manifest
tfw_cat -v file1_2.manifest
}
test_AddUpdateNoAuthor() {
execute $servald rhizome add file $SIDA file1_2 file1_2.manifest
tfw_cat --stderr
assertExitStatus '!=' 0
# Rhizome store contents still have old payload
executeOk_servald rhizome list
assert_rhizome_list --fromhere=0 file1
}
doc_AddUpdateNoAuthorWithSecret="Add new payload to authorless manifest with bundle secret"
setup_AddUpdateNoAuthorWithSecret() {
setup_AddUpdateNoAuthor
}
test_AddUpdateNoAuthorWithSecret() {
executeOk_servald rhizome add file '' file1_2 file1_2.manifest "$file1_secret"
tfw_cat --stderr
# Rhizome store contents have new payload, but it has lost its author (no BK
# field any more).
executeOk_servald rhizome list
assert_rhizome_list --fromhere=0 file1_2
}
doc_AddUpdateAutoVersion="Add new payload to existing manifest with automatic version"
setup_AddUpdateAutoVersion() {
setup_AddUpdateSameVersion
$SED -i -e '/^version=/d' file1_2.manifest
assert_manifest_fields file1_2.manifest !version
}
test_AddUpdateAutoVersion() {
tfw_cat -v file1_2.manifest
sleep 0.001 # Ensure that at least one millisecond has elapsed
executeOk_servald rhizome add file $SIDA file1_2 file1_2.manifest
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1_2 file2
}
doc_AddUpdateArgs="Update existing bundle using manifest args"
setup_AddUpdateArgs() {
setup_AddDeDuplicate
extract_manifest_id BID file1.manifest
cp file1.manifest file1_2.manifest
}
test_AddUpdateArgs() {
sleep 0.001 # Ensure that at least one millisecond has elapsed
executeOk_servald rhizome add file $SIDA file1_2 file1_2.manifest '' !version !filesize !filehash !date
assert_stdout_add_file file1_2 name=file1
assert_manifest_fields file1_2.manifest name=file1
extract_manifest_id BID2 file1_2.manifest
assert [ $BID = $BID2 ]
assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload.
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1_2 file2
}
doc_AddServiceInvalid="Add with invalid service fails"
setup_AddServiceInvalid() {
setup_servald
setup_rhizome
echo "Message1" >file1
echo 'service=Fubar!' >file1.manifest
}
test_AddServiceInvalid() {
execute $servald rhizome add file $SIDA file1 file1.manifest
tfw_cat --stdout --stderr
assertExitStatus '!=' 0
}
doc_AddServiceUnsupported="Add with unsupported service succeeds"
setup_AddServiceUnsupported() {
setup_servald
setup_rhizome
echo "Message1" >file1
echo 'service=Fubar' >file1.manifest
}
test_AddServiceUnsupported() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest
tfw_cat --stdout --stderr
}
doc_AddUpdateNoAuthorWithPassphrase="Add and update authorless bundle with only secret passphrase"
setup_AddUpdateNoAuthorWithPassphrase() {
setup_servald
setup_rhizome
create_file file1 1k
create_file file1_2 2k
pass='On the Ning Nang Nong'
}
test_AddUpdateNoAuthorWithPassphrase() {
executeOk_servald rhizome add file '' file1 file1.manifest "#$pass"
tfw_cat --stdout --stderr
assert_stdout_add_file file1 !.author '!BK'
assert_manifest_complete file1.manifest
extract_manifest_id BID file1.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=0 file1
executeOk_servald rhizome add file '' file1_2 file1_2.manifest "#$pass"
tfw_cat --stdout --stderr
assert_stdout_add_file file1_2 !.author '!BK'
assert_manifest_complete file1_2.manifest
extract_manifest_id BID2 file1.manifest
assert [ "$BID" = "$BID2" ]
executeOk_servald rhizome extract file $BID file1x
tfw_cat --stdout --stderr
assert diff file1_2 file1x
}
doc_AddUpdateWithPassphrase="Add and update bundle using secret passphrase"
setup_AddUpdateWithPassphrase() {
setup_servald
setup_rhizome
create_file file1 1k
create_file file1_2 2k
pass='On the Ning Nang Nong'
}
test_AddUpdateWithPassphrase() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest "#$pass"
tfw_cat --stdout --stderr
assert_stdout_add_file file1 .author=$SIDA
assert_manifest_complete file1.manifest
extract_manifest_id BID file1.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1
executeOk_servald rhizome add file $SIDA file1_2 file1_2.manifest "#$pass"
tfw_cat --stdout --stderr
assert_stdout_add_file file1_2 .author=$SIDA
assert_manifest_complete file1_2.manifest
extract_manifest_id BID2 file1.manifest
assert [ "$BID" = "$BID2" ]
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1_2
executeOk_servald rhizome extract file $BID file1x
tfw_cat --stdout --stderr
assert diff file1_2 file1x
}
doc_EncryptedPayload="Add and extract an encrypted payload"
setup_EncryptedPayload() {
setup_servald
setup_rhizome
echo "Clear Text" >file1
echo -e "service=file\nname=private\ncrypt=1" >file1.manifest
}
test_EncryptedPayload() {
executeOk_servald rhizome add file $SIDA file1 file1.manifest
tfw_cat --stdout --stderr
assert_stdout_add_file file1
assert_manifest_complete file1.manifest
executeOk_servald rhizome list
assert_rhizome_list --fromhere=1 file1
extract_manifest_id BID file1.manifest
executeOk_servald rhizome extract file $BID file1x
tfw_cat --stdout --stderr
assert diff file1 file1x
extract_manifest_filehash filehash file1.manifest
executeOk_servald rhizome export file $filehash file1y
assert ! diff file1 file1y
}
doc_RecipientIsEncrypted="Setting recipient triggers encryption by default"
setup_RecipientIsEncrypted() {
A_IDENTITY_COUNT=2
setup_servald
setup_rhizome
echo "Clear Text1" >file1