Git-Raw

 view release on metacpan or  search on metacpan

t/10-clone.t  view on Meta::CPAN

# Incorrect authentication type (username and password)
ok (!eval { $repo = Git::Raw::Repository -> clone($remote_url, $path, {}, {
		'callbacks' => {
			'credentials' => sub {
				my ($url, $user, $types) = @_;
				return Git::Raw::Cred -> userpass(
					$user, 'password');
			}
		}
	});
});
rmtree $path;
ok ! -e $path;

# Incorrect authentication type (SSH interactive)
ok (!eval { $repo = Git::Raw::Repository -> clone($remote_url, $path, {}, {
		'callbacks' => {
			'credentials' => sub {
				my ($url, $user, $types) = @_;
				return Git::Raw::Cred -> sshinteractive(
					'metheunknownuser', sub {
						return ('badpassword');
					});
			}
		}
	});
});
rmtree $path;
ok ! -e $path;

# Incorrect authentication type (SSH agent)
my $badCount = 0;
ok (!eval { $repo = Git::Raw::Repository -> clone($remote_url, $path, {}, {
		'callbacks' => {
			'credentials' => sub {
				my ($url, $user, $types) = @_;
				if (++$badCount >= 2) {
					die "Skipping...";
				}
				return Git::Raw::Cred -> sshagent($user);
			}
		}
	});
});
rmtree $path;
ok ! -e $path;

($credentials_fired, $certificate_check_fired, $update_tips_fired) = (0, 0, 0);
$repo = Git::Raw::Repository -> clone($remote_url, $path, {
		'checkout_branch' => 'main'
	}, {
	'callbacks' => {
		'credentials' => sub {
			my ($url, $user) = @_;
			$credentials_fired = 1;

			my $ssh_dir = catfile($ENV{HOME}, '.ssh');
			ok -e $ssh_dir;

			my $public_key = catfile($ssh_dir, 'id_rsa.pub');
			my $private_key = catfile($ssh_dir, 'id_rsa');
			ok -f $public_key;
			ok -f $private_key;

			is $user, $ENV{USER};
			is $url, $remote_url;

			return Git::Raw::Cred -> sshkey(
				$user,
				$public_key,
				$private_key
			);
		},
		'certificate_check' => sub {
			my ($cert, $valid) = @_;
			$certificate_check_fired = 1;

			ok (defined($valid));

			isa_ok $cert, 'Git::Raw::Cert';
			isa_ok $cert, 'Git::Raw::Cert::HostKey';
			is $cert -> type, 'hostkey';

			$cert -> ssh_types;
			my $type_count = $cert -> ssh_types;
			is $type_count, 2;

			my @types = $cert -> ssh_types;
			is scalar(@types), 2;

			is $types[0], 'md5';
			is $types[1], 'sha1';

			my $md5 = $cert -> md5;
			is length($md5), 16;

			my $sha1 = $cert -> sha1;
			is length($sha1), 20;

			1;
		},
		'update_tips' => sub {
			my ($ref, $a, $b) = @_;
			$update_tips_fired = 1;

			like $ref, qr/refs/;
			ok !defined($a);
			ok defined($b);
		}
	}
});

ok !$repo -> is_empty;
is $credentials_fired, 1;
is $certificate_check_fired, 1;
is $update_tips_fired, 1;
@remotes = $repo -> remotes;

is $remotes[0] -> name, 'origin';
is $remotes[0] -> url, $remote_url;

@remotes = ();
$repo = undef;

rmtree $path;
ok ! -e $path;

done_testing;



( run in 1.928 second using v1.01-cache-2.11-cpan-98e64b0badf )