t / t7510-signed-commit.shon commit rebase -i: fix post-rewrite hook with failed exec command (b12d3e9)
   1#!/bin/sh
   2
   3test_description='signed commit tests'
   4. ./test-lib.sh
   5. "$TEST_DIRECTORY/lib-gpg.sh"
   6
   7test_expect_success GPG 'create signed commits' '
   8        test_when_finished "test_unconfig commit.gpgsign" &&
   9
  10        echo 1 >file && git add file &&
  11        test_tick && git commit -S -m initial &&
  12        git tag initial &&
  13        git branch side &&
  14
  15        echo 2 >file && test_tick && git commit -a -S -m second &&
  16        git tag second &&
  17
  18        git checkout side &&
  19        echo 3 >elif && git add elif &&
  20        test_tick && git commit -m "third on side" &&
  21
  22        git checkout master &&
  23        test_tick && git merge -S side &&
  24        git tag merge &&
  25
  26        echo 4 >file && test_tick && git commit -a -m "fourth unsigned" &&
  27        git tag fourth-unsigned &&
  28
  29        test_tick && git commit --amend -S -m "fourth signed" &&
  30        git tag fourth-signed &&
  31
  32        git config commit.gpgsign true &&
  33        echo 5 >file && test_tick && git commit -a -m "fifth signed" &&
  34        git tag fifth-signed &&
  35
  36        git config commit.gpgsign false &&
  37        echo 6 >file && test_tick && git commit -a -m "sixth" &&
  38        git tag sixth-unsigned &&
  39
  40        git config commit.gpgsign true &&
  41        echo 7 >file && test_tick && git commit -a -m "seventh" --no-gpg-sign &&
  42        git tag seventh-unsigned &&
  43
  44        test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
  45        git tag seventh-signed
  46
  47        echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
  48        git tag eighth-signed-alt
  49'
  50
  51test_expect_success GPG 'show signatures' '
  52        (
  53                for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
  54                do
  55                        git show --pretty=short --show-signature $commit >actual &&
  56                        grep "Good signature from" actual &&
  57                        ! grep "BAD signature from" actual &&
  58                        echo $commit OK || exit 1
  59                done
  60        ) &&
  61        (
  62                for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
  63                do
  64                        git show --pretty=short --show-signature $commit >actual &&
  65                        ! grep "Good signature from" actual &&
  66                        ! grep "BAD signature from" actual &&
  67                        echo $commit OK || exit 1
  68                done
  69        ) &&
  70        (
  71                for commit in eighth-signed-alt
  72                do
  73                        git show --pretty=short --show-signature $commit >actual &&
  74                        grep "Good signature from" actual &&
  75                        ! grep "BAD signature from" actual &&
  76                        grep "not certified" actual &&
  77                        echo $commit OK || exit 1
  78                done
  79        )
  80'
  81
  82test_expect_success GPG 'detect fudged signature' '
  83        git cat-file commit seventh-signed >raw &&
  84
  85        sed -e "s/seventh/7th forged/" raw >forged1 &&
  86        git hash-object -w -t commit forged1 >forged1.commit &&
  87        git show --pretty=short --show-signature $(cat forged1.commit) >actual1 &&
  88        grep "BAD signature from" actual1 &&
  89        ! grep "Good signature from" actual1
  90'
  91
  92test_expect_success GPG 'detect fudged signature with NUL' '
  93        git cat-file commit seventh-signed >raw &&
  94        cat raw >forged2 &&
  95        echo Qwik | tr "Q" "\000" >>forged2 &&
  96        git hash-object -w -t commit forged2 >forged2.commit &&
  97        git show --pretty=short --show-signature $(cat forged2.commit) >actual2 &&
  98        grep "BAD signature from" actual2 &&
  99        ! grep "Good signature from" actual2
 100'
 101
 102test_expect_success GPG 'amending already signed commit' '
 103        git checkout fourth-signed^0 &&
 104        git commit --amend -S --no-edit &&
 105        git show -s --show-signature HEAD >actual &&
 106        grep "Good signature from" actual &&
 107        ! grep "BAD signature from" actual
 108'
 109
 110test_expect_success GPG 'show good signature with custom format' '
 111        cat >expect <<-\EOF &&
 112        G
 113        13B6F51ECDDE430D
 114        C O Mitter <committer@example.com>
 115        EOF
 116        git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
 117        test_cmp expect actual
 118'
 119
 120test_expect_success GPG 'show bad signature with custom format' '
 121        cat >expect <<-\EOF &&
 122        B
 123        13B6F51ECDDE430D
 124        C O Mitter <committer@example.com>
 125        EOF
 126        git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
 127        test_cmp expect actual
 128'
 129
 130test_expect_success GPG 'show unknown signature with custom format' '
 131        cat >expect <<-\EOF &&
 132        U
 133        61092E85B7227189
 134        Eris Discordia <discord@example.net>
 135        EOF
 136        git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
 137        test_cmp expect actual
 138'
 139
 140test_expect_success GPG 'show lack of signature with custom format' '
 141        cat >expect <<-\EOF &&
 142        N
 143
 144
 145        EOF
 146        git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
 147        test_cmp expect actual
 148'
 149
 150test_done