diff options
Diffstat (limited to 'internal/git/catfile/parser_test.go')
-rw-r--r-- | internal/git/catfile/parser_test.go | 199 |
1 files changed, 0 insertions, 199 deletions
diff --git a/internal/git/catfile/parser_test.go b/internal/git/catfile/parser_test.go index 6d2e6d53c..b54251965 100644 --- a/internal/git/catfile/parser_test.go +++ b/internal/git/catfile/parser_test.go @@ -1,215 +1,16 @@ package catfile import ( - "bytes" "fmt" - "strings" "testing" - "time" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" - "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb" "google.golang.org/protobuf/types/known/timestamppb" ) -func TestParser_ParseCommit(t *testing.T) { - t.Parallel() - - info := &ObjectInfo{ - Oid: gittest.DefaultObjectHash.EmptyTreeOID, - Type: "commit", - } - - // Valid-but-interesting commits should be test at the FindCommit level. - // Invalid objects (that Git would complain about during fsck) can be - // tested here. - // - // Once a repository contains a pathological object it can be hard to get - // rid of it. Because of this I think it's nicer to ignore such objects - // than to throw hard errors. - for _, tc := range []struct { - desc string - in string - out *gitalypb.GitCommit - }{ - { - desc: "empty commit object", - in: "", - out: &gitalypb.GitCommit{Id: info.Oid.String()}, - }, - { - desc: "no email", - in: "author Jane Doe", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe")}, - }, - }, - { - desc: "unmatched <", - in: "author Jane Doe <janedoe@example.com", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe")}, - }, - }, - { - desc: "unmatched >", - in: "author Jane Doe janedoe@example.com>", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe janedoe@example.com>")}, - }, - }, - { - desc: "missing date", - in: "author Jane Doe <janedoe@example.com> ", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe"), Email: []byte("janedoe@example.com")}, - }, - }, - { - desc: "date too high", - in: "author Jane Doe <janedoe@example.com> 9007199254740993 +0200", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{ - Name: []byte("Jane Doe"), - Email: []byte("janedoe@example.com"), - Date: ×tamppb.Timestamp{Seconds: 9223371974719179007}, - Timezone: []byte("+0200"), - }, - }, - }, - { - desc: "date negative", - in: "author Jane Doe <janedoe@example.com> -1 +0200", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{ - Name: []byte("Jane Doe"), - Email: []byte("janedoe@example.com"), - Date: ×tamppb.Timestamp{Seconds: 9223371974719179007}, - Timezone: []byte("+0200"), - }, - }, - }, - { - desc: "ssh signature", - in: `gpgsig -----BEGIN SSH SIGNATURE----- -U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgtc+Qk8jhMwVZk/jFEFCM16LNQb -30q5kK30bbetfjyTMAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 -AAAAQLSyv010gOFwIs9QTtDvlfIEWiAw2iQL/T9usGcxHXn/W5l0cOFCd7O+WaMDg0t0nW -fF3T79iV8paT4/OfX8Ygg= ------END SSH SIGNATURE-----`, - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - SignatureType: gitalypb.SignatureType_SSH, - }, - }, - { - desc: "SHA256 signature", - in: fmt.Sprintf(`gpgsig-sha256 -----BEGIN PGP SIGNATURE----- -Version: ObjectivePGP -Comment: https://www.objectivepgp.com -Charset: UTF-8 -%c -wsFcBAABCgAGBQJecon1AAoJEDYMjTn1G2THmSsP/At/jskLdF0i7p0nKf4JLjeeqRJ4k2IUg87U -ZwV6mbLo5XFm8Sq7CJBAGAhlOZE4BAwKALuawmgs5XMEZwK2z6AIgosGTVpmxDTTI11bXt4XIOdz -qF7c/gUrJOZzjFXOqDsd5UuPRupwznC5eKlLbfImR+NYxKryo8JGdF5t52ph4kChcQsKlSkXuYNI -+9UgbaMclEjb0OLm+mcP9QxW+Cs9JS2Jb4Jh6XONWW1nDN3ZTDDskguIqqF47UxIgSImrmpMcEj9 -YSNU0oMoHM4+1DoXp1t99EGPoAMvO+a5g8gd1jouCIrI6KOX+GeG/TFFM0mQwg/d/N9LR049m8ed -vgqg/lMiWUxQGL2IPpYPcgiUEqfn7ete+NMzQV5zstxF/q7Yj2BhM2L7FPHxKaoy/w5Q/DcAO4wN -5gxVmIvbCDk5JOx8I+boIS8ZxSvIlJ5IWaPrcjg5Mc40it+WHvMqxVnCzH0c6KcXaJ2SibVb59HR -pdRhEXXw/hRN65l/xwyM8sklQalAGu755gNJZ4k9ApBVUssZyiu+te2+bDirAcmK8/x1jvMQY6bn -DFxBE7bMHDp24IFPaVID84Ryt3vSSBEkrUGm7OkyDESTpHCr4sfD5o3LCUCIibTqv/CAhe59mhbB -2AXL7X+EzylKy6C1N5KUUiMTW94AuF6f8FqBoxnf -=U6zM ------END PGP SIGNATURE-----`, ' '), - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - SignatureType: gitalypb.SignatureType_PGP, - }, - }, - { - desc: "huge", - in: "author " + strings.Repeat("A", 100000), - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Author: &gitalypb.CommitAuthor{ - Name: bytes.Repeat([]byte("A"), 100000), - }, - }, - }, - { - desc: "has encoding", - in: "encoding Windows-1251", - out: &gitalypb.GitCommit{ - Id: info.Oid.String(), - Encoding: "Windows-1251", - }, - }, - } { - t.Run(tc.desc, func(t *testing.T) { - info.Size = int64(len(tc.in)) - out, err := NewParser().ParseCommit(newStaticObject(tc.in, "commit", info.Oid)) - require.NoError(t, err, "parse error") - require.Equal(t, tc.out, out) - }) - } -} - -func TestParseCommitAuthor(t *testing.T) { - t.Parallel() - - for _, tc := range []struct { - desc string - author string - expected *gitalypb.CommitAuthor - }{ - { - desc: "empty author", - author: "", - expected: &gitalypb.CommitAuthor{}, - }, - { - desc: "normal author", - author: "Au Thor <au.thor@example.com> 1625121079 +0000", - expected: &gitalypb.CommitAuthor{ - Name: []byte("Au Thor"), - Email: []byte("au.thor@example.com"), - Date: timestamppb.New(time.Unix(1625121079, 0)), - Timezone: []byte("+0000"), - }, - }, - { - desc: "author with missing mail", - author: "Au Thor <> 1625121079 +0000", - expected: &gitalypb.CommitAuthor{ - Name: []byte("Au Thor"), - Date: timestamppb.New(time.Unix(1625121079, 0)), - Timezone: []byte("+0000"), - }, - }, - { - desc: "author with missing date", - author: "Au Thor <au.thor@example.com>", - expected: &gitalypb.CommitAuthor{ - Name: []byte("Au Thor"), - Email: []byte("au.thor@example.com"), - }, - }, - } { - t.Run(tc.desc, func(t *testing.T) { - testhelper.ProtoEqual(t, tc.expected, parseCommitAuthor(tc.author)) - }) - } -} - func TestParser_ParseTag(t *testing.T) { t.Parallel() |