Sharkey/packages/backend/test/unit/misc/is-system-account.ts

48 lines
2.3 KiB
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { isSystemAccount } from '@/misc/is-system-account.js';
describe(isSystemAccount, () => {
it('should return true for instance.actor', () => {
2024-10-07 15:45:58 +00:00
expect(isSystemAccount({ username: 'instance.actor', host: null })).toBeTruthy();
});
it('should return true for relay.actor', () => {
2024-10-07 15:45:58 +00:00
expect(isSystemAccount({ username: 'relay.actor', host: null })).toBeTruthy();
});
it('should return true for any username with a dot', () => {
2024-10-07 15:45:58 +00:00
expect(isSystemAccount({ username: 'some.user', host: null })).toBeTruthy();
expect(isSystemAccount({ username: 'some.', host: null })).toBeTruthy();
expect(isSystemAccount({ username: '.user', host: null })).toBeTruthy();
expect(isSystemAccount({ username: '.', host: null })).toBeTruthy();
});
it('should return true for usernames with multiple dots', () => {
2024-10-07 15:45:58 +00:00
expect(isSystemAccount({ username: 'some.user.account', host: null })).toBeTruthy();
expect(isSystemAccount({ username: '..', host: null })).toBeTruthy();
});
it('should return false for usernames without a dot', () => {
2024-10-07 15:45:58 +00:00
expect(isSystemAccount({ username: 'instance_actor', host: null })).toBeFalsy();
expect(isSystemAccount({ username: 'instanceactor', host: null })).toBeFalsy();
expect(isSystemAccount({ username: 'relay_actor', host: null })).toBeFalsy();
expect(isSystemAccount({ username: 'relayactor', host: null })).toBeFalsy();
expect(isSystemAccount({ username: '', host: null })).toBeFalsy();
});
it('should return false for users from another instance', () => {
expect(isSystemAccount({ username: 'instance.actor', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: 'relay.actor', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: 'some.user', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: 'some.', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: '.user', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: '.', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: 'some.user.account', host: 'example.com' })).toBeFalsy();
expect(isSystemAccount({ username: '..', host: 'example.com' })).toBeFalsy();
});
});