Skip to content

Commit

Permalink
(Chocobozzz#3520) [cli] Hardened auth add: No longer fails with ext…
Browse files Browse the repository at this point in the history
…raneous characters.

**The Solution:**
I have hardened `auth add` by stripping out everything from the third '/' to the end of the instance URL.

**The Problem:**
When adding an authorization for the peertube-cli, before this commit you could not have anything after the domain_name:port.

For instance, if there was a trailing / in your instance URL, before this commit it will always fail with

    expected 200 "OK", got 404 "Not Found".

It took me over 20 minutes to figure out that this was the problem.

See Issue Chocobozzz#3091.
  • Loading branch information
hopeseekr committed Dec 27, 2020
1 parent f88453e commit 92ac5cf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/tools/peertube-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,19 @@ program
}
}
}, async (_, result) => {
const stripExtraneousFromPeerTubeUrl = function (url: string) {
// Get everything before the 3rd /.
const urlLength: number = url.includes('/', 8) ? url.indexOf('/', 8) : url.length;

return url.substr(0, urlLength);
}

// Check credentials
try {
// Strip out everything after the domain:port.
// @see https://github.com/Chocobozzz/PeerTube/issues/3520
result.url = stripExtraneousFromPeerTubeUrl(result.url);

await getAccessToken(result.url, result.username, result.password)
} catch (err) {
console.error(err.message)
Expand Down

0 comments on commit 92ac5cf

Please sign in to comment.