aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorTheodore R. Smith <theodore@phpexperts.pro>2020-12-27 09:13:11 -0600
committerTheodore R. Smith <theodore@phpexperts.pro>2020-12-27 14:29:54 -0600
commit8e76aa1d75aebdadd0451d2e57c9bb65d1e75b9a (patch)
tree3b9809e75c8e8f9044080182801f4516a11fe242 /server
parentf88453e2335ec9140df927d3cca727d2a3a4ab70 (diff)
downloadPeerTube-8e76aa1d75aebdadd0451d2e57c9bb65d1e75b9a.tar.gz
PeerTube-8e76aa1d75aebdadd0451d2e57c9bb65d1e75b9a.tar.zst
PeerTube-8e76aa1d75aebdadd0451d2e57c9bb65d1e75b9a.zip
(#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.
Diffstat (limited to 'server')
-rw-r--r--server/tests/cli/peertube.ts12
-rw-r--r--server/tools/peertube-auth.ts11
2 files changed, 23 insertions, 0 deletions
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index 348438533..fcf7e2e2e 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -66,6 +66,18 @@ describe('Test CLI wrapper', function () {
66 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) 66 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
67 }) 67 })
68 68
69 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
70 this.timeout(60000)
71
72 const env = getEnvCli(server)
73 let fullServerURL
74 fullServerURL = server.url + '/'
75 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
76
77 fullServerURL = server.url + '/asdfasdf'
78 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
79 })
80
69 it('Should default to this user', async function () { 81 it('Should default to this user', async function () {
70 this.timeout(60000) 82 this.timeout(60000)
71 83
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
80 } 80 }
81 } 81 }
82 }, async (_, result) => { 82 }, async (_, result) => {
83 const stripExtraneousFromPeerTubeUrl = function (url: string) {
84 // Get everything before the 3rd /.
85 const urlLength: number = url.includes('/', 8) ? url.indexOf('/', 8) : url.length
86
87 return url.substr(0, urlLength)
88 }
89
83 // Check credentials 90 // Check credentials
84 try { 91 try {
92 // Strip out everything after the domain:port.
93 // @see https://github.com/Chocobozzz/PeerTube/issues/3520
94 result.url = stripExtraneousFromPeerTubeUrl(result.url)
95
85 await getAccessToken(result.url, result.username, result.password) 96 await getAccessToken(result.url, result.username, result.password)
86 } catch (err) { 97 } catch (err) {
87 console.error(err.message) 98 console.error(err.message)