|
388 | 388 | end
|
389 | 389 | end
|
390 | 390 | end
|
| 391 | + |
| 392 | + describe '.extract_signature' do |
| 393 | + subject { described_class.extract_signature(repository, commit_id) } |
| 394 | + |
| 395 | + shared_examples '.extract_signature' do |
| 396 | + context 'when the commit is signed' do |
| 397 | + let(:commit_id) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } |
| 398 | + |
| 399 | + it 'returns signature and signed text' do |
| 400 | + signature, signed_text = subject |
| 401 | + |
| 402 | + expected_signature = <<~SIGNATURE |
| 403 | + -----BEGIN PGP SIGNATURE----- |
| 404 | + Version: GnuPG/MacGPG2 v2.0.22 (Darwin) |
| 405 | + Comment: GPGTools - https://gpgtools.org |
| 406 | +
|
| 407 | + iQEcBAABCgAGBQJTDvaZAAoJEGJ8X1ifRn8XfvYIAMuB0yrbTGo1BnOSoDfyrjb0 |
| 408 | + Kw2EyUzvXYL72B63HMdJ+/0tlSDC6zONF3fc+bBD8z+WjQMTbwFNMRbSSy2rKEh+ |
| 409 | + mdRybOP3xBIMGgEph0/kmWln39nmFQBsPRbZBWoU10VfI/ieJdEOgOphszgryRar |
| 410 | + TyS73dLBGE9y9NIININVaNISet9D9QeXFqc761CGjh4YIghvPpi+YihMWapGka6v |
| 411 | + hgKhX+hc5rj+7IEE0CXmlbYR8OYvAbAArc5vJD7UTxAY4Z7/l9d6Ydt9GQ25khfy |
| 412 | + ANFgltYzlR6evLFmDjssiP/mx/ZMN91AL0ueJ9nNGv411Mu2CUW+tDCaQf35mdc= |
| 413 | + =j51i |
| 414 | + -----END PGP SIGNATURE----- |
| 415 | + SIGNATURE |
| 416 | + |
| 417 | + expect(signature).to eq(expected_signature.chomp) |
| 418 | + expect(signature).to be_a_binary_string |
| 419 | + |
| 420 | + expected_signed_text = <<~SIGNED_TEXT |
| 421 | + tree 22bfa2fbd217df24731f43ff43a4a0f8db759dae |
| 422 | + parent ae73cb07c9eeaf35924a10f713b364d32b2dd34f |
| 423 | + author Dmitriy Zaporozhets <[email protected]> 1393489561 +0200 |
| 424 | + committer Dmitriy Zaporozhets <[email protected]> 1393489561 +0200 |
| 425 | +
|
| 426 | + Feature added |
| 427 | +
|
| 428 | + Signed-off-by: Dmitriy Zaporozhets <[email protected]> |
| 429 | + SIGNED_TEXT |
| 430 | + |
| 431 | + expect(signed_text).to eq(expected_signed_text) |
| 432 | + expect(signed_text).to be_a_binary_string |
| 433 | + end |
| 434 | + end |
| 435 | + |
| 436 | + context 'when the commit has no signature' do |
| 437 | + let(:commit_id) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' } |
| 438 | + |
| 439 | + it 'returns nil' do |
| 440 | + expect(subject).to be_nil |
| 441 | + end |
| 442 | + end |
| 443 | + |
| 444 | + context 'when the commit cannot be found' do |
| 445 | + let(:commit_id) { Gitlab::Git::BLANK_SHA } |
| 446 | + |
| 447 | + it 'returns nil' do |
| 448 | + expect(subject).to be_nil |
| 449 | + end |
| 450 | + end |
| 451 | + |
| 452 | + context 'when the commit ID is invalid' do |
| 453 | + let(:commit_id) { '4b4918a572fa86f9771e5ba40fbd48e' } |
| 454 | + |
| 455 | + it 'raises ArgumentError' do |
| 456 | + expect { subject }.to raise_error(ArgumentError) |
| 457 | + end |
| 458 | + end |
| 459 | + end |
| 460 | + |
| 461 | + context 'with gitaly' do |
| 462 | + it_behaves_like '.extract_signature' |
| 463 | + end |
| 464 | + |
| 465 | + context 'without gitaly', :skip_gitaly_mock do |
| 466 | + it_behaves_like '.extract_signature' |
| 467 | + end |
| 468 | + end |
391 | 469 | end
|
392 | 470 |
|
393 | 471 | describe '#init_from_rugged' do
|
|
0 commit comments