Skip to content

Commit 4a9cfa9

Browse files
committed
Fixed remote test error in linux / osx
OSX/Linux now implement the proper behavior of libgit2 for the credentials call back. When connecting to the remote, if the credentials are bad, the remote_connect will try the credentials cb again until the credentials cb returns an unusable credentials object or the server accepts the credentials. As such, we need to put a counter on the credentials for hardcoded values, and then return nothing in the cred call back and expect to catch an error thrown by libgit.
1 parent 154d011 commit 4a9cfa9

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

test/tests/remote.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,27 @@ describe("Remote", function() {
191191
.then(function(remote) {
192192
var ref = "refs/heads/" + branch;
193193
var refs = [ref + ":" + ref];
194+
var firstPass = true;
194195
var options = {
195196
callbacks: {
196-
credentials: function(url, userName) {
197-
if (url.indexOf("https") === -1) {
198-
return NodeGit.Cred.sshKeyFromAgent(userName);
199-
} else {
200-
return NodeGit.Cred.userpassPlaintextNew(userName, "");
197+
credentials:function(url, userName) {
198+
if (firstPass) {
199+
if (url.indexOf("https") === -1) {
200+
return NodeGit.Cred.sshKeyFromAgent(userName);
201+
} else {
202+
return NodeGit.Cred.defaultNew();
203+
}
201204
}
205+
},
206+
certificateCheck: function() {
207+
return 1;
202208
}
203209
}
204210
};
205211
return remote.push(refs, options);
206212
})
213+
// takes care of windows bug, see the .catch for the proper pathway
214+
// that this flow should take (cred cb doesn't run twice -> throws error)
207215
.then(function() {
208216
return Promise.reject(
209217
new Error("should not be able to push to the repository"));
@@ -213,6 +221,17 @@ describe("Remote", function() {
213221
} else {
214222
return Promise.resolve();
215223
}
224+
})
225+
// catches linux / osx failure to use anonymous credentials
226+
// stops callback infinite loop
227+
.catch(function (reason) {
228+
if (reason.message !==
229+
"credentials callback returned an invalid cred type")
230+
{
231+
throw reason;
232+
} else {
233+
return Promise.resolve();
234+
}
216235
});
217236
});
218237
});

vendor/libgit2.gyp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,34 +253,23 @@
253253
"libgit2/src/xdiff/xutils.h",
254254
],
255255
"conditions": [
256-
["OS!='win'", {
257-
"defines": [
258-
"GIT_SSL"
259-
]
260-
}],
261256
["OS=='mac'", {
262257
"defines": [
263-
"GIT_SECURE_TRANSPORT",
264-
"GIT_CURL"
258+
"GIT_SECURE_TRANSPORT"
265259
],
266260
"sources": [
267261
"libgit2/src/stransport_stream.c",
268262
"libgit2/src/stransport_stream.h",
269263
"libgit2/src/tls_stream.c",
270-
"libgit2/src/tls_stream.h",
271-
"libgit2/src/curl_stream.c",
272-
"libgit2/src/curl_stream.h"
264+
"libgit2/src/tls_stream.h"
273265
],
274266
"link_settings": {
275267
"xcode_settings": {
276268
"OTHER_LDFLAGS": [
277269
"-framework Security",
278270
"-framework CoreFoundation"
279271
],
280-
},
281-
"libraries": [
282-
'/usr/lib/libcurl.dylib'
283-
],
272+
}
284273
}
285274
}],
286275
["OS=='win'", {}, {

0 commit comments

Comments
 (0)