]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/external-auth.ts
Optimize broadcast job creation
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / external-auth.ts
index 48f942f7ff9f5961d759a956106bbb0c1e45d149..583100671cdd73118d9f41c26a0fb02077f412d5 100644 (file)
@@ -2,33 +2,32 @@
 
 import 'mocha'
 import { expect } from 'chai'
-import { HttpStatusCode } from '@shared/core-utils'
+import { wait } from '@shared/core-utils'
+import { HttpStatusCode, UserRole } from '@shared/models'
 import {
   cleanupTests,
+  createSingleServer,
   decodeQueryString,
-  flushAndRunServer,
+  PeerTubeServer,
   PluginsCommand,
-  ServerInfo,
-  setAccessTokensToServers,
-  wait
-} from '@shared/extra-utils'
-import { UserRole } from '@shared/models'
+  setAccessTokensToServers
+} from '@shared/server-commands'
 
 async function loginExternal (options: {
-  server: ServerInfo
+  server: PeerTubeServer
   npmName: string
   authName: string
   username: string
   query?: any
-  statusCodeExpected?: HttpStatusCode
-  statusCodeExpectedStep2?: HttpStatusCode
+  expectedStatus?: HttpStatusCode
+  expectedStatusStep2?: HttpStatusCode
 }) {
   const res = await options.server.plugins.getExternalAuth({
     npmName: options.npmName,
     npmVersion: '0.0.1',
     authName: options.authName,
     query: options.query,
-    expectedStatus: options.statusCodeExpected || HttpStatusCode.FOUND_302
+    expectedStatus: options.expectedStatus || HttpStatusCode.FOUND_302
   })
 
   if (res.status !== HttpStatusCode.FOUND_302) return
@@ -39,14 +38,14 @@ async function loginExternal (options: {
   const resLogin = await options.server.login.loginUsingExternalToken({
     username: options.username,
     externalAuthToken: externalAuthToken as string,
-    expectedStatus: options.statusCodeExpectedStep2
+    expectedStatus: options.expectedStatusStep2
   })
 
   return resLogin.body
 }
 
 describe('Test external auth plugins', function () {
-  let server: ServerInfo
+  let server: PeerTubeServer
 
   let cyanAccessToken: string
   let cyanRefreshToken: string
@@ -59,7 +58,7 @@ describe('Test external auth plugins', function () {
   before(async function () {
     this.timeout(30000)
 
-    server = await flushAndRunServer(1)
+    server = await createSingleServer(1)
     await setAccessTokensToServers([ server ])
 
     for (const suffix of [ 'one', 'two', 'three' ]) {
@@ -126,7 +125,7 @@ describe('Test external auth plugins', function () {
       expectedStatus: HttpStatusCode.BAD_REQUEST_400
     })
 
-    await server.servers.waitUntilLog('expired external auth token', 2)
+    await server.servers.waitUntilLog('expired external auth token', 4)
   })
 
   it('Should auto login Cyan, create the user and use the token', async function () {
@@ -268,7 +267,7 @@ describe('Test external auth plugins', function () {
         username: 'kefka'
       },
       username: 'kefka',
-      statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+      expectedStatus: HttpStatusCode.NOT_FOUND_404
     })
   })
 
@@ -293,7 +292,7 @@ describe('Test external auth plugins', function () {
         username: 'cyan'
       },
       username: 'cyan',
-      statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+      expectedStatus: HttpStatusCode.NOT_FOUND_404
     })
 
     await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
@@ -307,7 +306,7 @@ describe('Test external auth plugins', function () {
       npmName: 'test-external-auth-two',
       authName: 'external-auth-4',
       username: 'kefka2',
-      statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
+      expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
     })
 
     await loginExternal({
@@ -315,7 +314,7 @@ describe('Test external auth plugins', function () {
       npmName: 'test-external-auth-two',
       authName: 'external-auth-4',
       username: 'kefka',
-      statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
+      expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
     })
   })
 
@@ -327,7 +326,7 @@ describe('Test external auth plugins', function () {
       npmName: 'test-external-auth-two',
       authName: 'external-auth-6',
       username: 'existing_user',
-      statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
+      expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
     })
   })