Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credentials-Helper and --rootPath #1060

Closed
dayaftereh opened this issue Mar 6, 2018 · 4 comments
Closed

Credentials-Helper and --rootPath #1060

dayaftereh opened this issue Mar 6, 2018 · 4 comments

Comments

@dayaftereh
Copy link
Contributor

Hey,

I discoverd that the bin/credentials-helper ignores the --rootPath, because the request url http://localhost:${port}/api/credentials in the credentials-helper#L14 is without the rootPath.

Test-Case

Run the ungit command with the --rootPath like:

&> ungit --rootPath=/ungit --port=4000

Open http://localhost:4000/ungit/ and try to clone a repository. The clone operation fails with the followring response:

{
   "isGitError":true,
   "errorCode":"unknown",
   "command":"-c color.ui=false -c core.quotepath=false -c core.pager=cat -c credential.helper=/usr/lib/node_modules/ungit/bin/credentials-helper 0 4000 https://github.com/FredrikNoren/ungit.git clone https://github.com/FredrikNoren/ungit.git ungit",
   "workingDirectory":"/home",
   "error":"Cloning into 'ungit'...\nundefined:1\nBad Request\n^\n\nSyntaxError: Unexpected token B in JSON at position 0\n    at JSON.parse (<anonymous>)\n    at IncomingMessage.res.on (/usr/lib/node_modules/ungit/bin/credentials-helper:24:31)\n    at emitOne (events.js:116:13)\n    at IncomingMessage.emit (events.js:211:7)\n    at IncomingMessage.Readable.read (_stream_readable.js:475:10)\n    at flow (_stream_readable.js:846:34)\n    at resume_ (_stream_readable.js:828:3)\n    at _combinedTickCallback (internal/process/next_tick.js:138:11)\n    at process._tickCallback (internal/process/next_tick.js:180:9)\nfatal: could not read Username for 'https://github.com': No such device or address\n",
   "message":"Cloning into 'ungit'...",
   "stderr":"Cloning into 'ungit'...\nundefined:1\nBad Request\n^\n\nSyntaxError: Unexpected token B in JSON at position 0\n    at JSON.parse (<anonymous>)\n    at IncomingMessage.res.on (/usr/lib/node_modules/ungit/bin/credentials-helper:24:31)\n    at emitOne (events.js:116:13)\n    at IncomingMessage.emit (events.js:211:7)\n    at IncomingMessage.Readable.read (_stream_readable.js:475:10)\n    at flow (_stream_readable.js:846:34)\n    at resume_ (_stream_readable.js:828:3)\n    at _combinedTickCallback (internal/process/next_tick.js:138:11)\n    at process._tickCallback (internal/process/next_tick.js:180:9)\nfatal: could not read Username for 'https://github.com': No such device or address\n",
   "stdout":""
}

Solution

Just pass the rootPath to the bin/credentials-helper, like socketId or origin.

My-Quick-Fix

I add a environment variable ROOT_PATH to the url for the bin/credentials-helper.

Example:

let localUrl = `api/credentials?socketId=${socketId}&remote=${encodeURIComponent(remote)}`;
if (process.env['ROOT_PATH']) {
    localUrl = url.resolve(process.env['ROOT_PATH'], localUrl);
}
localUrl = url.resolve(`http://localhost:${port}`, localUrl);
// ...
http.get(localUrl, (res) => {
// ...
@jung-kim
Copy link
Collaborator

jung-kim commented Mar 6, 2018

Ah, you are absolutely right.

It seems like you have a solid fix for it and feel free to send me a PR. If not I will create one later this week.

Thanks

@wormeyman
Copy link
Contributor

I think this can be closed right? Fixed with #1061 right?

@dayaftereh
Copy link
Contributor Author

Hey, yes, this is fixed with #1061, but I think there is still a problem with credentials-helper and authentication. But I'm not yet sure, because when is start ungit with authentication=true and user={"admin":admin"} is can't authentication via credentials-helper. I can check this and open if needed a new issue ?

@jung-kim
Copy link
Collaborator

Ah... do you mean #1061 helped but it didn't fully fixed it? yes can you please open a new ticket with the details? thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants