Debian Codegraph @

tests/test-censor.t

raw
1 #testcases revlogv1 delta-info revlogv2
2
3 #if revlogv2
4
5 $ cat >> $HGRCPATH <<EOF
6 > [experimental]
7 > revlogv2=enable-unstable-format-and-corrupt-my-data
8 > [storage]
9 > fileindex.slow-path=allow
10 > EOF
11
12 #endif
13
14 #if delta-info
15
16 $ cat >> $HGRCPATH <<EOF
17 > [format]
18 > use-delta-info-flags=yes
19 > EOF
20
21 #else
22
23 $ cat >> $HGRCPATH <<EOF
24 > [format]
25 > use-delta-info-flags=no
26 > EOF
27
28 #endif
29
30 $ cp $HGRCPATH $HGRCPATH.orig
31
32 Create repo with unimpeachable content
33
34 $ hg init r
35 $ cd r
36 $ echo 'Initially untainted file' > target
37 $ echo 'Normal file here' > bystander
38 $ hg add target bystander
39 $ hg ci -m init
40
41 Clone repo so we can test pull later
42
43 $ cd ..
44 $ hg clone r rpull
45 updating to branch default
46 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
47 $ cd r
48
49 Introduce content which will ultimately require censorship. Name the first
50 censored node C1, second C2, and so on
51
52 $ echo 'Tainted file' > target
53 $ echo 'Passwords: hunter2' >> target
54 $ hg ci -m taint target
55 $ C1=`hg id -r . -T "{node}"`
56
57 $ echo 'hunter3' >> target
58 $ echo 'Normal file v2' > bystander
59 $ hg ci -m moretaint target bystander
60 $ C2=`hg id -r . -T "{node}"`
61
62 Add a new sanitized versions to correct our mistake. Name the first head H1,
63 the second head H2, and so on
64
65 $ echo 'Tainted file is now sanitized' > target
66 $ hg ci -m sanitized target
67 $ H1=`hg id -r . -T "{node}"`
68
69 $ hg update -r $C2
70 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
71 $ echo 'Tainted file now super sanitized' > target
72 $ hg ci -m 'super sanitized' target
73 created new head
74 $ H2=`hg id -r . -T "{node}"`
75
76 Verify target contents before censorship at each revision
77
78 $ hg cat -r $H1 target | head -n 10
79 Tainted file is now sanitized
80 $ hg cat -r $H2 target | head -n 10
81 Tainted file now super sanitized
82 $ hg cat -r $C2 target | head -n 10
83 Tainted file
84 Passwords: hunter2
85 hunter3
86 $ hg cat -r $C1 target | head -n 10
87 Tainted file
88 Passwords: hunter2
89 $ hg cat -r 0 target | head -n 10
90 Initially untainted file
91
92 Censor revision with 2 offenses
93
94 (this also tests file pattern matching: path relative to cwd case)
95
96 $ mkdir -p foo/bar/baz
97 $ hg --config extensions.censor= --cwd foo/bar/baz censor -r $C2 -t "remove password" ../../../target
98 checking for the censored content in 2 heads
99 checking for the censored content in the working directory
100 censoring 1 file revisions
101 $ hg cat -r $H1 target | head -n 10
102 Tainted file is now sanitized
103 $ hg cat -r $H2 target | head -n 10
104 Tainted file now super sanitized
105 $ hg cat -r $C2 target | head -n 10
106 abort: censored node: 1e0247a9a4b7
107 (set censor.policy to ignore errors)
108 $ hg cat -r $C1 target | head -n 10
109 Tainted file
110 Passwords: hunter2
111 $ hg cat -r 0 target | head -n 10
112 Initially untainted file
113
114 Censor revision with 1 offense
115
116 (this also tests file pattern matching: with 'path:' scheme)
117
118 $ hg --config extensions.censor= --cwd foo/bar/baz censor -r $C1 path:target
119 checking for the censored content in 2 heads
120 checking for the censored content in the working directory
121 censoring 1 file revisions
122 $ hg cat -r $H1 target | head -n 10
123 Tainted file is now sanitized
124 $ hg cat -r $H2 target | head -n 10
125 Tainted file now super sanitized
126 $ hg cat -r $C2 target | head -n 10
127 abort: censored node: 1e0247a9a4b7
128 (set censor.policy to ignore errors)
129 $ hg cat -r $C1 target | head -n 10
130 abort: censored node: 613bc869fceb
131 (set censor.policy to ignore errors)
132 $ hg cat -r 0 target | head -n 10
133 Initially untainted file
134
135 Can only checkout target at uncensored revisions, -X is workaround for --all
136
137 $ hg revert -r $C2 target | head -n 10
138 abort: censored node: 1e0247a9a4b7
139 (set censor.policy to ignore errors)
140 $ hg revert -r $C1 target | head -n 10
141 abort: censored node: 613bc869fceb
142 (set censor.policy to ignore errors)
143 $ hg revert -r $C1 --all
144 reverting bystander
145 reverting target
146 abort: censored node: 613bc869fceb
147 (set censor.policy to ignore errors)
148 [255]
149 $ hg revert -r $C1 --all -X target
150 $ cat target | head -n 10
151 Tainted file now super sanitized
152 $ hg revert -r 0 --all
153 reverting target
154 $ cat target | head -n 10
155 Initially untainted file
156 $ hg revert -r $H2 --all
157 reverting bystander
158 reverting target
159 $ cat target | head -n 10
160 Tainted file now super sanitized
161
162 Uncensored file can be viewed at any revision
163
164 $ hg cat -r $H1 bystander | head -n 10
165 Normal file v2
166 $ hg cat -r $C2 bystander | head -n 10
167 Normal file v2
168 $ hg cat -r $C1 bystander | head -n 10
169 Normal file here
170 $ hg cat -r 0 bystander | head -n 10
171 Normal file here
172
173 Can update to children of censored revision
174
175 $ hg update -r $H1
176 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
177 $ cat target | head -n 10
178 Tainted file is now sanitized
179 $ hg update -r $H2
180 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
181 $ cat target | head -n 10
182 Tainted file now super sanitized
183
184 Set censor policy to abort in trusted $HGRC so hg verify fails
185
186 $ cp $HGRCPATH.orig $HGRCPATH
187 $ cat >> $HGRCPATH <<EOF
188 > [censor]
189 > policy = abort
190 > EOF
191
192 Repo fails verification due to censorship
193
194 $ hg verify
195 checking changesets
196 checking manifests
197 crosschecking files in changesets and manifests
198 checking files
199 target@1: censored file data
200 target@2: censored file data
201 not checking dirstate because of previous errors
202 checked 5 changesets with 7 changes to 2 files
203 2 integrity errors encountered!
204 (first damaged changeset appears to be 1)
205 [1]
206
207 Cannot update to revision with censored data
208
209 $ hg update -r $C2
210 abort: censored node: 1e0247a9a4b7
211 (set censor.policy to ignore errors)
212 [255]
213 $ hg update -r $C1
214 abort: censored node: 613bc869fceb
215 (set censor.policy to ignore errors)
216 [255]
217 $ hg update -r 0
218 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
219 $ hg update -r $H2
220 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
221
222 Set censor policy to ignore in trusted $HGRC so hg verify passes
223
224 $ cp $HGRCPATH.orig $HGRCPATH
225 $ cat >> $HGRCPATH <<EOF
226 > [censor]
227 > policy = ignore
228 > EOF
229
230 Repo passes verification with warnings with explicit config
231
232 $ hg verify -q
233
234 May update to revision with censored data with explicit config
235
236 $ hg update -r $C2
237 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
238 $ cat target | head -n 10
239 $ hg update -r $C1
240 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
241 $ cat target | head -n 10
242 $ hg update -r 0
243 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
244 $ cat target | head -n 10
245 Initially untainted file
246 $ hg update -r $H2
247 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
248 $ cat target | head -n 10
249 Tainted file now super sanitized
250
251 Can merge in revision with censored data. Test requires one branch of history
252 with the file censored, but we can't censor at a head, so advance H1.
253
254 $ hg update -r $H1
255 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
256 $ C3=$H1
257 $ echo 'advanced head H1' > target
258 $ hg ci -m 'advance head H1' target
259 $ H1=`hg id -r . -T "{node}"`
260 $ hg --config extensions.censor= censor -r $C3 target
261 checking for the censored content in 2 heads
262 checking for the censored content in the working directory
263 censoring 1 file revisions
264 $ hg update -r $H2
265 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
266 $ hg merge -r $C3
267 merging target
268 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
269 (branch merge, don't forget to commit)
270
271 Revisions present in repository heads may not be censored
272
273 $ hg update -C -r $H2
274 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
275 $ hg --config extensions.censor= censor -r $H2 target
276 checking for the censored content in 2 heads
277 abort: cannot censor file in heads (78a8fc215e79)
278 (clean/delete and commit first)
279 [255]
280 $ echo 'twiddling thumbs' > bystander
281 $ hg ci -m 'bystander commit'
282 $ H2=`hg id -r . -T "{node}"`
283 $ hg --config extensions.censor= censor -r "$H2^" target
284 checking for the censored content in 2 heads
285 abort: cannot censor file in heads (efbe78065929)
286 (clean/delete and commit first)
287 [255]
288
289 Cannot censor working directory
290
291 $ echo 'seriously no passwords' > target
292 $ hg ci -m 'extend second head arbitrarily' target
293 $ H2=`hg id -r . -T "{node}"`
294 $ hg update -r "$H2^"
295 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
296 $ hg --config extensions.censor= censor -r . target
297 checking for the censored content in 2 heads
298 checking for the censored content in the working directory
299 abort: cannot censor working directory
300 (clean/delete/update first)
301 [255]
302 $ hg update -r $H2
303 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
304
305 Can re-add file after being deleted + censored
306
307 $ C4=$H2
308 $ hg rm target
309 $ hg ci -m 'delete target so it may be censored'
310 $ H2=`hg id -r . -T "{node}"`
311 $ hg --config extensions.censor= censor -r $C4 target
312 checking for the censored content in 2 heads
313 checking for the censored content in the working directory
314 censoring 1 file revisions
315 $ hg cat -r $C4 target | head -n 10
316 $ hg cat -r "$H2^^" target | head -n 10
317 Tainted file now super sanitized
318 $ echo 'fresh start' > target
319 $ hg add target
320 $ hg ci -m reincarnated target
321 $ H2=`hg id -r . -T "{node}"`
322 $ hg cat -r $H2 target | head -n 10
323 fresh start
324 $ hg cat -r "$H2^" target | head -n 10
325 target: no such file in rev 452ec1762369
326 $ hg cat -r $C4 target | head -n 10
327 $ hg cat -r "$H2^^^" target | head -n 10
328 Tainted file now super sanitized
329
330 Can censor enough revision to move back to inline storage
331
332 $ hg debugrevlogstats | grep target
333 rev-count data-size inl type target
334 8 ??? no file target (glob) (revlogv2 !)
335 8 ??? yes file target (glob) (no-revlogv2 !)
336 $ $TESTDIR/seq.py 4000 | $TESTDIR/sha256line.py > target
337 $ hg ci -m 'add 100k passwords'
338 $ H2=`hg id -r . -T "{node}"`
339 $ C5=$H2
340 $ hg revert -r "$H2^" target
341 $ hg ci -m 'cleaned 100k passwords'
342 $ H2=`hg id -r . -T "{node}"`
343 $ hg debugrevlogstats | grep target
344 rev-count data-size inl type target
345 10 ?????? no file target (glob)
346 $ hg --config extensions.censor= censor -r $C5 target
347 checking for the censored content in 2 heads
348 checking for the censored content in the working directory
349 censoring 1 file revisions
350
351 The important part is for the censor operation to not crash and the repository
352 to not be corrupted. Right now this involve keeping the revlog split.
353
354 $ hg debugrevlogstats | grep target
355 rev-count data-size inl type target
356 10 ??? no file target (glob)
357 $ hg cat -r $C5 target | head -n 10
358 $ hg cat -r $H2 target | head -n 10
359 fresh start
360 $ hg verify
361 checking changesets
362 checking manifests
363 crosschecking files in changesets and manifests
364 checking files
365 checking dirstate
366 checked 12 changesets with 13 changes to 2 files
367
368 Repo with censored nodes can be cloned and cloned nodes are censored
369
370 $ cd ..
371 $ hg clone r rclone
372 updating to branch default
373 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
374 $ cd rclone
375 $ hg cat -r $H1 target | head -n 10
376 advanced head H1
377 $ hg cat -r $H2~5 target | head -n 10
378 Tainted file now super sanitized
379 $ hg cat -r $C2 target | head -n 10
380 $ hg cat -r $C1 target | head -n 10
381 $ hg cat -r 0 target | head -n 10
382 Initially untainted file
383 $ hg verify -q
384
385 Repo cloned before tainted content introduced can pull censored nodes
386
387 $ cd ../rpull
388 $ hg cat -r tip target | head -n 10
389 Initially untainted file
390 $ hg verify -q
391 $ hg pull -r $H1 -r $H2
392 pulling from $TESTTMP/r
393 searching for changes
394 adding changesets
395 adding manifests
396 adding file changes
397 added 11 changesets with 11 changes to 2 files (+1 heads)
398 new changesets * (glob)
399 (run 'hg heads' to see heads, 'hg merge' to merge)
400 $ hg update 4
401 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
402 $ cat target | head -n 10
403 Tainted file now super sanitized
404 $ hg cat -r $H1 target | head -n 10
405 advanced head H1
406 $ hg cat -r $H2~5 target | head -n 10
407 Tainted file now super sanitized
408 $ hg cat -r $C2 target | head -n 10
409 $ hg cat -r $C1 target | head -n 10
410 $ hg cat -r 0 target | head -n 10
411 Initially untainted file
412 $ hg verify -q
413
414 Censored nodes can be pushed if they censor previously unexchanged nodes
415
416 $ echo 'Passwords: hunter2hunter2' > target
417 $ hg ci -m 're-add password from clone' target
418 created new head
419 $ H3=`hg id -r . -T "{node}"`
420 $ REV=$H3
421 $ echo 'Re-sanitized; nothing to see here' > target
422 $ hg ci -m 're-sanitized' target
423 $ H2=`hg id -r . -T "{node}"`
424 $ CLEANREV=$H2
425 $ hg cat -r $REV target | head -n 10
426 Passwords: hunter2hunter2
427 $ hg --config extensions.censor= censor -r $REV target
428 checking for the censored content in 3 heads
429 checking for the censored content in the working directory
430 censoring 1 file revisions
431 $ hg cat -r $REV target | head -n 10
432 $ hg cat -r $CLEANREV target | head -n 10
433 Re-sanitized; nothing to see here
434 $ hg push -f -r $H2
435 pushing to $TESTTMP/r
436 searching for changes
437 adding changesets
438 adding manifests
439 adding file changes
440 added 2 changesets with 2 changes to 1 files (+1 heads)
441
442 $ cd ../r
443 $ hg cat -r $REV target | head -n 10
444 $ hg cat -r $CLEANREV target | head -n 10
445 Re-sanitized; nothing to see here
446 $ hg update $CLEANREV
447 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
448 $ cat target | head -n 10
449 Re-sanitized; nothing to see here
450
451 Censored nodes can be bundled up and unbundled in another repo
452
453 $ hg bundle --base 0 ../pwbundle
454 13 changesets found
455 $ cd ../rclone
456 $ hg unbundle ../pwbundle
457 adding changesets
458 adding manifests
459 adding file changes
460 added 2 changesets with 2 changes to 2 files (+1 heads)
461 new changesets * (glob)
462 (run 'hg heads .' to see heads, 'hg merge' to merge)
463 $ hg cat -r $REV target | head -n 10
464 $ hg cat -r $CLEANREV target | head -n 10
465 Re-sanitized; nothing to see here
466 $ hg update $CLEANREV
467 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
468 $ cat target | head -n 10
469 Re-sanitized; nothing to see here
470 $ hg verify -q
471
472 Grepping only warns, doesn't error out
473
474 $ cd ../rpull
475 $ hg grep 'Normal file'
476 bystander:Normal file v2
477 $ hg grep nothing
478 target:Re-sanitized; nothing to see here
479 $ hg grep --diff 'Normal file'
480 cannot search in censored file: target:7
481 cannot search in censored file: target:10
482 cannot search in censored file: target:12
483 bystander:6:-:Normal file v2
484 cannot search in censored file: target:1
485 cannot search in censored file: target:2
486 cannot search in censored file: target:3
487 bystander:2:-:Normal file here
488 bystander:2:+:Normal file v2
489 bystander:0:+:Normal file here
490 $ hg grep --diff nothing
491 cannot search in censored file: target:7
492 cannot search in censored file: target:10
493 cannot search in censored file: target:12
494 target:13:+:Re-sanitized; nothing to see here
495 cannot search in censored file: target:1
496 cannot search in censored file: target:2
497 cannot search in censored file: target:3
498
499 Censored nodes can be imported on top of censored nodes, consecutively
500
501 $ hg init ../rimport
502 $ hg bundle --base 1 ../rimport/splitbundle
503 12 changesets found
504 $ cd ../rimport
505 $ hg pull -r $H1 -r $H2 ../r
506 pulling from ../r
507 adding changesets
508 adding manifests
509 adding file changes
510 added 8 changesets with 10 changes to 2 files (+1 heads)
511 new changesets e97f55b2665a:dcbaf17bf3a1
512 (run 'hg heads' to see heads, 'hg merge' to merge)
513 $ hg unbundle splitbundle
514 adding changesets
515 adding manifests
516 adding file changes
517 added 6 changesets with 5 changes to 2 files (+1 heads)
518 new changesets * (glob)
519 (run 'hg heads .' to see heads, 'hg merge' to merge)
520 $ hg update $H2
521 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
522 $ cat target | head -n 10
523 Re-sanitized; nothing to see here
524 $ hg verify -q
525 $ cd ../r
526
527 Can import bundle where first revision of a file is censored
528
529 $ hg init ../rinit
530 $ hg --config extensions.censor= censor -r 0 target
531 checking for the censored content in 3 heads
532 checking for the censored content in the working directory
533 censoring 1 file revisions
534 $ hg bundle -r 0 --base null ../rinit/initbundle
535 1 changesets found
536 $ cd ../rinit
537 $ hg unbundle initbundle
538 adding changesets
539 adding manifests
540 adding file changes
541 added 1 changesets with 2 changes to 2 files
542 new changesets e97f55b2665a (1 drafts)
543 (run 'hg update' to get a working copy)
544 $ hg cat -r 0 target | head -n 10
545
546 Can skip the head checking steps
547
548 $ hg --config extensions.censor= censor -r 0 --no-check-heads target
549 checking for the censored content in the working directory
550 censoring 1 file revisions
551
552 Can censor multiple revision in one go.
553
554 $ cd ../r
555 $ hg --config extensions.censor= censor -r 0+1 target
556 checking for the censored content in 3 heads
557 checking for the censored content in the working directory
558 censoring 2 file revisions
559
560
561
562 #if revlogv2
563
564 Testing feature that does not work in revlog v1
565 ===============================================
566
567 Censoring a revision that is used as delta base
568 -----------------------------------------------
569
570 $ cd ..
571 $ hg init censor-with-delta
572 $ cd censor-with-delta
573 $ echo root > target
574 $ hg add target
575 $ hg commit -m root
576 $ B0=`hg id -r . -T "{node}"`
577 >>> with open('target', 'ab') as fp:
578 ... fp.write(b'\n'.join([b'Password: hunter%d' % x for x in range(0, 50001)])) and None
579 ... fp.write(b'\n') and None
580
581 $ hg ci -m 'write a long file'
582 $ B1=`hg id -r . -T "{node}"`
583 $ echo 'small change (should create a delta)' >> target
584 $ hg ci -m 'create a delta over the password'
585 (should show that the last revision is a delta, not a snapshot)
586 $ B2=`hg id -r . -T "{node}"`
587
588 Make sure the last revision is a delta against the revision we will censor
589
590 $ hg debugdeltachain target -T '{rev} {chainid} {chainlen} {prevrev}\n'
591 0 1 1 -1
592 1 2 1 -1
593 2 2 2 1
594
595 Censor the file
596
597 $ hg cat -r $B1 target | wc -l
598 *50002 (re)
599 $ hg --config extensions.censor= censor -r $B1 target
600 checking for the censored content in 1 heads
601 checking for the censored content in the working directory
602 censoring 1 file revisions
603 $ hg cat -r $B1 target | wc -l
604 *0 (re)
605
606 Check the children is fine
607
608 $ hg cat -r $B2 target | wc -l
609 *50003 (re)
610
611 #endif
612
613 Testing repository upgrade with censors revision
614 ================================================
615
616 $ cd ../rclone
617
618 With the "abort" policy
619 =======================
620
621 $ hg verify --config censor.policy=ignore
622 checking changesets
623 checking manifests
624 crosschecking files in changesets and manifests
625 checking files
626 checking dirstate
627 checked 14 changesets with 15 changes to 2 files
628 $ hg debugupgraderepo --run --quiet \
629 > --optimize re-delta-parent \
630 > --config censor.policy=abort
631 upgrade will perform the following actions:
632
633 requirements
634 preserved: * (glob)
635
636 optimisations: re-delta-parent
637
638 processed revlogs:
639 - all-filelogs
640 - changelog
641 - manifest
642
643 $ hg verify --config censor.policy=ignore
644 checking changesets
645 checking manifests
646 crosschecking files in changesets and manifests
647 checking files
648 checking dirstate
649 checked 14 changesets with 15 changes to 2 files
650
651 With the "ignore" policy
652 ========================
653
654 $ hg verify --config censor.policy=ignore
655 checking changesets
656 checking manifests
657 crosschecking files in changesets and manifests
658 checking files
659 checking dirstate
660 checked 14 changesets with 15 changes to 2 files
661 $ hg debugupgraderepo --run --quiet \
662 > --optimize re-delta-parent \
663 > --config censor.policy=ignore
664 upgrade will perform the following actions:
665
666 requirements
667 preserved: * (glob)
668
669 optimisations: re-delta-parent
670
671 processed revlogs:
672 - all-filelogs
673 - changelog
674 - manifest
675
676 $ hg verify --config censor.policy=ignore
677 checking changesets
678 checking manifests
679 crosschecking files in changesets and manifests
680 checking files
681 checking dirstate
682 checked 14 changesets with 15 changes to 2 files