##// END OF EJS Templates
subrepo: extend path auditing test to include more weird patterns (SEC)...
Yuya Nishihara -
r41549:31286c92 stable
parent child Browse files
Show More
@@ -36,6 +36,330 b' on clone (and update):'
36 abort: path 'sub/.hg' is inside nested repo 'sub'
36 abort: path 'sub/.hg' is inside nested repo 'sub'
37 [255]
37 [255]
38
38
39 Test absolute path
40 ------------------
41
42 on commit:
43
44 $ hg init absolutepath
45 $ cd absolutepath
46 $ hg init sub
47 $ echo '/sub = sub' >> .hgsub
48 $ hg ci -qAm 'add subrepo "/sub"'
49 abort: path contains illegal component: /sub
50 [255]
51
52 prepare tampered repo (including the commit above):
53
54 $ hg import --bypass -qm 'add subrepo "/sub"' - <<'EOF'
55 > diff --git a/.hgsub b/.hgsub
56 > new file mode 100644
57 > --- /dev/null
58 > +++ b/.hgsub
59 > @@ -0,0 +1,1 @@
60 > +/sub = sub
61 > diff --git a/.hgsubstate b/.hgsubstate
62 > new file mode 100644
63 > --- /dev/null
64 > +++ b/.hgsubstate
65 > @@ -0,0 +1,1 @@
66 > +0000000000000000000000000000000000000000 /sub
67 > EOF
68 $ cd ..
69
70 on clone (and update):
71
72 $ hg clone -q absolutepath absolutepath2
73 abort: path contains illegal component: /sub
74 [255]
75
76 Test root path
77 --------------
78
79 on commit:
80
81 $ hg init rootpath
82 $ cd rootpath
83 $ hg init sub
84 $ echo '/ = sub' >> .hgsub
85 $ hg ci -qAm 'add subrepo "/"'
86 abort: path ends in directory separator: /
87 [255]
88
89 prepare tampered repo (including the commit above):
90
91 $ hg import --bypass -qm 'add subrepo "/"' - <<'EOF'
92 > diff --git a/.hgsub b/.hgsub
93 > new file mode 100644
94 > --- /dev/null
95 > +++ b/.hgsub
96 > @@ -0,0 +1,1 @@
97 > +/ = sub
98 > diff --git a/.hgsubstate b/.hgsubstate
99 > new file mode 100644
100 > --- /dev/null
101 > +++ b/.hgsubstate
102 > @@ -0,0 +1,1 @@
103 > +0000000000000000000000000000000000000000 /
104 > EOF
105 $ cd ..
106
107 on clone (and update):
108
109 $ hg clone -q rootpath rootpath2
110 abort: path ends in directory separator: /
111 [255]
112
113 Test empty path
114 ---------------
115
116 on commit:
117
118 $ hg init emptypath
119 $ cd emptypath
120 $ hg init sub
121 $ echo '= sub' >> .hgsub
122 $ hg ci -qAm 'add subrepo ""'
123 hg: parse error at .hgsub:1: = sub
124 [255]
125
126 prepare tampered repo (including the commit above):
127
128 $ hg import --bypass -qm 'add subrepo ""' - <<'EOF'
129 > diff --git a/.hgsub b/.hgsub
130 > new file mode 100644
131 > --- /dev/null
132 > +++ b/.hgsub
133 > @@ -0,0 +1,1 @@
134 > += sub
135 > diff --git a/.hgsubstate b/.hgsubstate
136 > new file mode 100644
137 > --- /dev/null
138 > +++ b/.hgsubstate
139 > @@ -0,0 +1,1 @@
140 > +0000000000000000000000000000000000000000
141 > EOF
142 $ cd ..
143
144 on clone (and update):
145
146 $ hg clone -q emptypath emptypath2
147 hg: parse error at .hgsub:1: = sub
148 [255]
149
150 Test current path
151 -----------------
152
153 on commit:
154 BROKEN: should fail
155
156 $ hg init currentpath
157 $ cd currentpath
158 $ hg init sub
159 $ echo '. = sub' >> .hgsub
160 $ hg ci -qAm 'add subrepo "."'
161 $ cd ..
162
163 on clone (and update):
164
165 $ hg clone -q currentpath currentpath2 --config ui.timeout=1
166 waiting for lock on working directory of $TESTTMP/currentpath2/. * (glob)
167 abort: working directory of $TESTTMP/currentpath2/.: timed out waiting for lock held by '*' (glob)
168 [255]
169
170 Test outer path
171 ---------------
172
173 on commit:
174
175 $ mkdir outerpath
176 $ cd outerpath
177 $ hg init main
178 $ cd main
179 $ hg init ../sub
180 $ echo '../sub = ../sub' >> .hgsub
181 $ hg ci -qAm 'add subrepo "../sub"'
182 abort: path contains illegal component: ../sub
183 [255]
184
185 prepare tampered repo (including the commit above):
186
187 $ hg import --bypass -qm 'add subrepo "../sub"' - <<'EOF'
188 > diff --git a/.hgsub b/.hgsub
189 > new file mode 100644
190 > --- /dev/null
191 > +++ b/.hgsub
192 > @@ -0,0 +1,1 @@
193 > +../sub = ../sub
194 > diff --git a/.hgsubstate b/.hgsubstate
195 > new file mode 100644
196 > --- /dev/null
197 > +++ b/.hgsubstate
198 > @@ -0,0 +1,1 @@
199 > +0000000000000000000000000000000000000000 ../sub
200 > EOF
201 $ cd ..
202
203 on clone (and update):
204
205 $ hg clone -q main main2
206 abort: path contains illegal component: ../sub
207 [255]
208 $ cd ..
209
210 Test variable expansion
211 -----------------------
212
213 Subrepository paths shouldn't be expanded, but we fail to handle them
214 properly. Any local repository paths are expanded.
215
216 on commit:
217 BROKEN: wrong error message
218
219 $ mkdir envvar
220 $ cd envvar
221 $ hg init main
222 $ cd main
223 $ hg init sub1
224 $ cat <<'EOF' > sub1/hgrc
225 > [hooks]
226 > log = echo pwned
227 > EOF
228 $ hg -R sub1 ci -qAm 'add sub1 files'
229 $ hg -R sub1 log -r. -T '{node}\n'
230 39eb4b4d3e096527668784893a9280578a8f38b8
231 $ echo '$SUB = sub1' >> .hgsub
232 $ SUB=sub1 hg ci -qAm 'add subrepo "$SUB"'
233 abort: repository $TESTTMP/envvar/main/$SUB already exists!
234 [255]
235
236 prepare tampered repo (including the changes above as two commits):
237
238 $ hg import --bypass -qm 'add subrepo "$SUB"' - <<'EOF'
239 > diff --git a/.hgsub b/.hgsub
240 > new file mode 100644
241 > --- /dev/null
242 > +++ b/.hgsub
243 > @@ -0,0 +1,1 @@
244 > +$SUB = sub1
245 > diff --git a/.hgsubstate b/.hgsubstate
246 > new file mode 100644
247 > --- /dev/null
248 > +++ b/.hgsubstate
249 > @@ -0,0 +1,1 @@
250 > +0000000000000000000000000000000000000000 $SUB
251 > EOF
252 $ hg debugsetparents 0
253 $ hg import --bypass -qm 'update subrepo "$SUB"' - <<'EOF'
254 > diff --git a/.hgsubstate b/.hgsubstate
255 > --- a/.hgsubstate
256 > +++ b/.hgsubstate
257 > @@ -1,1 +1,1 @@
258 > -0000000000000000000000000000000000000000 $SUB
259 > +39eb4b4d3e096527668784893a9280578a8f38b8 $SUB
260 > EOF
261 $ cd ..
262
263 on clone (and update) with various substitutions:
264
265 $ hg clone -q main main2
266 $ ls main2
267 $SUB
268
269 $ SUB=sub1 hg clone -q main main3
270 $ ls main3
271 sub1
272
273 $ SUB=sub2 hg clone -q main main4
274 $ ls main4
275 sub2
276
277 on clone empty subrepo into .hg, then pull (and update), which at least fails:
278 BROKEN: the first clone should fail
279
280 $ SUB=.hg hg clone -qr0 main main5
281 $ ls main5
282 $ ls -d main5/.hg/.hg
283 main5/.hg/.hg
284 $ SUB=.hg hg -R main5 pull -u
285 pulling from $TESTTMP/envvar/main
286 searching for changes
287 adding changesets
288 adding manifests
289 adding file changes
290 added 1 changesets with 1 changes to 1 files
291 new changesets 7a2f0e59146f
292 abort: repository $TESTTMP/envvar/main5/$SUB already exists!
293 [255]
294 $ cat main5/.hg/hgrc | grep pwned
295 [1]
296
297 on clone (and update) into .hg, which at least fails:
298
299 $ SUB=.hg hg clone -q main main6
300 abort: destination '$TESTTMP/envvar/main6/.hg' is not empty (in subrepository ".hg")
301 [255]
302 $ ls main6
303 $ cat main6/.hg/hgrc | grep pwned
304 [1]
305
306 on clone (and update) into .hg/* subdir:
307 BROKEN: should fail
308
309 $ SUB=.hg/foo hg clone -q main main7
310 $ ls main7
311 $ ls main7/.hg/foo
312 hgrc
313
314 on clone (and update) into outer tree:
315 BROKEN: should fail
316
317 $ SUB=../out-of-tree-write hg clone -q main main8
318 $ ls main8
319
320 on clone (and update) into e.g. $HOME, which doesn't work since subrepo paths
321 are concatenated prior to variable expansion:
322
323 $ SUB="$TESTTMP/envvar/fakehome" hg clone -q main main9
324 $ ls main9 | wc -l
325 \s*1 (re)
326
327 $ ls
328 main
329 main2
330 main3
331 main4
332 main5
333 main6
334 main7
335 main8
336 main9
337 out-of-tree-write
338 $ cd ..
339
340 Test tilde
341 ----------
342
343 The leading tilde may be expanded to $HOME, but it's a valid subrepo path.
344 However, we might want to prohibit it as it seems potentially unsafe.
345
346 on commit:
347
348 $ hg init tilde
349 $ cd tilde
350 $ hg init './~'
351 $ echo '~ = ~' >> .hgsub
352 $ hg ci -qAm 'add subrepo "~"'
353 $ ls
354 ~
355 $ cd ..
356
357 on clone (and update):
358
359 $ hg clone -q tilde tilde2
360 $ ls tilde2
361 ~
362
39 Test direct symlink traversal
363 Test direct symlink traversal
40 -----------------------------
364 -----------------------------
41
365
@@ -130,3 +454,166 b' on clone (and update):'
130 root
454 root
131
455
132 #endif
456 #endif
457
458 Test symlink traversal by variable expansion
459 --------------------------------------------
460
461 #if symlink
462
463 $ FAKEHOME="$TESTTMP/envvarsym/fakehome"
464
465 on commit:
466 BROKEN: wrong error message
467
468 $ mkdir envvarsym
469 $ cd envvarsym
470 $ hg init main
471 $ cd main
472 $ ln -s "`echo "$FAKEHOME" | sed 's|\(.\)/.*|\1|'`"
473 $ hg ci -qAm 'add symlink to top-level system directory'
474
475 $ hg init sub1
476 $ echo pwned > sub1/pwned
477 $ hg -R sub1 ci -qAm 'add sub1 files'
478 $ hg -R sub1 log -r. -T '{node}\n'
479 f40c9134ba1b6961e12f250868823f0092fb68a8
480 $ echo '$SUB = sub1' >> .hgsub
481 $ SUB="$FAKEHOME" hg ci -qAm 'add subrepo "$SUB"'
482 abort: repository $TESTTMP/envvarsym/main/$SUB already exists!
483 [255]
484
485 prepare tampered repo (including the changes above as two commits):
486
487 $ hg import --bypass -qm 'add subrepo "$SUB"' - <<'EOF'
488 > diff --git a/.hgsub b/.hgsub
489 > new file mode 100644
490 > --- /dev/null
491 > +++ b/.hgsub
492 > @@ -0,0 +1,1 @@
493 > +$SUB = sub1
494 > diff --git a/.hgsubstate b/.hgsubstate
495 > new file mode 100644
496 > --- /dev/null
497 > +++ b/.hgsubstate
498 > @@ -0,0 +1,1 @@
499 > +0000000000000000000000000000000000000000 $SUB
500 > EOF
501 $ hg debugsetparents 1
502 $ hg import --bypass -qm 'update subrepo "$SUB"' - <<'EOF'
503 > diff --git a/.hgsubstate b/.hgsubstate
504 > --- a/.hgsubstate
505 > +++ b/.hgsubstate
506 > @@ -1,1 +1,1 @@
507 > -0000000000000000000000000000000000000000 $SUB
508 > +f40c9134ba1b6961e12f250868823f0092fb68a8 $SUB
509 > EOF
510 $ cd ..
511
512 on clone (and update) without fakehome directory:
513 BROKEN: should fail
514
515 $ rm -fR "$FAKEHOME"
516 $ SUB="$FAKEHOME" hg clone -q main main2
517 $ ls "$FAKEHOME"
518 pwned
519
520 on clone (and update) with empty fakehome directory:
521 BROKEN: should fail
522
523 $ rm -fR "$FAKEHOME"
524 $ mkdir "$FAKEHOME"
525 $ SUB="$FAKEHOME" hg clone -q main main3
526 $ ls "$FAKEHOME"
527 pwned
528
529 on clone (and update) with non-empty fakehome directory:
530 BROKEN: wrong error message
531
532 $ rm -fR "$FAKEHOME"
533 $ mkdir "$FAKEHOME"
534 $ touch "$FAKEHOME/a"
535 $ SUB="$FAKEHOME" hg clone -q main main4
536 abort: destination '$TESTTMP/envvarsym/fakehome' is not empty (in subrepository "*") (glob)
537 [255]
538 $ ls "$FAKEHOME"
539 a
540
541 on clone empty subrepo with non-empty fakehome directory,
542 then pull (and update):
543 BROKEN: the first clone should fail
544
545 $ rm -fR "$FAKEHOME"
546 $ mkdir "$FAKEHOME"
547 $ touch "$FAKEHOME/a"
548 $ SUB="$FAKEHOME" hg clone -qr1 main main5
549 $ ls "$FAKEHOME"
550 a
551 $ ls -d "$FAKEHOME/.hg"
552 $TESTTMP/envvarsym/fakehome/.hg
553 $ SUB="$FAKEHOME" hg -R main5 pull -u
554 pulling from $TESTTMP/envvarsym/main
555 searching for changes
556 adding changesets
557 adding manifests
558 adding file changes
559 added 1 changesets with 1 changes to 1 files
560 new changesets * (glob)
561 abort: repository $TESTTMP/envvarsym/main5/$SUB already exists!
562 [255]
563 $ ls "$FAKEHOME"
564 a
565
566 on clone empty subrepo with hg-managed fakehome directory,
567 then pull (and update):
568 BROKEN: wrong error message
569
570 $ rm -fR "$FAKEHOME"
571 $ hg init "$FAKEHOME"
572 $ touch "$FAKEHOME/a"
573 $ hg -R "$FAKEHOME" ci -qAm 'add fakehome file'
574 $ SUB="$FAKEHOME" hg clone -qr1 main main6
575 abort: repository $TESTTMP/envvarsym/main6/$SUB already exists!
576 [255]
577 $ ls "$FAKEHOME"
578 a
579 $ SUB="$FAKEHOME" hg -R main6 pull -u
580 pulling from $TESTTMP/envvarsym/main
581 searching for changes
582 adding changesets
583 adding manifests
584 adding file changes
585 added 1 changesets with 1 changes to 1 files
586 new changesets * (glob)
587 .hgsubstate: untracked file differs
588 abort: untracked files in working directory differ from files in requested revision
589 [255]
590 $ ls "$FAKEHOME"
591 a
592
593 on clone only symlink with hg-managed fakehome directory,
594 then pull (and update):
595 BROKEN: wrong error message
596
597 $ rm -fR "$FAKEHOME"
598 $ hg init "$FAKEHOME"
599 $ touch "$FAKEHOME/a"
600 $ hg -R "$FAKEHOME" ci -qAm 'add fakehome file'
601 $ SUB="$FAKEHOME" hg clone -qr0 main main7
602 $ ls "$FAKEHOME"
603 a
604 $ SUB="$FAKEHOME" hg -R main7 pull -uf
605 pulling from $TESTTMP/envvarsym/main
606 searching for changes
607 adding changesets
608 adding manifests
609 adding file changes
610 added 2 changesets with 3 changes to 2 files
611 new changesets * (glob)
612 abort: repository $TESTTMP/envvarsym/main7/$SUB already exists!
613 [255]
614 $ ls "$FAKEHOME"
615 a
616
617 $ cd ..
618
619 #endif
General Comments 0
You need to be logged in to leave comments. Login now