]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5546-receive-limits.sh
Merge branch 'js/doc-unit-tests'
[thirdparty/git.git] / t / t5546-receive-limits.sh
1 #!/bin/sh
2
3 test_description='check receive input limits'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 # Let's run tests with different unpack limits: 1 and 10000
9 # When the limit is 1, `git receive-pack` will call `git index-pack`.
10 # When the limit is 10000, `git receive-pack` will call `git unpack-objects`.
11
12 validate_store_type () {
13 git -C dest count-objects -v >actual &&
14 case "$store_type" in
15 index)
16 grep "^count: 0$" actual ;;
17 unpack)
18 grep "^packs: 0$" actual ;;
19 esac || {
20 echo "store_type is $store_type"
21 cat actual
22 false;
23 }
24 }
25
26 test_pack_input_limit () {
27 store_type=$1
28
29 case "$store_type" in
30 index) unpack_limit=1 other_limit=10000 ;;
31 unpack) unpack_limit=10000 other_limit=1 ;;
32 esac
33
34 test_expect_success 'prepare destination repository' '
35 rm -fr dest &&
36 git --bare init dest
37 '
38
39 test_expect_success "set unpacklimit to $unpack_limit" '
40 git --git-dir=dest config receive.unpacklimit "$unpack_limit"
41 '
42
43 test_expect_success 'setting receive.maxInputSize to 512 rejects push' '
44 git --git-dir=dest config receive.maxInputSize 512 &&
45 test_must_fail git push dest HEAD
46 '
47
48 test_expect_success 'bumping limit to 4k allows push' '
49 git --git-dir=dest config receive.maxInputSize 4k &&
50 git push dest HEAD
51 '
52
53 test_expect_success 'prepare destination repository (again)' '
54 rm -fr dest &&
55 git --bare init dest
56 '
57
58 test_expect_success 'lifting the limit allows push' '
59 git --git-dir=dest config receive.maxInputSize 0 &&
60 git push dest HEAD
61 '
62
63 test_expect_success 'prepare destination repository (once more)' '
64 rm -fr dest &&
65 git --bare init dest
66 '
67
68 test_expect_success 'receive trumps transfer' '
69 git --git-dir=dest config receive.unpacklimit "$unpack_limit" &&
70 git --git-dir=dest config transfer.unpacklimit "$other_limit" &&
71 git push dest HEAD &&
72 validate_store_type
73 '
74
75 }
76
77 test_expect_success "create known-size (1024 bytes) commit" '
78 test-tool genrandom foo 1024 >one-k &&
79 git add one-k &&
80 test_commit one-k
81 '
82
83 test_pack_input_limit index
84 test_pack_input_limit unpack
85
86 test_done