auth-security-email.test.ts32 lines · main
1import { describe, expect, test } from 'bun:test';
2
3import { checkEmailGate, normalizeEmail } from './auth-security.js';
4
5describe('normalizeEmail', () => {
6 test('lowercases and trims', () => {
7 expect(normalizeEmail(' Foo@Example.COM ')).toBe('foo@example.com');
8 });
9
10 test('gmail dots + plus aliases collapse', () => {
11 expect(normalizeEmail('a.b.c+promo@gmail.com')).toBe('abc@gmail.com');
12 expect(normalizeEmail('abc@gmail.com')).toBe('abc@gmail.com');
13 expect(normalizeEmail('A.B.C@googlemail.com')).toBe('abc@gmail.com');
14 });
15
16 test('non-gmail keeps dots and plus', () => {
17 expect(normalizeEmail('a.b+x@company.com')).toBe('a.b+x@company.com');
18 });
19});
20
21describe('checkEmailGate + gmail normalize', () => {
22 test('blocklist on gmail domain still catches plus aliases', () => {
23 const gate = checkEmailGate('evil+tag@gmail.com', {
24 allowedDomains: [],
25 blockedDomains: ['gmail.com'],
26 blockDisposable: false,
27 blockSubaddresses: false,
28 });
29 // domain check uses normalized domain gmail.com
30 expect(gate.allowed).toBe(false);
31 });
32});