X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Fid-and-pass-auth.ts;h=cbba638c2bab3788fbe39509fe9f8f21155cd916;hb=9129b7694d577322327ee79e9b9aa64deee92765;hp=0268d35a037c96f736db70e4b50ca103c8dd1fbc;hpb=e307e4fce39853d445d086f92b8c556c363ee15d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 0268d35a0..cbba638c2 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -12,9 +12,9 @@ import { updateMyUser, userLogin, wait, - login, refreshToken + login, refreshToken, getConfig, updatePluginSettings, getUsersList } from '../../../shared/extra-utils' -import { User, UserRole } from '@shared/models' +import { User, UserRole, ServerConfig } from '@shared/models' import { expect } from 'chai' describe('Test id and pass auth plugins', function () { @@ -41,6 +41,20 @@ describe('Test id and pass auth plugins', function () { } }) + it('Should display the correct configuration', async function () { + const res = await getConfig(server.url) + + const config: ServerConfig = res.body + + const auths = config.plugin.registeredIdAndPassAuths + expect(auths).to.have.lengthOf(8) + + const crashAuth = auths.find(a => a.authName === 'crash-auth') + expect(crashAuth).to.exist + expect(crashAuth.npmName).to.equal('peertube-plugin-test-id-pass-auth-one') + expect(crashAuth.weight).to.equal(50) + }) + it('Should not login', async function () { await userLogin(server, { username: 'toto', password: 'password' }, 400) }) @@ -143,7 +157,7 @@ describe('Test id and pass auth plugins', function () { expect(body.role).to.equal(UserRole.MODERATOR) }) - it('Should correctly auth token of laguna', async function () { + it('Should reject token of laguna by the plugin hook', async function () { this.timeout(10000) await wait(5000) @@ -151,6 +165,44 @@ describe('Test id and pass auth plugins', function () { await getMyUserInformation(server.url, lagunaAccessToken, 401) }) + it('Should reject an invalid username, email, role or display name', async function () { + await userLogin(server, { username: 'ward', password: 'ward password' }, 400) + await waitUntilLog(server, 'valid username') + + await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400) + await waitUntilLog(server, 'valid display name') + + await userLogin(server, { username: 'raine', password: 'raine password' }, 400) + await waitUntilLog(server, 'valid role') + + await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400) + await waitUntilLog(server, 'valid email') + }) + + it('Should unregister spyro-auth and do not login existing Spyro', async function () { + await updatePluginSettings({ + url: server.url, + accessToken: server.accessToken, + npmName: 'peertube-plugin-test-id-pass-auth-one', + settings: { disableSpyro: true } + }) + + await userLogin(server, { username: 'spyro', password: 'spyro password' }, 400) + await userLogin(server, { username: 'spyro', password: 'fake' }, 400) + }) + + it('Should have disabled this auth', async function () { + const res = await getConfig(server.url) + + const config: ServerConfig = res.body + + const auths = config.plugin.registeredIdAndPassAuths + expect(auths).to.have.lengthOf(7) + + const spyroAuth = auths.find(a => a.authName === 'spyro-auth') + expect(spyroAuth).to.not.exist + }) + it('Should uninstall the plugin one and do not login existing Crash', async function () { await uninstallPlugin({ url: server.url, @@ -161,6 +213,32 @@ describe('Test id and pass auth plugins', function () { await userLogin(server, { username: 'crash', password: 'crash password' }, 400) }) + it('Should display the correct configuration', async function () { + const res = await getConfig(server.url) + + const config: ServerConfig = res.body + + const auths = config.plugin.registeredIdAndPassAuths + expect(auths).to.have.lengthOf(6) + + const crashAuth = auths.find(a => a.authName === 'crash-auth') + expect(crashAuth).to.not.exist + }) + + it('Should display plugin auth information in users list', async function () { + const res = await getUsersList(server.url, server.accessToken) + + const users: User[] = res.body.data + + const root = users.find(u => u.username === 'root') + const crash = users.find(u => u.username === 'crash') + const laguna = users.find(u => u.username === 'laguna') + + expect(root.pluginAuth).to.be.null + expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') + expect(laguna.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-two') + }) + after(async function () { await cleanupTests([ server ]) })