aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/users/users.ts34
-rw-r--r--server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js8
-rw-r--r--server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js2
-rw-r--r--server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js2
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts97
5 files changed, 105 insertions, 38 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 7ba04a4ca..60fbd2a20 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -2,8 +2,9 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { MyUser, User, UserRole, Video, VideoPlaylistType, VideoAbuseState, VideoAbuseUpdate } from '../../../../shared/index' 5import { MyUser, User, UserRole, Video, VideoAbuseState, VideoAbuseUpdate, VideoPlaylistType } from '../../../../shared/index'
6import { 6import {
7 addVideoCommentThread,
7 blockUser, 8 blockUser,
8 cleanupTests, 9 cleanupTests,
9 createUser, 10 createUser,
@@ -11,12 +12,14 @@ import {
11 flushAndRunServer, 12 flushAndRunServer,
12 getAccountRatings, 13 getAccountRatings,
13 getBlacklistedVideosList, 14 getBlacklistedVideosList,
15 getCustomConfig,
14 getMyUserInformation, 16 getMyUserInformation,
15 getMyUserVideoQuotaUsed, 17 getMyUserVideoQuotaUsed,
16 getMyUserVideoRating, 18 getMyUserVideoRating,
17 getUserInformation, 19 getUserInformation,
18 getUsersList, 20 getUsersList,
19 getUsersListPaginationAndSort, 21 getUsersListPaginationAndSort,
22 getVideoAbusesList,
20 getVideoChannel, 23 getVideoChannel,
21 getVideosList, 24 getVideosList,
22 installPlugin, 25 installPlugin,
@@ -26,21 +29,21 @@ import {
26 registerUserWithChannel, 29 registerUserWithChannel,
27 removeUser, 30 removeUser,
28 removeVideo, 31 removeVideo,
32 reportVideoAbuse,
29 ServerInfo, 33 ServerInfo,
30 testImage, 34 testImage,
31 unblockUser, 35 unblockUser,
36 updateCustomSubConfig,
32 updateMyAvatar, 37 updateMyAvatar,
33 updateMyUser, 38 updateMyUser,
34 updateUser, 39 updateUser,
40 updateVideoAbuse,
35 uploadVideo, 41 uploadVideo,
36 userLogin, 42 userLogin,
37 reportVideoAbuse, 43 waitJobs
38 addVideoCommentThread,
39 updateVideoAbuse,
40 getVideoAbusesList, updateCustomSubConfig, getCustomConfig, waitJobs
41} from '../../../../shared/extra-utils' 44} from '../../../../shared/extra-utils'
42import { follow } from '../../../../shared/extra-utils/server/follows' 45import { follow } from '../../../../shared/extra-utils/server/follows'
43import { setAccessTokensToServers, logout } from '../../../../shared/extra-utils/users/login' 46import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
44import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' 47import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
45import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 48import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
46import { CustomConfig } from '@shared/models/server' 49import { CustomConfig } from '@shared/models/server'
@@ -60,7 +63,14 @@ describe('Test users', function () {
60 63
61 before(async function () { 64 before(async function () {
62 this.timeout(30000) 65 this.timeout(30000)
63 server = await flushAndRunServer(1) 66
67 server = await flushAndRunServer(1, {
68 rates_limit: {
69 login: {
70 max: 30
71 }
72 }
73 })
64 74
65 await setAccessTokensToServers([ server ]) 75 await setAccessTokensToServers([ server ])
66 76
@@ -217,8 +227,6 @@ describe('Test users', function () {
217 await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) 227 await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401)
218 }) 228 })
219 229
220 it('Should not be able to remove a video')
221
222 it('Should not be able to rate a video', async function () { 230 it('Should not be able to rate a video', async function () {
223 const path = '/api/v1/videos/' 231 const path = '/api/v1/videos/'
224 const data = { 232 const data = {
@@ -235,13 +243,17 @@ describe('Test users', function () {
235 await makePutBodyRequest(options) 243 await makePutBodyRequest(options)
236 }) 244 })
237 245
238 it('Should be able to login again') 246 it('Should be able to login again', async function () {
247 server.accessToken = await serverLogin(server)
248 })
239 249
240 it('Should have an expired access token') 250 it('Should have an expired access token')
241 251
242 it('Should refresh the token') 252 it('Should refresh the token')
243 253
244 it('Should be able to upload a video again') 254 it('Should be able to get my user information again', async function () {
255 await getMyUserInformation(server.url, server.accessToken)
256 })
245 }) 257 })
246 258
247 describe('Creating a user', function () { 259 describe('Creating a user', function () {
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js
index 4755ed643..9fc12a3e3 100644
--- a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js
@@ -3,7 +3,7 @@ async function register ({
3 peertubeHelpers 3 peertubeHelpers
4}) { 4}) {
5 registerIdAndPassAuth({ 5 registerIdAndPassAuth({
6 type: 'id-and-pass', 6 authName: 'spyro-auth',
7 7
8 onLogout: () => { 8 onLogout: () => {
9 peertubeHelpers.logger.info('On logout for auth 1 - 1') 9 peertubeHelpers.logger.info('On logout for auth 1 - 1')
@@ -16,7 +16,7 @@ async function register ({
16 return Promise.resolve({ 16 return Promise.resolve({
17 username: 'spyro', 17 username: 'spyro',
18 email: 'spyro@example.com', 18 email: 'spyro@example.com',
19 role: 0, 19 role: 2,
20 displayName: 'Spyro the Dragon' 20 displayName: 'Spyro the Dragon'
21 }) 21 })
22 } 22 }
@@ -26,7 +26,7 @@ async function register ({
26 }) 26 })
27 27
28 registerIdAndPassAuth({ 28 registerIdAndPassAuth({
29 type: 'id-and-pass', 29 authName: 'crash-auth',
30 30
31 onLogout: () => { 31 onLogout: () => {
32 peertubeHelpers.logger.info('On logout for auth 1 - 2') 32 peertubeHelpers.logger.info('On logout for auth 1 - 2')
@@ -39,7 +39,7 @@ async function register ({
39 return Promise.resolve({ 39 return Promise.resolve({
40 username: 'crash', 40 username: 'crash',
41 email: 'crash@example.com', 41 email: 'crash@example.com',
42 role: 2, 42 role: 1,
43 displayName: 'Crash Bandicoot' 43 displayName: 'Crash Bandicoot'
44 }) 44 })
45 } 45 }
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js
index 2a15b3754..372f3fa0c 100644
--- a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js
@@ -3,7 +3,7 @@ async function register ({
3 peertubeHelpers 3 peertubeHelpers
4}) { 4}) {
5 registerIdAndPassAuth({ 5 registerIdAndPassAuth({
6 type: 'id-and-pass', 6 authName: 'laguna-bad-auth',
7 7
8 onLogout: () => { 8 onLogout: () => {
9 peertubeHelpers.logger.info('On logout for auth 3 - 1') 9 peertubeHelpers.logger.info('On logout for auth 3 - 1')
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js
index edfc870c0..c0e560019 100644
--- a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js
@@ -3,7 +3,7 @@ async function register ({
3 peertubeHelpers 3 peertubeHelpers
4}) { 4}) {
5 registerIdAndPassAuth({ 5 registerIdAndPassAuth({
6 type: 'id-and-pass', 6 authName: 'laguna-auth',
7 7
8 onLogout: () => { 8 onLogout: () => {
9 peertubeHelpers.logger.info('On logout for auth 2 - 1') 9 peertubeHelpers.logger.info('On logout for auth 2 - 1')
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index 5b4d1a1db..45fa7856c 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -1,11 +1,23 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
5import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' 5import {
6 getMyUserInformation,
7 getPluginTestPath,
8 installPlugin,
9 logout,
10 setAccessTokensToServers,
11 uninstallPlugin,
12 updateMyUser,
13 userLogin
14} from '../../../shared/extra-utils'
15import { User, UserRole } from '@shared/models'
16import { expect } from 'chai'
6 17
7describe('Test id and pass auth plugins', function () { 18describe('Test id and pass auth plugins', function () {
8 let server: ServerInfo 19 let server: ServerInfo
20 let crashToken: string
9 21
10 before(async function () { 22 before(async function () {
11 this.timeout(30000) 23 this.timeout(30000)
@@ -13,54 +25,97 @@ describe('Test id and pass auth plugins', function () {
13 server = await flushAndRunServer(1) 25 server = await flushAndRunServer(1)
14 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
15 27
16 await installPlugin({ 28 for (const suffix of [ 'one', 'two', 'three' ]) {
17 url: server.url, 29 await installPlugin({
18 accessToken: server.accessToken, 30 url: server.url,
19 path: getPluginTestPath('-id-pass-auth-one') 31 accessToken: server.accessToken,
20 }) 32 path: getPluginTestPath('-id-pass-auth-' + suffix)
21 33 })
22 await installPlugin({ 34 }
23 url: server.url,
24 accessToken: server.accessToken,
25 path: getPluginTestPath('-id-pass-auth-two')
26 })
27 }) 35 })
28 36
29 it('Should not login', async function() { 37 it('Should not login', async function () {
30 38 await userLogin(server, { username: 'toto', password: 'password' }, 400)
31 }) 39 })
32 40
33 it('Should login Spyro, create the user and use the token', async function() { 41 it('Should login Spyro, create the user and use the token', async function () {
42 const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' })
34 43
44 const res = await getMyUserInformation(server.url, accessToken)
45
46 const body: User = res.body
47 expect(body.username).to.equal('spyro')
48 expect(body.account.displayName).to.equal('Spyro the Dragon')
49 expect(body.role).to.equal(UserRole.USER)
35 }) 50 })
36 51
37 it('Should login Crash, create the user and use the token', async function() { 52 it('Should login Crash, create the user and use the token', async function () {
53 crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
54
55 const res = await getMyUserInformation(server.url, crashToken)
38 56
57 const body: User = res.body
58 expect(body.username).to.equal('crash')
59 expect(body.account.displayName).to.equal('Crash Bandicoot')
60 expect(body.role).to.equal(UserRole.MODERATOR)
39 }) 61 })
40 62
41 it('Should login the first Laguna, create the user and use the token', async function() { 63 it('Should login the first Laguna, create the user and use the token', async function () {
64 const accessToken = await userLogin(server, { username: 'laguna', password: 'laguna password' })
42 65
66 const res = await getMyUserInformation(server.url, accessToken)
67
68 const body: User = res.body
69 expect(body.username).to.equal('laguna')
70 expect(body.account.displayName).to.equal('laguna')
71 expect(body.role).to.equal(UserRole.USER)
43 }) 72 })
44 73
45 it('Should update Crash profile', async function () { 74 it('Should update Crash profile', async function () {
75 await updateMyUser({
76 url: server.url,
77 accessToken: crashToken,
78 displayName: 'Beautiful Crash',
79 description: 'Mutant eastern barred bandicoot'
80 })
46 81
82 const res = await getMyUserInformation(server.url, crashToken)
83
84 const body: User = res.body
85 expect(body.account.displayName).to.equal('Beautiful Crash')
86 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
47 }) 87 })
48 88
49 it('Should logout Crash', async function () { 89 it('Should logout Crash', async function () {
50 90 await logout(server.url, crashToken)
51 // test token
52 }) 91 })
53 92
54 it('Should have logged the Crash logout', async function () { 93 it('Should have logged out Crash', async function () {
94 await getMyUserInformation(server.url, crashToken, 401)
55 95
96 await waitUntilLog(server, 'On logout for auth 1 - 2')
56 }) 97 })
57 98
58 it('Should login Crash and keep the old existing profile', async function () { 99 it('Should login Crash and keep the old existing profile', async function () {
100 crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
59 101
102 const res = await getMyUserInformation(server.url, crashToken)
103
104 const body: User = res.body
105 expect(body.username).to.equal('crash')
106 expect(body.account.displayName).to.equal('Beautiful Crash')
107 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
108 expect(body.role).to.equal(UserRole.MODERATOR)
60 }) 109 })
61 110
62 it('Should uninstall the plugin one and do not login existing Crash', async function () { 111 it('Should uninstall the plugin one and do not login existing Crash', async function () {
112 await uninstallPlugin({
113 url: server.url,
114 accessToken: server.accessToken,
115 npmName: 'peertube-plugin-test-id-pass-auth-one'
116 })
63 117
118 await userLogin(server, { username: 'crash', password: 'crash password' }, 400)
64 }) 119 })
65 120
66 after(async function () { 121 after(async function () {