From 8e76aa1d75aebdadd0451d2e57c9bb65d1e75b9a Mon Sep 17 00:00:00 2001 From: "Theodore R. Smith" Date: Sun, 27 Dec 2020 09:13:11 -0600 Subject: (#3520) [cli] Hardened `auth add`: No longer fails with extraneous 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 #3091. --- server/tools/peertube-auth.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'server/tools') diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index 1a4fae4ce..7673b92cd 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts @@ -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) -- cgit v1.2.3 From 24198e976f41bcc41b90c640f2c51931fc22b0a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 30 Dec 2020 11:26:24 +0100 Subject: Styling --- server/tools/peertube-auth.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'server/tools') diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index 7673b92cd..6a0b89fe2 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts @@ -46,6 +46,15 @@ function isURLaPeerTubeInstance (url: string) { return url.startsWith('http://') || url.startsWith('https://') } +function stripExtraneousFromPeerTubeUrl (url: string) { + // Get everything before the 3rd /. + const urlLength = url.includes('/', 8) + ? url.indexOf('/', 8) + : url.length + + return url.substr(0, urlLength) +} + program .name('auth') .usage('[command] [options]') @@ -80,12 +89,6 @@ 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 { -- cgit v1.2.3