Begin auth plugin support

This commit is contained in:
Chocobozzz
2020-04-22 16:07:04 +02:00
committed by Chocobozzz
parent 8d41976378
commit 7fed637506
23 changed files with 604 additions and 74 deletions

View File

@@ -40,7 +40,7 @@ import {
getVideoAbusesList, updateCustomSubConfig, getCustomConfig, waitJobs
} from '../../../../shared/extra-utils'
import { follow } from '../../../../shared/extra-utils/server/follows'
import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
import { setAccessTokensToServers, logout } from '../../../../shared/extra-utils/users/login'
import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
import { CustomConfig } from '@shared/models/server'
@@ -205,11 +205,17 @@ describe('Test users', function () {
})
describe('Logout', function () {
it('Should logout (revoke token)')
it('Should logout (revoke token)', async function () {
await logout(server.url, server.accessToken)
})
it('Should not be able to get the user information')
it('Should not be able to get the user information', async function () {
await getMyUserInformation(server.url, server.accessToken, 401)
})
it('Should not be able to upload a video')
it('Should not be able to upload a video', async function () {
await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401)
})
it('Should not be able to remove a video')

View File

@@ -0,0 +1,61 @@
async function register ({
registerIdAndPassAuth,
peertubeHelpers
}) {
registerIdAndPassAuth({
type: 'id-and-pass',
onLogout: () => {
peertubeHelpers.logger.info('On logout for auth 1 - 1')
},
getWeight: () => 15,
login (body) {
if (body.id === 'spyro' && body.password === 'spyro password') {
return Promise.resolve({
username: 'spyro',
email: 'spyro@example.com',
role: 0,
displayName: 'Spyro the Dragon'
})
}
return null
}
})
registerIdAndPassAuth({
type: 'id-and-pass',
onLogout: () => {
peertubeHelpers.logger.info('On logout for auth 1 - 2')
},
getWeight: () => 50,
login (body) {
if (body.id === 'crash' && body.password === 'crash password') {
return Promise.resolve({
username: 'crash',
email: 'crash@example.com',
role: 2,
displayName: 'Crash Bandicoot'
})
}
return null
}
})
}
async function unregister () {
return
}
module.exports = {
register,
unregister
}
// ###########################################################################

View File

@@ -0,0 +1,20 @@
{
"name": "peertube-plugin-test-id-pass-auth-one",
"version": "0.0.1",
"description": "Id and pass auth one",
"engine": {
"peertube": ">=1.3.0"
},
"keywords": [
"peertube",
"plugin"
],
"homepage": "https://github.com/Chocobozzz/PeerTube",
"author": "Chocobozzz",
"bugs": "https://github.com/Chocobozzz/PeerTube/issues",
"library": "./main.js",
"staticDirs": {},
"css": [],
"clientScripts": [],
"translations": {}
}

View File

@@ -0,0 +1,37 @@
async function register ({
registerIdAndPassAuth,
peertubeHelpers
}) {
registerIdAndPassAuth({
type: 'id-and-pass',
onLogout: () => {
peertubeHelpers.logger.info('On logout for auth 3 - 1')
},
getWeight: () => 5,
login (body) {
if (body.id === 'laguna' && body.password === 'laguna password') {
return Promise.resolve({
username: 'laguna',
email: 'laguna@example.com',
displayName: 'Laguna Loire'
})
}
return null
}
})
}
async function unregister () {
return
}
module.exports = {
register,
unregister
}
// ###########################################################################

View File

@@ -0,0 +1,20 @@
{
"name": "peertube-plugin-test-id-pass-auth-three",
"version": "0.0.1",
"description": "Id and pass auth three",
"engine": {
"peertube": ">=1.3.0"
},
"keywords": [
"peertube",
"plugin"
],
"homepage": "https://github.com/Chocobozzz/PeerTube",
"author": "Chocobozzz",
"bugs": "https://github.com/Chocobozzz/PeerTube/issues",
"library": "./main.js",
"staticDirs": {},
"css": [],
"clientScripts": [],
"translations": {}
}

View File

@@ -0,0 +1,36 @@
async function register ({
registerIdAndPassAuth,
peertubeHelpers
}) {
registerIdAndPassAuth({
type: 'id-and-pass',
onLogout: () => {
peertubeHelpers.logger.info('On logout for auth 2 - 1')
},
getWeight: () => 30,
login (body) {
if (body.id === 'laguna' && body.password === 'laguna password') {
return Promise.resolve({
username: 'laguna',
email: 'laguna@example.com'
})
}
return null
}
})
}
async function unregister () {
return
}
module.exports = {
register,
unregister
}
// ###########################################################################

View File

@@ -0,0 +1,20 @@
{
"name": "peertube-plugin-test-id-pass-auth-two",
"version": "0.0.1",
"description": "Id and pass auth two",
"engine": {
"peertube": ">=1.3.0"
},
"keywords": [
"peertube",
"plugin"
],
"homepage": "https://github.com/Chocobozzz/PeerTube",
"author": "Chocobozzz",
"bugs": "https://github.com/Chocobozzz/PeerTube/issues",
"library": "./main.js",
"staticDirs": {},
"css": [],
"clientScripts": [],
"translations": {}
}

View File

@@ -0,0 +1,69 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils'
describe('Test id and pass auth plugins', function () {
let server: ServerInfo
before(async function () {
this.timeout(30000)
server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ])
await installPlugin({
url: server.url,
accessToken: server.accessToken,
path: getPluginTestPath('-id-pass-auth-one')
})
await installPlugin({
url: server.url,
accessToken: server.accessToken,
path: getPluginTestPath('-id-pass-auth-two')
})
})
it('Should not login', async function() {
})
it('Should login Spyro, create the user and use the token', async function() {
})
it('Should login Crash, create the user and use the token', async function() {
})
it('Should login the first Laguna, create the user and use the token', async function() {
})
it('Should update Crash profile', async function () {
})
it('Should logout Crash', async function () {
// test token
})
it('Should have logged the Crash logout', async function () {
})
it('Should login Crash and keep the old existing profile', async function () {
})
it('Should uninstall the plugin one and do not login existing Crash', async function () {
})
after(async function () {
await cleanupTests([ server ])
})
})

View File

@@ -1,4 +1,5 @@
import './action-hooks'
import './id-and-pass-auth'
import './filter-hooks'
import './translations'
import './video-constants'