Restrict fleet settings reads to administrators (Refs #99)
This commit is contained in:
@@ -39,7 +39,11 @@ describe('management route permissions', () => {
|
||||
expect(allows('admin', route, method)).toBe(true);
|
||||
});
|
||||
|
||||
it.each(['/api/users', '/api/users/[id]', '/api/users/[id]/password', '/settings', '/settings/users', '/server-keys', '/keys', '/api/server-keys', '/api/provisioning/[id]/override'])('reserves all methods on %s for administrators', route => {
|
||||
it.each([
|
||||
'/api/users', '/api/users/[id]', '/api/users/[id]/password', '/settings', '/settings/users',
|
||||
'/api/settings', '/api/settings/retention', '/api/settings/retention/preview',
|
||||
'/server-keys', '/keys', '/api/server-keys', '/api/provisioning/[id]/override'
|
||||
])('reserves all methods on %s for administrators', route => {
|
||||
for (const method of ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE']) {
|
||||
expect(routePermission(route, method)).toBe('admin');
|
||||
expect(allows('viewer', route, method)).toBe(false);
|
||||
@@ -51,7 +55,7 @@ describe('management route permissions', () => {
|
||||
it.each([
|
||||
['/api/hosts', 'POST'], ['/api/hosts/[id]', 'PATCH'], ['/api/hosts/[id]', 'DELETE'], ['/api/hosts/[id]/enrollment', 'POST'],
|
||||
['/api/hosts/[id]/credentials', 'DELETE'], ['/api/hosts/[id]/credentials', 'POST'],
|
||||
['/api/hosts/[id]/operations', 'POST'], ['/api/settings', 'PUT'], ['/api/game-files', 'POST'],
|
||||
['/api/hosts/[id]/operations', 'POST'], ['/api/game-files', 'POST'],
|
||||
['/api/game-files/[id]/download', 'POST'], ['/api/game-files/[id]/upload/files/[...path]', 'PUT'],
|
||||
['/api/game-files/[id]/upload/complete', 'POST'], ['/api/maintenance', 'POST'], ['/api/watchdog', 'POST'], ['/api/plutonium', 'POST']
|
||||
])('protects host, game-file, and global policy mutations at %s', (route, method) => {
|
||||
|
||||
@@ -142,6 +142,15 @@ describe('browser authentication guard', () => {
|
||||
if (expectedStatus === 200) { expect(call.resolve).toHaveBeenCalledOnce(); expect(call.event.locals.user).toEqual(session.user); }
|
||||
else expect(call.resolve).not.toHaveBeenCalled();
|
||||
});
|
||||
it.each(['GET', 'HEAD'])('restricts global settings %s requests to administrators', async method => {
|
||||
for (const role of ['viewer', 'operator', 'admin'] as const) {
|
||||
signIn(role);
|
||||
const call = requestFor('/api/settings', { method });
|
||||
expect((await call.invoke()).status).toBe(role === 'admin' ? 200 : 403);
|
||||
if (role === 'admin') expect(call.resolve).toHaveBeenCalledOnce();
|
||||
else expect(call.resolve).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
it.each(['GET', 'HEAD'])('restricts raw beta file %s requests to operators and administrators', async method => {
|
||||
for (const role of ['viewer', 'operator', 'admin'] as const) {
|
||||
signIn(role);
|
||||
|
||||
Reference in New Issue
Block a user