Skip to content

Commit 989d6ef

Browse files
Change certificate_check to pass true or false for validity.
Also update and clean up some of the test cases.
1 parent 3c1b1e7 commit 989d6ef

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

ext/rugged/rugged_remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int certificate_check_cb(git_cert *cert, int valid, const char *host, voi
104104
return valid ? 0 : GIT_ECERTIFICATE;
105105

106106
rb_ary_push(args, payload->certificate_check);
107-
rb_ary_push(args, INT2FIX(valid));
107+
rb_ary_push(args, valid ? Qtrue : Qfalse);
108108
rb_ary_push(args, rb_str_new_utf8(host));
109109

110110
ret = rb_protect(rugged__block_yield_splat, args, &payload->exception);

test/online/fetch_test.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,44 @@ def test_fetch_over_https
3030
end
3131

3232
def test_fetch_over_https_with_certificate_callback
33-
result = {}
3433
@repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")
3534

35+
args = {}
3636
@repo.fetch("origin", {
3737
certificate_check: lambda { |valid, host|
38-
result[:valid] = valid
39-
true
38+
args[:valid] = valid
39+
args[:host] = host
40+
41+
true
4042
}
4143
})
42-
assert_equal result[:valid], 1
44+
45+
assert_equal({ valid: true, host: "github.com" }, args)
4346
end
4447

4548
def test_fetch_over_https_with_certificate_callback_fail
46-
result = {}
4749
@repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")
4850

4951
exception = assert_raises Rugged::NetworkError do
5052
@repo.fetch("origin", {
51-
certificate_check: lambda { |valid, host|
52-
result[:valid] = valid
53-
false
54-
}
53+
certificate_check: lambda { |valid, host| false }
5554
})
5655
end
56+
5757
assert_equal "user cancelled certificate check", exception.message
5858
end
5959

6060
def test_fetch_over_https_with_certificate_callback_exception
61-
result = {}
6261
@repo.remotes.create("origin", "https://github.com/libgit2/TestGitRepository.git")
6362

6463
exception = assert_raises RuntimeError do
6564
@repo.fetch("origin", {
6665
certificate_check: lambda { |valid, host|
67-
result[:valid] = valid
6866
raise "Exception from callback"
6967
}
7068
})
7169
end
70+
7271
assert_equal "Exception from callback", exception.message
7372
end
7473
end

0 commit comments

Comments
 (0)