aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/users')
-rw-r--r--shared/extra-utils/users/login.ts19
-rw-r--r--shared/extra-utils/users/users.ts8
2 files changed, 23 insertions, 4 deletions
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts
index ddeb9df2a..f9bfb3cb3 100644
--- a/shared/extra-utils/users/login.ts
+++ b/shared/extra-utils/users/login.ts
@@ -1,6 +1,7 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2 2
3import { ServerInfo } from '../server/servers' 3import { ServerInfo } from '../server/servers'
4import { getClient } from '../server/clients'
4 5
5type Client = { id: string, secret: string } 6type Client = { id: string, secret: string }
6type User = { username: string, password: string } 7type User = { username: string, password: string }
@@ -38,6 +39,23 @@ async function userLogin (server: Server, user: User, expectedStatus = 200) {
38 return res.body.access_token as string 39 return res.body.access_token as string
39} 40}
40 41
42async function getAccessToken (url: string, username: string, password: string) {
43 const resClient = await getClient(url)
44 const client = {
45 id: resClient.body.client_id,
46 secret: resClient.body.client_secret
47 }
48
49 const user = { username, password }
50
51 try {
52 const res = await login(url, client, user)
53 return res.body.access_token
54 } catch (err) {
55 throw new Error('Cannot authenticate. Please check your username/password.')
56 }
57}
58
41function setAccessTokensToServers (servers: ServerInfo[]) { 59function setAccessTokensToServers (servers: ServerInfo[]) {
42 const tasks: Promise<any>[] = [] 60 const tasks: Promise<any>[] = []
43 61
@@ -55,6 +73,7 @@ export {
55 login, 73 login,
56 serverLogin, 74 serverLogin,
57 userLogin, 75 userLogin,
76 getAccessToken,
58 setAccessTokensToServers, 77 setAccessTokensToServers,
59 Server, 78 Server,
60 Client, 79 Client,
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
index 1c39881d6..5fa8cde0c 100644
--- a/shared/extra-utils/users/users.ts
+++ b/shared/extra-utils/users/users.ts
@@ -1,11 +1,11 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' 2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
3
4import { UserCreate, UserRole } from '../../index'
5import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' 3import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
6import { ServerInfo, userLogin } from '..'
7import { UserAdminFlag } from '../../models/users/user-flag.model' 4import { UserAdminFlag } from '../../models/users/user-flag.model'
8import { UserRegister } from '../../models/users/user-register.model' 5import { UserRegister } from '../../models/users/user-register.model'
6import { UserRole } from '../../models/users/user-role'
7import { ServerInfo } from '../server/servers'
8import { userLogin } from './login'
9 9
10type CreateUserArgs = { url: string, 10type CreateUserArgs = { url: string,
11 accessToken: string, 11 accessToken: string,