github.com/google/go-github/v42@v42.0.0/github/git_commits_test.go (about) 1 // Copyright 2013 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "encoding/json" 11 "fmt" 12 "net/http" 13 "strings" 14 "testing" 15 "time" 16 17 "github.com/google/go-cmp/cmp" 18 "golang.org/x/crypto/openpgp" 19 ) 20 21 func TestCommit_Marshal(t *testing.T) { 22 testJSONMarshal(t, &Commit{}, "{}") 23 24 u := &Commit{ 25 SHA: String("s"), 26 Author: &CommitAuthor{ 27 Date: &referenceTime, 28 Name: String("n"), 29 Email: String("e"), 30 Login: String("u"), 31 }, 32 Committer: &CommitAuthor{ 33 Date: &referenceTime, 34 Name: String("n"), 35 Email: String("e"), 36 Login: String("u"), 37 }, 38 Message: String("m"), 39 Tree: &Tree{ 40 SHA: String("s"), 41 Entries: []*TreeEntry{{ 42 SHA: String("s"), 43 Path: String("p"), 44 Mode: String("m"), 45 Type: String("t"), 46 Size: Int(1), 47 Content: String("c"), 48 URL: String("u"), 49 }}, 50 Truncated: Bool(false), 51 }, 52 Parents: nil, 53 Stats: &CommitStats{ 54 Additions: Int(1), 55 Deletions: Int(1), 56 Total: Int(1), 57 }, 58 HTMLURL: String("h"), 59 URL: String("u"), 60 Verification: &SignatureVerification{ 61 Verified: Bool(false), 62 Reason: String("r"), 63 Signature: String("s"), 64 Payload: String("p"), 65 }, 66 NodeID: String("n"), 67 CommentCount: Int(1), 68 SigningKey: &openpgp.Entity{}, 69 } 70 71 want := `{ 72 "sha": "s", 73 "author": { 74 "date": ` + referenceTimeStr + `, 75 "name": "n", 76 "email": "e", 77 "username": "u" 78 }, 79 "committer": { 80 "date": ` + referenceTimeStr + `, 81 "name": "n", 82 "email": "e", 83 "username": "u" 84 }, 85 "message": "m", 86 "tree": { 87 "sha": "s", 88 "tree": [ 89 { 90 "sha": "s", 91 "path": "p", 92 "mode": "m", 93 "type": "t", 94 "size": 1, 95 "content": "c", 96 "url": "u" 97 } 98 ], 99 "truncated": false 100 }, 101 "stats": { 102 "additions": 1, 103 "deletions": 1, 104 "total": 1 105 }, 106 "html_url": "h", 107 "url": "u", 108 "verification": { 109 "verified": false, 110 "reason": "r", 111 "signature": "s", 112 "payload": "p" 113 }, 114 "node_id": "n", 115 "comment_count": 1 116 }` 117 118 testJSONMarshal(t, u, want) 119 } 120 121 func TestGitService_GetCommit(t *testing.T) { 122 client, mux, _, teardown := setup() 123 defer teardown() 124 125 mux.HandleFunc("/repos/o/r/git/commits/s", func(w http.ResponseWriter, r *http.Request) { 126 testMethod(t, r, "GET") 127 fmt.Fprint(w, `{"sha":"s","message":"Commit Message.","author":{"name":"n"}}`) 128 }) 129 130 ctx := context.Background() 131 commit, _, err := client.Git.GetCommit(ctx, "o", "r", "s") 132 if err != nil { 133 t.Errorf("Git.GetCommit returned error: %v", err) 134 } 135 136 want := &Commit{SHA: String("s"), Message: String("Commit Message."), Author: &CommitAuthor{Name: String("n")}} 137 if !cmp.Equal(commit, want) { 138 t.Errorf("Git.GetCommit returned %+v, want %+v", commit, want) 139 } 140 141 const methodName = "GetCommit" 142 testBadOptions(t, methodName, func() (err error) { 143 _, _, err = client.Git.GetCommit(ctx, "\n", "\n", "\n") 144 return err 145 }) 146 147 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 148 got, resp, err := client.Git.GetCommit(ctx, "o", "r", "s") 149 if got != nil { 150 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 151 } 152 return resp, err 153 }) 154 } 155 156 func TestGitService_GetCommit_invalidOwner(t *testing.T) { 157 client, _, _, teardown := setup() 158 defer teardown() 159 160 ctx := context.Background() 161 _, _, err := client.Git.GetCommit(ctx, "%", "%", "%") 162 testURLParseError(t, err) 163 } 164 165 func TestGitService_CreateCommit(t *testing.T) { 166 client, mux, _, teardown := setup() 167 defer teardown() 168 169 input := &Commit{ 170 Message: String("Commit Message."), 171 Tree: &Tree{SHA: String("t")}, 172 Parents: []*Commit{{SHA: String("p")}}, 173 } 174 175 mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) { 176 v := new(createCommit) 177 json.NewDecoder(r.Body).Decode(v) 178 179 testMethod(t, r, "POST") 180 181 want := &createCommit{ 182 Message: input.Message, 183 Tree: String("t"), 184 Parents: []string{"p"}, 185 } 186 if !cmp.Equal(v, want) { 187 t.Errorf("Request body = %+v, want %+v", v, want) 188 } 189 fmt.Fprint(w, `{"sha":"s"}`) 190 }) 191 192 ctx := context.Background() 193 commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input) 194 if err != nil { 195 t.Errorf("Git.CreateCommit returned error: %v", err) 196 } 197 198 want := &Commit{SHA: String("s")} 199 if !cmp.Equal(commit, want) { 200 t.Errorf("Git.CreateCommit returned %+v, want %+v", commit, want) 201 } 202 203 const methodName = "CreateCommit" 204 testBadOptions(t, methodName, func() (err error) { 205 _, _, err = client.Git.CreateCommit(ctx, "\n", "\n", input) 206 return err 207 }) 208 209 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 210 got, resp, err := client.Git.CreateCommit(ctx, "o", "r", input) 211 if got != nil { 212 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 213 } 214 return resp, err 215 }) 216 } 217 218 func TestGitService_CreateSignedCommit(t *testing.T) { 219 client, mux, _, teardown := setup() 220 defer teardown() 221 222 signature := "----- BEGIN PGP SIGNATURE -----\n\naaaa\naaaa\n----- END PGP SIGNATURE -----" 223 224 input := &Commit{ 225 Message: String("Commit Message."), 226 Tree: &Tree{SHA: String("t")}, 227 Parents: []*Commit{{SHA: String("p")}}, 228 Verification: &SignatureVerification{ 229 Signature: String(signature), 230 }, 231 } 232 233 mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) { 234 v := new(createCommit) 235 json.NewDecoder(r.Body).Decode(v) 236 237 testMethod(t, r, "POST") 238 239 want := &createCommit{ 240 Message: input.Message, 241 Tree: String("t"), 242 Parents: []string{"p"}, 243 Signature: String(signature), 244 } 245 if !cmp.Equal(v, want) { 246 t.Errorf("Request body = %+v, want %+v", v, want) 247 } 248 fmt.Fprint(w, `{"sha":"commitSha"}`) 249 }) 250 251 ctx := context.Background() 252 commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input) 253 if err != nil { 254 t.Errorf("Git.CreateCommit returned error: %v", err) 255 } 256 257 want := &Commit{SHA: String("commitSha")} 258 if !cmp.Equal(commit, want) { 259 t.Errorf("Git.CreateCommit returned %+v, want %+v", commit, want) 260 } 261 262 const methodName = "CreateCommit" 263 testBadOptions(t, methodName, func() (err error) { 264 _, _, err = client.Git.CreateCommit(ctx, "\n", "\n", input) 265 return err 266 }) 267 268 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { 269 got, resp, err := client.Git.CreateCommit(ctx, "o", "r", input) 270 if got != nil { 271 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) 272 } 273 return resp, err 274 }) 275 } 276 277 func TestGitService_CreateSignedCommitWithInvalidParams(t *testing.T) { 278 client, _, _, teardown := setup() 279 defer teardown() 280 281 input := &Commit{ 282 SigningKey: &openpgp.Entity{}, 283 } 284 285 ctx := context.Background() 286 _, _, err := client.Git.CreateCommit(ctx, "o", "r", input) 287 if err == nil { 288 t.Errorf("Expected error to be returned because invalid params was passed") 289 } 290 } 291 292 func TestGitService_CreateSignedCommitWithKey(t *testing.T) { 293 client, mux, _, teardown := setup() 294 defer teardown() 295 s := strings.NewReader(testGPGKey) 296 keyring, err := openpgp.ReadArmoredKeyRing(s) 297 if err != nil { 298 t.Errorf("Error reading keyring: %+v", err) 299 } 300 301 date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") 302 author := CommitAuthor{ 303 Name: String("go-github"), 304 Email: String("go-github@github.com"), 305 Date: &date, 306 } 307 input := &Commit{ 308 Message: String("Commit Message."), 309 Tree: &Tree{SHA: String("t")}, 310 Parents: []*Commit{{SHA: String("p")}}, 311 SigningKey: keyring[0], 312 Author: &author, 313 } 314 315 messageReader := strings.NewReader(`tree t 316 parent p 317 author go-github <go-github@github.com> 1493849023 +0200 318 committer go-github <go-github@github.com> 1493849023 +0200 319 320 Commit Message.`) 321 322 mux.HandleFunc("/repos/o/r/git/commits", func(w http.ResponseWriter, r *http.Request) { 323 v := new(createCommit) 324 json.NewDecoder(r.Body).Decode(v) 325 326 testMethod(t, r, "POST") 327 328 want := &createCommit{ 329 Message: input.Message, 330 Tree: String("t"), 331 Parents: []string{"p"}, 332 Author: &author, 333 } 334 335 sigReader := strings.NewReader(*v.Signature) 336 signer, err := openpgp.CheckArmoredDetachedSignature(keyring, messageReader, sigReader) 337 if err != nil { 338 t.Errorf("Error verifying signature: %+v", err) 339 } 340 if signer.Identities["go-github <go-github@github.com>"].Name != "go-github <go-github@github.com>" { 341 t.Errorf("Signer is incorrect. got: %+v, want %+v", signer.Identities["go-github <go-github@github.com>"].Name, "go-github <go-github@github.com>") 342 } 343 // Nullify Signature since we checked it above 344 v.Signature = nil 345 if !cmp.Equal(v, want) { 346 t.Errorf("Request body = %+v, want %+v", v, want) 347 } 348 fmt.Fprint(w, `{"sha":"commitSha"}`) 349 }) 350 351 ctx := context.Background() 352 commit, _, err := client.Git.CreateCommit(ctx, "o", "r", input) 353 if err != nil { 354 t.Errorf("Git.CreateCommit returned error: %v", err) 355 } 356 357 want := &Commit{SHA: String("commitSha")} 358 if !cmp.Equal(commit, want) { 359 t.Errorf("Git.CreateCommit returned %+v, want %+v", commit, want) 360 } 361 } 362 363 func TestGitService_createSignature_nilSigningKey(t *testing.T) { 364 a := &createCommit{ 365 Message: String("Commit Message."), 366 Tree: String("t"), 367 Parents: []string{"p"}, 368 } 369 370 _, err := createSignature(nil, a) 371 372 if err == nil { 373 t.Errorf("Expected error to be returned because no author was passed") 374 } 375 } 376 377 func TestGitService_createSignature_nilCommit(t *testing.T) { 378 _, err := createSignature(&openpgp.Entity{}, nil) 379 380 if err == nil { 381 t.Errorf("Expected error to be returned because no author was passed") 382 } 383 } 384 385 func TestGitService_createSignature_noAuthor(t *testing.T) { 386 a := &createCommit{ 387 Message: String("Commit Message."), 388 Tree: String("t"), 389 Parents: []string{"p"}, 390 } 391 392 _, err := createSignature(&openpgp.Entity{}, a) 393 394 if err == nil { 395 t.Errorf("Expected error to be returned because no author was passed") 396 } 397 } 398 399 func TestGitService_createSignature_invalidKey(t *testing.T) { 400 date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") 401 402 _, err := createSignature(&openpgp.Entity{}, &createCommit{ 403 Message: String("Commit Message."), 404 Tree: String("t"), 405 Parents: []string{"p"}, 406 Author: &CommitAuthor{ 407 Name: String("go-github"), 408 Email: String("go-github@github.com"), 409 Date: &date, 410 }, 411 }) 412 413 if err == nil { 414 t.Errorf("Expected error to be returned due to invalid key") 415 } 416 } 417 418 func TestGitService_createSignatureMessage_nilCommit(t *testing.T) { 419 _, err := createSignatureMessage(nil) 420 if err == nil { 421 t.Errorf("Expected error to be returned due to nil key") 422 } 423 } 424 425 func TestGitService_createSignatureMessage_nilMessage(t *testing.T) { 426 date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") 427 428 _, err := createSignatureMessage(&createCommit{ 429 Message: nil, 430 Parents: []string{"p"}, 431 Author: &CommitAuthor{ 432 Name: String("go-github"), 433 Email: String("go-github@github.com"), 434 Date: &date, 435 }, 436 }) 437 if err == nil { 438 t.Errorf("Expected error to be returned due to nil key") 439 } 440 } 441 442 func TestGitService_createSignatureMessage_emptyMessage(t *testing.T) { 443 date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") 444 emptyString := "" 445 _, err := createSignatureMessage(&createCommit{ 446 Message: &emptyString, 447 Parents: []string{"p"}, 448 Author: &CommitAuthor{ 449 Name: String("go-github"), 450 Email: String("go-github@github.com"), 451 Date: &date, 452 }, 453 }) 454 if err == nil { 455 t.Errorf("Expected error to be returned due to nil key") 456 } 457 } 458 459 func TestGitService_createSignatureMessage_nilAuthor(t *testing.T) { 460 _, err := createSignatureMessage(&createCommit{ 461 Message: String("Commit Message."), 462 Parents: []string{"p"}, 463 Author: nil, 464 }) 465 if err == nil { 466 t.Errorf("Expected error to be returned due to nil key") 467 } 468 } 469 470 func TestGitService_createSignatureMessage_withoutTree(t *testing.T) { 471 date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") 472 473 msg, _ := createSignatureMessage(&createCommit{ 474 Message: String("Commit Message."), 475 Parents: []string{"p"}, 476 Author: &CommitAuthor{ 477 Name: String("go-github"), 478 Email: String("go-github@github.com"), 479 Date: &date, 480 }, 481 }) 482 expected := `parent p 483 author go-github <go-github@github.com> 1493849023 +0200 484 committer go-github <go-github@github.com> 1493849023 +0200 485 486 Commit Message.` 487 if msg != expected { 488 t.Errorf("Returned message incorrect. returned %s, want %s", msg, expected) 489 } 490 } 491 492 func TestGitService_createSignatureMessage_withoutCommitter(t *testing.T) { 493 date, _ := time.Parse("Mon Jan 02 15:04:05 2006 -0700", "Thu May 04 00:03:43 2017 +0200") 494 495 msg, _ := createSignatureMessage(&createCommit{ 496 Message: String("Commit Message."), 497 Parents: []string{"p"}, 498 Author: &CommitAuthor{ 499 Name: String("go-github"), 500 Email: String("go-github@github.com"), 501 Date: &date, 502 }, 503 Committer: &CommitAuthor{ 504 Name: String("foo"), 505 Email: String("foo@bar.com"), 506 Date: &date, 507 }, 508 }) 509 expected := `parent p 510 author go-github <go-github@github.com> 1493849023 +0200 511 committer foo <foo@bar.com> 1493849023 +0200 512 513 Commit Message.` 514 if msg != expected { 515 t.Errorf("Returned message incorrect. returned %s, want %s", msg, expected) 516 } 517 } 518 519 func TestGitService_CreateCommit_invalidOwner(t *testing.T) { 520 client, _, _, teardown := setup() 521 defer teardown() 522 523 ctx := context.Background() 524 _, _, err := client.Git.CreateCommit(ctx, "%", "%", &Commit{}) 525 testURLParseError(t, err) 526 } 527 528 const testGPGKey = ` 529 -----BEGIN PGP PRIVATE KEY BLOCK----- 530 531 lQOYBFyi1qYBCAD3EPfLJzIt4qkAceUKkhdvfaIvOsBwXbfr5sSu/lkMqL0Wq47+ 532 iv+SRwOC7zvN8SlB8nPUgs5dbTRCJJfG5MAqTRR7KZRbyq2jBpi4BtmO30Ul/qId 533 3A18cVUfgVbxH85K9bdnyOxep/Q2NjLjTKmWLkzgmgkfbUmSLuWW9HRXPjYy9B7i 534 dOFD6GdkN/HwPAaId8ym0TE1mIuSpw8UQHyxusAkK52Pn4h/PgJhLTzbSi1X2eDt 535 OgzjhbdxTPzKFQfs97dY8y9C7Bt+CqH6Bvr3785LeKdxiUnCjfUJ+WAoJy780ec+ 536 IVwSpPp1CaEtzu73w6GH5945GELHE8HRe25FABEBAAEAB/9dtx72/VAoXZCTbaBe 537 iRnAnZwWZCe4t6PbJHa4lhv7FEpdPggIf3r/5lXrpYk+zdpDfI75LgDPKWwoJq83 538 r29A3GoHabcvtkp0yzzEmTyO2BvnlJWz09N9v5N1Vt8+qTzb7CZ8hJc8NGMK6TYW 539 R+8P21In4+XP+OluPMGzp9g1etHScLhQUtF/xcN3JQGkeq4CPX6jUSYlJNeEtuLm 540 xjBTLBdg8zK5mJ3tolvnS/VhSTdiBeUaYtVt/qxq+fPqdFGHrO5H9ORbt56ahU+f 541 Ne86sOjQfJZPsx9z8ffP+XhLZPT1ZUGJMI/Vysx9gwDiEnaxrCJ02fO0Dnqsj/o2 542 T14lBAD55+KtaS0C0OpHpA/F+XhL3IDcYQOYgu8idBTshr4vv7M+jdZqpECOn72Q 543 8SZJ+gYMcA9Z07Afnin1DVdtxiMN/tbyOu7e1BE7y77eA+zQw4PjLJPZJMbco7z+ 544 q9ZnZF3GyRyil6HkKUTfrao8AMtb0allZnqXwpPb5Mza32VqtwQA/RdbG6OIS6og 545 OpP7zKu4GP4guBk8NrVpV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BgBCAAmFiEELZ6AMqOpBMVblK0uiKTQXVy+MAsF 578 Alyi1qYCGwwFCQPCZwAACgkQiKTQXVy+MAstJAf/Tm2hfagVjzgJ5pFHmpP+fYxp 579 8dIPZLonP5HW12iaSOXThtvWBY578Cb9RmU+WkHyPXg8SyshW7aco4HrUDk+Qmyi 580 f9BvHS5RsLbyPlhgCqNkn+3QS62fZiIlbHLrQ/6iHXkgLV04Fnj+F4v8YYpOI9nY 581 NFc5iWm0zZRcLiRKZk1up8SCngyolcjVuTuCXDKyAUX1jRqDu7tlN0qVH0CYDGch 582 BqTKXNkzAvV+CKOyaUILSBBWdef+cxVrDCJuuC3894x3G1FjJycOy0m9PArvGtSG 583 g7/0Bp9oLXwiHzFoUMDvx+WlPnPHQNcufmQXUNdZvg+Ad4/unEU81EGDBDz3Eg== 584 =VFSn 585 -----END PGP PRIVATE KEY BLOCK-----` 586 587 func TestSignatureVerification_Marshal(t *testing.T) { 588 testJSONMarshal(t, &SignatureVerification{}, "{}") 589 590 u := &SignatureVerification{ 591 Verified: Bool(true), 592 Reason: String("reason"), 593 Signature: String("sign"), 594 Payload: String("payload"), 595 } 596 597 want := `{ 598 "verified": true, 599 "reason": "reason", 600 "signature": "sign", 601 "payload": "payload" 602 }` 603 604 testJSONMarshal(t, u, want) 605 } 606 607 func TestCommitAuthor_Marshal(t *testing.T) { 608 testJSONMarshal(t, &CommitAuthor{}, "{}") 609 610 u := &CommitAuthor{ 611 Date: &referenceTime, 612 Name: String("name"), 613 Email: String("email"), 614 Login: String("login"), 615 } 616 617 want := `{ 618 "date": ` + referenceTimeStr + `, 619 "name": "name", 620 "email": "email", 621 "username": "login" 622 }` 623 624 testJSONMarshal(t, u, want) 625 } 626 627 func TestCreateCommit_Marshal(t *testing.T) { 628 testJSONMarshal(t, &createCommit{}, "{}") 629 630 u := &createCommit{ 631 Author: &CommitAuthor{ 632 Date: &referenceTime, 633 Name: String("name"), 634 Email: String("email"), 635 Login: String("login"), 636 }, 637 Committer: &CommitAuthor{ 638 Date: &referenceTime, 639 Name: String("name"), 640 Email: String("email"), 641 Login: String("login"), 642 }, 643 Message: String("message"), 644 Tree: String("tree"), 645 Parents: []string{"p"}, 646 Signature: String("sign"), 647 } 648 649 want := `{ 650 "author": { 651 "date": ` + referenceTimeStr + `, 652 "name": "name", 653 "email": "email", 654 "username": "login" 655 }, 656 "committer": { 657 "date": ` + referenceTimeStr + `, 658 "name": "name", 659 "email": "email", 660 "username": "login" 661 }, 662 "message": "message", 663 "tree": "tree", 664 "parents": [ 665 "p" 666 ], 667 "signature": "sign" 668 }` 669 670 testJSONMarshal(t, u, want) 671 }