37 lines
1.7 KiB
TypeScript
37 lines
1.7 KiB
TypeScript
|
|
import { describe, it, expect } from 'vitest';
|
||
|
|
import { isSameOrigin } from '../../src/lib/sameOrigin.js';
|
||
|
|
|
||
|
|
describe('isSameOrigin — origin requesta vs nagłówek Origin', () => {
|
||
|
|
it('ten sam scheme+host+port to same-origin', () => {
|
||
|
|
expect(isSameOrigin('http://192.168.50.127:13001', 'http', '192.168.50.127:13001')).toBe(true);
|
||
|
|
expect(isSameOrigin('https://tisachi.ddns.net', 'https', 'tisachi.ddns.net')).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('domyślny port jest niewidoczny po jednej stronie', () => {
|
||
|
|
expect(isSameOrigin('http://api.example.test:80', 'http', 'api.example.test')).toBe(true);
|
||
|
|
expect(isSameOrigin('http://api.example.test', 'http', 'api.example.test:80')).toBe(true);
|
||
|
|
expect(isSameOrigin('https://api.example.test:443', 'https', 'api.example.test')).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('wielkość liter hosta nie ma znaczenia', () => {
|
||
|
|
expect(isSameOrigin('http://Api.Example.Test:13001', 'http', 'api.example.test:13001')).toBe(
|
||
|
|
true,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('inny port / inny scheme / inny host to cross-origin', () => {
|
||
|
|
expect(isSameOrigin('http://192.168.50.127:13001', 'http', '192.168.50.127:13000')).toBe(false);
|
||
|
|
expect(isSameOrigin('http://192.168.50.127:13001', 'https', '192.168.50.127:13001')).toBe(
|
||
|
|
false,
|
||
|
|
);
|
||
|
|
expect(isSameOrigin('http://obcy.example.test', 'http', 'api.example.test')).toBe(false);
|
||
|
|
// https:80 nie jest "domyślnym portem" — inny origin
|
||
|
|
expect(isSameOrigin('https://api.example.test:80', 'https', 'api.example.test')).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('wartość nieparująca originu to zawsze false', () => {
|
||
|
|
expect(isSameOrigin('null', 'http', 'api.example.test')).toBe(false);
|
||
|
|
expect(isSameOrigin('http://', 'http', 'api.example.test')).toBe(false);
|
||
|
|
});
|
||
|
|
});
|