Merge branch '3520-cli_auth_add_trailing_slash' into release/3.0.0

This commit is contained in:
Chocobozzz 2020-12-30 11:27:00 +01:00
commit 6eb3a98843
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 26 additions and 0 deletions

View File

@ -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)

View File

@ -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,8 +89,13 @@ program
}
}
}, async (_, result) => {
// 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)