2026-09-09 21:53:11 +03:30
|
|
|
import { findTenantForHost, scoreTenantHost } from './tenant-host.util';
|
|
|
|
|
|
|
|
|
|
const gholak = {
|
2026-09-09 22:07:40 +03:30
|
|
|
domain: 'app.gholaktala.ir',
|
2026-09-09 21:53:11 +03:30
|
|
|
domains: [],
|
2026-09-09 22:07:40 +03:30
|
|
|
appUrl: 'https://app.gholaktala.ir',
|
|
|
|
|
adminUrl: 'https://k.montzar.ir/admin',
|
2026-09-09 21:53:11 +03:30
|
|
|
nodeServer: 'https://new.gholaktala.ir/server',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const montzar = {
|
|
|
|
|
domain: 'k.montzar.ir',
|
|
|
|
|
domains: ['montzar.ir'],
|
|
|
|
|
appUrl: 'https://k.montzar.ir',
|
|
|
|
|
adminUrl: 'https://k.montzar.ir',
|
|
|
|
|
nodeServer: 'https://new.gholaktala.ir/server',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const otherOnSameBox = {
|
|
|
|
|
domain: 'examplegold.ir',
|
|
|
|
|
domains: [],
|
|
|
|
|
appUrl: 'https://examplegold.ir',
|
|
|
|
|
adminUrl: null,
|
|
|
|
|
nodeServer: 'https://new.gholaktala.ir/server',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
describe('findTenantForHost', () => {
|
2026-09-09 22:07:40 +03:30
|
|
|
const tenants = [gholak, otherOnSameBox, montzar];
|
2026-09-09 21:53:11 +03:30
|
|
|
|
2026-09-09 22:07:40 +03:30
|
|
|
it('hmac does not treat shared adminUrl as gholaktala', () => {
|
|
|
|
|
expect(scoreTenantHost(gholak, 'k.montzar.ir', 'hmac')).toBe(0);
|
|
|
|
|
expect(findTenantForHost(tenants, 'k.montzar.ir', 'hmac')?.domain).toBe(
|
|
|
|
|
'k.montzar.ir',
|
2026-09-09 21:53:11 +03:30
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-09 22:07:40 +03:30
|
|
|
it('hmac without montzar tenant does not fall back to gholak adminUrl', () => {
|
|
|
|
|
expect(
|
|
|
|
|
findTenantForHost([gholak, otherOnSameBox], 'k.montzar.ir', 'hmac'),
|
|
|
|
|
).toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('full get_user still maps k.montzar.ir to montzar by primary domain', () => {
|
2026-09-09 21:53:11 +03:30
|
|
|
expect(findTenantForHost(tenants, 'k.montzar.ir')?.domain).toBe(
|
|
|
|
|
'k.montzar.ir',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-09 22:07:40 +03:30
|
|
|
it('maps new.gholaktala.ir to gholaktala via subdomain, not nodeServer', () => {
|
|
|
|
|
const gholakBare = { ...gholak, domain: 'gholaktala.ir' };
|
|
|
|
|
expect(
|
|
|
|
|
findTenantForHost([montzar, otherOnSameBox, gholakBare], 'new.gholaktala.ir')
|
|
|
|
|
?.domain,
|
|
|
|
|
).toBe('gholaktala.ir');
|
|
|
|
|
expect(scoreTenantHost(gholakBare, 'new.gholaktala.ir')).toBe(75);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-09 21:53:11 +03:30
|
|
|
it('does not pick a random tenant when only nodeServer matches several rows', () => {
|
|
|
|
|
const sharedOnly = [
|
|
|
|
|
{ ...montzar, domain: 'a.ir', domains: [] },
|
|
|
|
|
{ ...gholak, domain: 'b.ir', domains: [] },
|
|
|
|
|
];
|
|
|
|
|
expect(findTenantForHost(sharedOnly, 'new.gholaktala.ir')).toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
});
|