test: admin apis authorization
Massimo Melina committed
Feb 24, 2025 at 19:09 UTC
9e259b730d0c2f4a9be7ec2f0e669e606267d371
2 files changed
+11
-7
tests/config.yaml
+1
@@ -1,6 +1,7 @@
1
port: 81
2
open_browser_at_start: false
3
allowed_referer: x.com
4
+localhost_admin: false
5
vfs:
6
masks:
7
"!tests/page/*.png":
tests/test.ts
+10
-7
@@ -156,15 +156,10 @@ describe('basics', () => {
156
it('folder size', reqApi('get_folder_size', { uri: 'f1/page' }, res => res.bytes === 6328 ))
157
it('folder size.cant', reqApi('get_folder_size', { uri: 'for-admins' }, 401))
158
159
- it('get_accounts', reqApi('get_accounts', {}, ({ list }) => _.find(list, { username}) && _.find(list, { username: 'admins' })))
160
-})
161
-
162
-describe('accounts', () => {
163
- const username = 'test-Add'
164
- it('accounts.add', reqApi('add_account', { username }, res => res?.username === username.toLowerCase()))
165
- it('accounts.remove', reqApi('del_account', { username }, 200))
159
+ it('get_accounts', reqApi('get_accounts', {}, 401)) // admin api requires login
160
})
161
162
+// do this before login, or max_dl_accounts config will override max_dl
163
describe('limits', () => {
164
const fn = ROOT + 'big'
165
before(() => writeFile(fn, BIG_CONTENT))
@@ -172,6 +167,14 @@ describe('limits', () => {
167
after(() => rm(fn))
168
})
169
170
+describe('accounts', () => {
171
+ before(() => login(username))
172
+ it('get_accounts', reqApi('get_accounts', {}, ({ list }) => _.find(list, { username }) && _.find(list, { username: 'admins' })))
173
+ const add = 'test-Add'
174
+ it('accounts.add', reqApi('add_account', { username: add }, res => res?.username === add.toLowerCase()))
175
+ it('accounts.remove', reqApi('del_account', { username: add }, 200))
176
+})
177
+
178
describe('after-login', () => {
179
before(() => login(username))
180
it('create_folder', reqApi('create_folder', { uri: UPLOAD_ROOT, name: 'temp' }, 200))