Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

(#3520) [cli] Hardened `auth add`: No longer fails with extraneous characters.

Theodore R. Smith8e76aa1d75ae
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index 3484385334..fcf7e2e2e5 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -66,6 +66,18 @@ describe('Test CLI wrapper', function () {
await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
})
+ it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
+ this.timeout(60000)
+
+ const env = getEnvCli(server)
+ let fullServerURL
+ fullServerURL = server.url + '/'
+ await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
+
+ fullServerURL = server.url + '/asdfasdf'
+ await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
+ })
+
it('Should default to this user', async function () {
this.timeout(60000)
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts
index 1a4fae4ced..7673b92cd2 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)