aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-30 11:27:00 +0100
committerChocobozzz <me@florianbigard.com>2020-12-30 11:27:00 +0100
commit6eb3a98843b845ce27a2231e40d466e1b40d0264 (patch)
tree8829394d961faf0ed75d943175bd705fc9d76109
parenta0194a187fba31ccb895a245134e8713798da47e (diff)
parent24198e976f41bcc41b90c640f2c51931fc22b0a4 (diff)
downloadPeerTube-6eb3a98843b845ce27a2231e40d466e1b40d0264.tar.gz
PeerTube-6eb3a98843b845ce27a2231e40d466e1b40d0264.tar.zst
PeerTube-6eb3a98843b845ce27a2231e40d466e1b40d0264.zip
Merge branch '3520-cli_auth_add_trailing_slash' into release/3.0.0
-rw-r--r--server/tests/cli/peertube.ts12
-rw-r--r--server/tools/peertube-auth.ts14
2 files changed, 26 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..6a0b89fe2 100644
--- a/server/tools/peertube-auth.ts
+++ b/server/tools/peertube-auth.ts
@@ -46,6 +46,15 @@ function isURLaPeerTubeInstance (url: string) {
46 return url.startsWith('http://') || url.startsWith('https://') 46 return url.startsWith('http://') || url.startsWith('https://')
47} 47}
48 48
49function stripExtraneousFromPeerTubeUrl (url: string) {
50 // Get everything before the 3rd /.
51 const urlLength = url.includes('/', 8)
52 ? url.indexOf('/', 8)
53 : url.length
54
55 return url.substr(0, urlLength)
56}
57
49program 58program
50 .name('auth') 59 .name('auth')
51 .usage('[command] [options]') 60 .usage('[command] [options]')
@@ -80,8 +89,13 @@ program
80 } 89 }
81 } 90 }
82 }, async (_, result) => { 91 }, async (_, result) => {
92
83 // Check credentials 93 // Check credentials
84 try { 94 try {
95 // Strip out everything after the domain:port.
96 // @see https://github.com/Chocobozzz/PeerTube/issues/3520
97 result.url = stripExtraneousFromPeerTubeUrl(result.url)
98
85 await getAccessToken(result.url, result.username, result.password) 99 await getAccessToken(result.url, result.username, result.password)
86 } catch (err) { 100 } catch (err) {
87 console.error(err.message) 101 console.error(err.message)