aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-01-19 09:28:29 +0100
committerChocobozzz <chocobozzz@cpy.re>2023-01-19 13:53:40 +0100
commitb379759f55a35837b803a3b988674972db2903d1 (patch)
tree895d556973fea9be21492fb60aec2ff7767f5b18 /shared
parent3e5716dd3a5b0db4a1db327714247da687419f92 (diff)
downloadPeerTube-b379759f55a35837b803a3b988674972db2903d1.tar.gz
PeerTube-b379759f55a35837b803a3b988674972db2903d1.tar.zst
PeerTube-b379759f55a35837b803a3b988674972db2903d1.zip
Add signup approval API tests
Diffstat (limited to 'shared')
-rw-r--r--shared/server-commands/server/config-command.ts50
-rw-r--r--shared/server-commands/server/server.ts3
-rw-r--r--shared/server-commands/users/index.ts1
-rw-r--r--shared/server-commands/users/registrations-command.ts157
-rw-r--r--shared/server-commands/users/users-command.ts29
5 files changed, 204 insertions, 36 deletions
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts
index 1c2315ed1..51267b85b 100644
--- a/shared/server-commands/server/config-command.ts
+++ b/shared/server-commands/server/config-command.ts
@@ -18,6 +18,33 @@ export class ConfigCommand extends AbstractCommand {
18 } 18 }
19 } 19 }
20 20
21 // ---------------------------------------------------------------------------
22
23 static getEmailOverrideConfig (emailPort: number) {
24 return {
25 smtp: {
26 hostname: '127.0.0.1',
27 port: emailPort
28 }
29 }
30 }
31
32 // ---------------------------------------------------------------------------
33
34 enableSignup (requiresApproval: boolean) {
35 return this.updateExistingSubConfig({
36 newConfig: {
37 signup: {
38 enabled: true,
39 requiresApproval,
40 limit: -1
41 }
42 }
43 })
44 }
45
46 // ---------------------------------------------------------------------------
47
21 disableImports () { 48 disableImports () {
22 return this.setImportsEnabled(false) 49 return this.setImportsEnabled(false)
23 } 50 }
@@ -44,6 +71,16 @@ export class ConfigCommand extends AbstractCommand {
44 }) 71 })
45 } 72 }
46 73
74 // ---------------------------------------------------------------------------
75
76 enableChannelSync () {
77 return this.setChannelSyncEnabled(true)
78 }
79
80 disableChannelSync () {
81 return this.setChannelSyncEnabled(false)
82 }
83
47 private setChannelSyncEnabled (enabled: boolean) { 84 private setChannelSyncEnabled (enabled: boolean) {
48 return this.updateExistingSubConfig({ 85 return this.updateExistingSubConfig({
49 newConfig: { 86 newConfig: {
@@ -56,13 +93,7 @@ export class ConfigCommand extends AbstractCommand {
56 }) 93 })
57 } 94 }
58 95
59 enableChannelSync () { 96 // ---------------------------------------------------------------------------
60 return this.setChannelSyncEnabled(true)
61 }
62
63 disableChannelSync () {
64 return this.setChannelSyncEnabled(false)
65 }
66 97
67 enableLive (options: { 98 enableLive (options: {
68 allowReplay?: boolean 99 allowReplay?: boolean
@@ -142,6 +173,8 @@ export class ConfigCommand extends AbstractCommand {
142 }) 173 })
143 } 174 }
144 175
176 // ---------------------------------------------------------------------------
177
145 enableStudio () { 178 enableStudio () {
146 return this.updateExistingSubConfig({ 179 return this.updateExistingSubConfig({
147 newConfig: { 180 newConfig: {
@@ -152,6 +185,8 @@ export class ConfigCommand extends AbstractCommand {
152 }) 185 })
153 } 186 }
154 187
188 // ---------------------------------------------------------------------------
189
155 getConfig (options: OverrideCommandOptions = {}) { 190 getConfig (options: OverrideCommandOptions = {}) {
156 const path = '/api/v1/config' 191 const path = '/api/v1/config'
157 192
@@ -304,6 +339,7 @@ export class ConfigCommand extends AbstractCommand {
304 signup: { 339 signup: {
305 enabled: false, 340 enabled: false,
306 limit: 5, 341 limit: 5,
342 requiresApproval: true,
307 requiresEmailVerification: false, 343 requiresEmailVerification: false,
308 minimumAge: 16 344 minimumAge: 16
309 }, 345 },
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts
index ae1395a74..793fae3a8 100644
--- a/shared/server-commands/server/server.ts
+++ b/shared/server-commands/server/server.ts
@@ -18,6 +18,7 @@ import {
18 BlocklistCommand, 18 BlocklistCommand,
19 LoginCommand, 19 LoginCommand,
20 NotificationsCommand, 20 NotificationsCommand,
21 RegistrationsCommand,
21 SubscriptionsCommand, 22 SubscriptionsCommand,
22 TwoFactorCommand, 23 TwoFactorCommand,
23 UsersCommand 24 UsersCommand
@@ -147,6 +148,7 @@ export class PeerTubeServer {
147 views?: ViewsCommand 148 views?: ViewsCommand
148 twoFactor?: TwoFactorCommand 149 twoFactor?: TwoFactorCommand
149 videoToken?: VideoTokenCommand 150 videoToken?: VideoTokenCommand
151 registrations?: RegistrationsCommand
150 152
151 constructor (options: { serverNumber: number } | { url: string }) { 153 constructor (options: { serverNumber: number } | { url: string }) {
152 if ((options as any).url) { 154 if ((options as any).url) {
@@ -430,5 +432,6 @@ export class PeerTubeServer {
430 this.views = new ViewsCommand(this) 432 this.views = new ViewsCommand(this)
431 this.twoFactor = new TwoFactorCommand(this) 433 this.twoFactor = new TwoFactorCommand(this)
432 this.videoToken = new VideoTokenCommand(this) 434 this.videoToken = new VideoTokenCommand(this)
435 this.registrations = new RegistrationsCommand(this)
433 } 436 }
434} 437}
diff --git a/shared/server-commands/users/index.ts b/shared/server-commands/users/index.ts
index 1afc02dc1..404756539 100644
--- a/shared/server-commands/users/index.ts
+++ b/shared/server-commands/users/index.ts
@@ -4,6 +4,7 @@ export * from './blocklist-command'
4export * from './login' 4export * from './login'
5export * from './login-command' 5export * from './login-command'
6export * from './notifications-command' 6export * from './notifications-command'
7export * from './registrations-command'
7export * from './subscriptions-command' 8export * from './subscriptions-command'
8export * from './two-factor-command' 9export * from './two-factor-command'
9export * from './users-command' 10export * from './users-command'
diff --git a/shared/server-commands/users/registrations-command.ts b/shared/server-commands/users/registrations-command.ts
new file mode 100644
index 000000000..4e97571f4
--- /dev/null
+++ b/shared/server-commands/users/registrations-command.ts
@@ -0,0 +1,157 @@
1import { pick } from '@shared/core-utils'
2import { HttpStatusCode, ResultList, UserRegistration, UserRegistrationRequest } from '@shared/models'
3import { unwrapBody } from '../requests'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class RegistrationsCommand extends AbstractCommand {
7
8 register (options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username'>) {
9 const { password = 'password', email = options.username + '@example.com' } = options
10 const path = '/api/v1/users/register'
11
12 return this.postBodyRequest({
13 ...options,
14
15 path,
16 fields: {
17 ...pick(options, [ 'username', 'displayName', 'channel' ]),
18
19 password,
20 email
21 },
22 implicitToken: false,
23 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
24 })
25 }
26
27 requestRegistration (
28 options: OverrideCommandOptions & Partial<UserRegistrationRequest> & Pick<UserRegistrationRequest, 'username' | 'registrationReason'>
29 ) {
30 const { password = 'password', email = options.username + '@example.com' } = options
31 const path = '/api/v1/users/registrations/request'
32
33 return unwrapBody<UserRegistration>(this.postBodyRequest({
34 ...options,
35
36 path,
37 fields: {
38 ...pick(options, [ 'username', 'displayName', 'channel', 'registrationReason' ]),
39
40 password,
41 email
42 },
43 implicitToken: false,
44 defaultExpectedStatus: HttpStatusCode.OK_200
45 }))
46 }
47
48 // ---------------------------------------------------------------------------
49
50 accept (options: OverrideCommandOptions & {
51 id: number
52 moderationResponse: string
53 }) {
54 const { id, moderationResponse } = options
55 const path = '/api/v1/users/registrations/' + id + '/accept'
56
57 return this.postBodyRequest({
58 ...options,
59
60 path,
61 fields: { moderationResponse },
62 implicitToken: true,
63 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
64 })
65 }
66
67 reject (options: OverrideCommandOptions & {
68 id: number
69 moderationResponse: string
70 }) {
71 const { id, moderationResponse } = options
72 const path = '/api/v1/users/registrations/' + id + '/reject'
73
74 return this.postBodyRequest({
75 ...options,
76
77 path,
78 fields: { moderationResponse },
79 implicitToken: true,
80 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
81 })
82 }
83
84 // ---------------------------------------------------------------------------
85
86 delete (options: OverrideCommandOptions & {
87 id: number
88 }) {
89 const { id } = options
90 const path = '/api/v1/users/registrations/' + id
91
92 return this.deleteRequest({
93 ...options,
94
95 path,
96 implicitToken: true,
97 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
98 })
99 }
100
101 // ---------------------------------------------------------------------------
102
103 list (options: OverrideCommandOptions & {
104 start?: number
105 count?: number
106 sort?: string
107 search?: string
108 } = {}) {
109 const path = '/api/v1/users/registrations'
110
111 return this.getRequestBody<ResultList<UserRegistration>>({
112 ...options,
113
114 path,
115 query: pick(options, [ 'start', 'count', 'sort', 'search' ]),
116 implicitToken: true,
117 defaultExpectedStatus: HttpStatusCode.OK_200
118 })
119 }
120
121 // ---------------------------------------------------------------------------
122
123 askSendVerifyEmail (options: OverrideCommandOptions & {
124 email: string
125 }) {
126 const { email } = options
127 const path = '/api/v1/users/registrations/ask-send-verify-email'
128
129 return this.postBodyRequest({
130 ...options,
131
132 path,
133 fields: { email },
134 implicitToken: false,
135 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
136 })
137 }
138
139 verifyEmail (options: OverrideCommandOptions & {
140 registrationId: number
141 verificationString: string
142 }) {
143 const { registrationId, verificationString } = options
144 const path = '/api/v1/users/registrations/' + registrationId + '/verify-email'
145
146 return this.postBodyRequest({
147 ...options,
148
149 path,
150 fields: {
151 verificationString
152 },
153 implicitToken: false,
154 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
155 })
156 }
157}
diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts
index 811b9685b..8a42fafc8 100644
--- a/shared/server-commands/users/users-command.ts
+++ b/shared/server-commands/users/users-command.ts
@@ -214,35 +214,6 @@ export class UsersCommand extends AbstractCommand {
214 return this.server.login.getAccessToken({ username, password }) 214 return this.server.login.getAccessToken({ username, password })
215 } 215 }
216 216
217 register (options: OverrideCommandOptions & {
218 username: string
219 password?: string
220 displayName?: string
221 email?: string
222 channel?: {
223 name: string
224 displayName: string
225 }
226 }) {
227 const { username, password = 'password', displayName, channel, email = username + '@example.com' } = options
228 const path = '/api/v1/users/register'
229
230 return this.postBodyRequest({
231 ...options,
232
233 path,
234 fields: {
235 username,
236 password,
237 email,
238 displayName,
239 channel
240 },
241 implicitToken: false,
242 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
243 })
244 }
245
246 // --------------------------------------------------------------------------- 217 // ---------------------------------------------------------------------------
247 218
248 getMyInfo (options: OverrideCommandOptions = {}) { 219 getMyInfo (options: OverrideCommandOptions = {}) {