Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.9 KB
Raw Blame
import { describe, expect, it } from 'vitest';

import { isAllowedBillingMailto, isAllowedBillingMailtoRequest } from '../billing.js';

describe('billing mailto policy', () => {
  it('allows localized subject and body for the fixed support inbox', () => {
    expect(
      isAllowedBillingMailto(
        'mailto:[email protected]?subject=Invoice%20request&body=Order%20details',
      ),
    ).toBe(true);
  });

  it.each(['[email protected]', '[email protected]', '[email protected]'])(
    'rejects recipient-affecting %s headers',
    (header) => {
      expect(isAllowedBillingMailto(`mailto:[email protected]?subject=x&${header}`)).toBe(false);
    },
  );

  it('rejects duplicate prefill fields', () => {
    expect(isAllowedBillingMailto('mailto:[email protected]?subject=first&subject=second')).toBe(
      false,
    );
  });

  it('rejects fragments that could be interpreted differently by native mail handlers', () => {
    expect(
      isAllowedBillingMailto('mailto:[email protected]?subject=x#&[email protected]'),
    ).toBe(false);
  });

  it.each(['%0D%0ABcc%3Aattacker%40example.com', '%09Bcc%3Aattacker%40example.com'])
    ('rejects control characters in the subject', (subject) => {
      expect(
        isAllowedBillingMailto(`mailto:[email protected]?subject=${subject}&body=details`),
      ).toBe(false);
    });

  it('rejects alternate recipients and malformed mailto URLs', () => {
    expect(isAllowedBillingMailto('mailto:[email protected]?subject=x')).toBe(false);
    expect(isAllowedBillingMailto('mailto://[email protected]?subject=x')).toBe(false);
    expect(isAllowedBillingMailto('mailto:xd-billing%40xd.com%FF?subject=x')).toBe(false);
  });

  it('requires a trusted sender in addition to the URL policy', () => {
    expect(isAllowedBillingMailtoRequest('mailto:[email protected]?subject=x', false)).toBe(false);
    expect(isAllowedBillingMailtoRequest('mailto:[email protected]?subject=x', true)).toBe(true);
  });
});