@@ -142,6 +142,30 @@ func TestRemoteURLRefs(t *testing.T) {
142142 }
143143 })
144144
145+ t .Run ("includes verify-sig op in refs claim" , func (t * testing.T ) {
146+ remote , err := repo .RemoteURL (nil , RemoteURLOptions {
147+ RefPolicies : RefPolicyList {
148+ {Pattern : "refs/heads/main" , Ops : Ops {OpVerifySig }},
149+ },
150+ })
151+ if err != nil {
152+ t .Fatalf ("remote url error: %v" , err )
153+ }
154+ claims := parseJWTFromURL (t , remote )
155+ refs , ok := claims ["refs" ].([]interface {})
156+ if ! ok || len (refs ) != 1 {
157+ t .Fatalf ("expected 1 ref rule, got %v" , claims ["refs" ])
158+ }
159+ rule , ok := refs [0 ].([]interface {})
160+ if ! ok || len (rule ) != 2 {
161+ t .Fatalf ("unexpected rule shape: %v" , refs [0 ])
162+ }
163+ ops , ok := rule [1 ].([]interface {})
164+ if ! ok || len (ops ) != 1 || ops [0 ] != "verify-sig" {
165+ t .Fatalf ("unexpected ops: %v" , rule [1 ])
166+ }
167+ })
168+
145169 t .Run ("omits refs from JWT when not provided" , func (t * testing.T ) {
146170 remote , err := repo .RemoteURL (nil , RemoteURLOptions {})
147171 if err != nil {
@@ -1938,7 +1962,7 @@ func TestGetCommit(t *testing.T) {
19381962 t .Fatalf ("unexpected sha query: %q" , got )
19391963 }
19401964 w .Header ().Set ("Content-Type" , "application/json" )
1941- _ , _ = w .Write ([]byte (`{"commit":{"sha":"abc123","message":"feat: add endpoint","author_name":"Jane Doe","author_email":"jane@example.com","committer_name":"Jane Doe","committer_email":"jane@example.com","date":"2024-01-15T14:32:18Z"}}` ))
1965+ _ , _ = w .Write ([]byte (`{"commit":{"sha":"abc123","message":"feat: add endpoint","author_name":"Jane Doe","author_email":"jane@example.com","committer_name":"Jane Doe","committer_email":"jane@example.com","date":"2024-01-15T14:32:18Z","signature":"-----BEGIN PGP SIGNATURE-----\nABC\n-----END PGP SIGNATURE-----\n","payload":"tree deadbeef\nauthor Jane Doe <jane@example.com> 1700000000 +0000\n" }}` ))
19421966 }))
19431967 defer server .Close ()
19441968
@@ -1964,6 +1988,34 @@ func TestGetCommit(t *testing.T) {
19641988 if result .Commit .RawDate != "2024-01-15T14:32:18Z" || result .Commit .Date .IsZero () {
19651989 t .Fatalf ("unexpected date: %+v" , result .Commit )
19661990 }
1991+ if ! strings .Contains (result .Commit .Signature , "BEGIN PGP SIGNATURE" ) {
1992+ t .Fatalf ("unexpected signature: %q" , result .Commit .Signature )
1993+ }
1994+ if ! strings .HasPrefix (result .Commit .Payload , "tree deadbeef" ) {
1995+ t .Fatalf ("unexpected payload: %q" , result .Commit .Payload )
1996+ }
1997+ }
1998+
1999+ func TestGetCommitUnsigned (t * testing.T ) {
2000+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2001+ w .Header ().Set ("Content-Type" , "application/json" )
2002+ _ , _ = w .Write ([]byte (`{"commit":{"sha":"abc123","message":"chore: noop","author_name":"Jane Doe","author_email":"jane@example.com","committer_name":"Jane Doe","committer_email":"jane@example.com","date":"2024-01-15T14:32:18Z"}}` ))
2003+ }))
2004+ defer server .Close ()
2005+
2006+ client , err := NewClient (Options {Name : "acme" , Key : testKey , APIBaseURL : server .URL })
2007+ if err != nil {
2008+ t .Fatalf ("client error: %v" , err )
2009+ }
2010+ repo := & Repo {ID : "repo" , DefaultBranch : "main" , client : client }
2011+
2012+ result , err := repo .GetCommit (nil , GetCommitOptions {SHA : "abc123" })
2013+ if err != nil {
2014+ t .Fatalf ("get commit error: %v" , err )
2015+ }
2016+ if result .Commit .Signature != "" || result .Commit .Payload != "" {
2017+ t .Fatalf ("expected empty signature/payload for unsigned commit, got %+v" , result .Commit )
2018+ }
19672019}
19682020
19692021func TestGetCommitRequiresSHA (t * testing.T ) {
0 commit comments