Skip to content

Commit

Permalink
fix: handle permissions for the super-user (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Dec 16, 2024
1 parent 7e56635 commit c9549be
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
-p 64738:64738/tcp \
-p 64738:64738/udp \
-e MUMBLE_CONFIG_AUTOBAN_ATTEMPTS=0 \
-e MUMBLE_SUPERUSER_PASSWORD=123456 \
--volume ${{ github.workspace }}/e2e/mumble-data:/data \
--user root \
mumblevoip/mumble-server:latest
Expand Down
59 changes: 59 additions & 0 deletions e2e/manages-as-super-user.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Channel, Client } from '../src';
import { waitABit } from './utils/wait-a-bit';

describe('Manages server as the super-user (e2e)', () => {
let client: Client;

beforeAll(async () => {
client = new Client({
host: 'localhost',
port: 64738,
username: 'superuser',
password: '123456',
rejectUnauthorized: false,
});
await client.connect();
await waitABit(1000);
});

afterAll(async () => {
await waitABit(1000);
client.disconnect();
});

it('should create channels', async () => {
let channelCreatedEventEmitted = false;
client.once('channelCreate', (channel: Channel) => {
expect(channel.name).toEqual('sub10');
channelCreatedEventEmitted = true;
});

expect(client.user?.channel).toBeTruthy();
const channel = client.user!.channel;
expect(channel).toBeTruthy();
const sub1 = await channel.createSubChannel('sub10');
expect(sub1.parent).toEqual(channel.id);
expect(channelCreatedEventEmitted).toBe(true);

const sub2 = await sub1.createSubChannel('sub11');
expect(sub2.parent).toEqual(sub1.id);
});

it('should remove channels', async () => {
let channelRemoveEventEmitted = false;

client.once('channelRemove', (channel: Channel) => {
expect(channel.name).toEqual('sub11');
channelRemoveEventEmitted = true;
});

const sub2 = client.channels.byName('sub11');
await sub2?.remove();
expect(client.channels.byName('sub11')).toBe(undefined);
expect(channelRemoveEventEmitted).toBe(true);

const sub1 = client.channels.byName('sub10');
await sub1?.remove();
expect(client.channels.byName('sub10')).toBe(undefined);
});
});
Binary file modified e2e/mumble-data/murmur.sqlite
Binary file not shown.
4 changes: 4 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export class Channel {
* @returns Permissions.
*/
async getPermissions(): Promise<Permissions> {
if (this.client.user?.userId === 0) {
return Permissions.superUser();
}

if (this.client.permissions.has(this.id)) {
return this.client.permissions.get(this.id)!;
}
Expand Down
7 changes: 7 additions & 0 deletions src/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ enum Permission {
}

export class Permissions {
static superUser(): Permissions {
return new Permissions(
// https://github.com/mumble-voip/mumble/blob/edd4588c8ae03d785d59102e2435151a682ec51d/src/ACL.cpp#L106
Permission.All & ~(Permission.Speak | Permission.Whisper),
);
}

constructor(public readonly permissions: number) {}

get canJoinChannel(): boolean {
Expand Down
2 changes: 2 additions & 0 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class User {
readonly session: number;
name?: string;
channelId = 0;
userId?: number;
mute = false;
deaf = false;
suppress = false;
Expand Down Expand Up @@ -55,6 +56,7 @@ export class User {
const changes: UserChanges = {
...syncProperty(this, 'name', userState.name),
...syncProperty(this, 'channelId', userState.channelId),
...syncProperty(this, 'userId', userState.userId),
...syncProperty(this, 'mute', userState.mute),
...syncProperty(this, 'deaf', userState.deaf),
...syncProperty(this, 'suppress', userState.suppress),
Expand Down

0 comments on commit c9549be

Please sign in to comment.