aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users/login.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/users/login.ts')
-rw-r--r--shared/extra-utils/users/login.ts13
1 files changed, 7 insertions, 6 deletions
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'
2 2
3import { ServerInfo } from '../server/servers' 3import { ServerInfo } from '../server/servers'
4import { getClient } from '../server/clients' 4import { getClient } from '../server/clients'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5 6
6type Client = { id: string, secret: string } 7type Client = { id: string, secret: string }
7type User = { username: string, password: string } 8type User = { username: string, password: string }
8type Server = { url: string, client: Client, user: User } 9type Server = { url: string, client: Client, user: User }
9 10
10function login (url: string, client: Client, user: User, expectedStatus = 200) { 11function login (url: string, client: Client, user: User, expectedStatus = HttpStatusCode.OK_200) {
11 const path = '/api/v1/users/token' 12 const path = '/api/v1/users/token'
12 13
13 const body = { 14 const body = {
@@ -27,7 +28,7 @@ function login (url: string, client: Client, user: User, expectedStatus = 200) {
27 .expect(expectedStatus) 28 .expect(expectedStatus)
28} 29}
29 30
30function logout (url: string, token: string, expectedStatus = 200) { 31function logout (url: string, token: string, expectedStatus = HttpStatusCode.OK_200) {
31 const path = '/api/v1/users/revoke-token' 32 const path = '/api/v1/users/revoke-token'
32 33
33 return request(url) 34 return request(url)
@@ -38,12 +39,12 @@ function logout (url: string, token: string, expectedStatus = 200) {
38} 39}
39 40
40async function serverLogin (server: Server) { 41async function serverLogin (server: Server) {
41 const res = await login(server.url, server.client, server.user, 200) 42 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
42 43
43 return res.body.access_token as string 44 return res.body.access_token as string
44} 45}
45 46
46function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = 200) { 47function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = HttpStatusCode.OK_200) {
47 const path = '/api/v1/users/token' 48 const path = '/api/v1/users/token'
48 49
49 const body = { 50 const body = {
@@ -61,7 +62,7 @@ function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus
61 .expect(expectedStatus) 62 .expect(expectedStatus)
62} 63}
63 64
64async function userLogin (server: Server, user: User, expectedStatus = 200) { 65async function userLogin (server: Server, user: User, expectedStatus = HttpStatusCode.OK_200) {
65 const res = await login(server.url, server.client, user, expectedStatus) 66 const res = await login(server.url, server.client, user, expectedStatus)
66 67
67 return res.body.access_token as string 68 return res.body.access_token as string
@@ -95,7 +96,7 @@ function setAccessTokensToServers (servers: ServerInfo[]) {
95 return Promise.all(tasks) 96 return Promise.all(tasks)
96} 97}
97 98
98function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = 200) { 99function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = HttpStatusCode.OK_200) {
99 const path = '/api/v1/users/token' 100 const path = '/api/v1/users/token'
100 101
101 const body = { 102 const body = {