From f2eb23cd87cf32b8fe545178143b5f49e06a58da Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 8 Dec 2020 21:16:10 +0100 Subject: emit more specific status codes on video upload (#3423) - reduce http status codes list to potentially useful codes - convert more codes to typed ones - factorize html generator for error responses --- shared/extra-utils/users/login.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'shared/extra-utils/users/login.ts') diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index 275bb0826..39e1a2747 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts @@ -2,12 +2,13 @@ import * as request from 'supertest' import { ServerInfo } from '../server/servers' import { getClient } from '../server/clients' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' type Client = { id: string, secret: string } type User = { username: string, password: string } type Server = { url: string, client: Client, user: User } -function login (url: string, client: Client, user: User, expectedStatus = 200) { +function login (url: string, client: Client, user: User, expectedStatus = HttpStatusCode.OK_200) { const path = '/api/v1/users/token' const body = { @@ -27,7 +28,7 @@ function login (url: string, client: Client, user: User, expectedStatus = 200) { .expect(expectedStatus) } -function logout (url: string, token: string, expectedStatus = 200) { +function logout (url: string, token: string, expectedStatus = HttpStatusCode.OK_200) { const path = '/api/v1/users/revoke-token' return request(url) @@ -38,12 +39,12 @@ function logout (url: string, token: string, expectedStatus = 200) { } async function serverLogin (server: Server) { - const res = await login(server.url, server.client, server.user, 200) + const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) return res.body.access_token as string } -function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) { +function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = HttpStatusCode.OK_200) { const path = '/api/v1/users/token' const body = { @@ -61,7 +62,7 @@ function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus .expect(expectedStatus) } -async function userLogin (server: Server, user: User, expectedStatus = 200) { +async function userLogin (server: Server, user: User, expectedStatus = HttpStatusCode.OK_200) { const res = await login(server.url, server.client, user, expectedStatus) return res.body.access_token as string @@ -95,7 +96,7 @@ function setAccessTokensToServers (servers: ServerInfo[]) { return Promise.all(tasks) } -function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = 200) { +function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = HttpStatusCode.OK_200) { const path = '/api/v1/users/token' const body = { -- cgit v1.2.3