<commit_before>import connect from 'connect';
import request from 'supertest';
import { IncomingMessage, ServerResponse } from 'http';

import crossdomain = require('..')

describe('crossdomain', () => {
  function app (middleware: ReturnType<typeof crossdomain>) {
    const result = connect();
    result.use(middleware);
    result.use((_req: IncomingMessage, res: ServerResponse) => {
      res.end('Hello world');
    });
    return result;
  }

  it('sets X-Permitted-Cross-Domain-Policies: none when called with no arguments', () => {
    return request(app(crossdomain()))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'none')
      .expect('Hello world');
  });

  it('sets X-Permitted-Cross-Domain-Policies: none when called with an empty object', () => {
    return request(app(crossdomain({})))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'none')
      .expect('Hello world');
  });

  it('can explicitly set the policy to "none"', () => {
    return request(app(crossdomain({ permittedPolicies: 'none' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'none')
      .expect('Hello world');
  });

  it('can set the policy to "master-only"', () => {
    return request(app(crossdomain({ permittedPolicies: 'master-only' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'master-only')
      .expect('Hello world');
  });

  it('can set the policy to "by-content-type"', () => {
    return request(app(crossdomain({ permittedPolicies: 'by-content-type' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'by-content-type')
      .expect('Hello world');
  });

  it('can set the policy to "all"', () => {
    return request(app(crossdomain({ permittedPolicies: 'all' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'all')
      .expect('Hello world');
  });

  it('cannot set the policy to "by-ftp-filename"', () => {
    expect(() => { crossdomain({ permittedPolicies: 'by-ftp-filename' }); }).toThrow();
  });

  it('cannot set the policy to invalid values', () => {
    expect(() => { crossdomain({ permittedPolicies: '' }); }).toThrow();
    expect(() => { crossdomain({ permittedPolicies: 'NONE' }); }).toThrow();
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    expect(() => { crossdomain({ permittedPolicies: null } as any); }).toThrow();
  });

  it('names its function and middleware', () => {
    expect(crossdomain.name).toStrictEqual('crossdomain');
    expect(crossdomain().name).toStrictEqual('crossdomain');
  });
});<commit_msg>Add a test to ensure that String instances are not supported<commit_after>import connect from 'connect';
import request from 'supertest';
import { IncomingMessage, ServerResponse } from 'http';

import crossdomain = require('..')

describe('crossdomain', () => {
  function app (middleware: ReturnType<typeof crossdomain>) {
    const result = connect();
    result.use(middleware);
    result.use((_req: IncomingMessage, res: ServerResponse) => {
      res.end('Hello world');
    });
    return result;
  }

  it('sets X-Permitted-Cross-Domain-Policies: none when called with no arguments', () => {
    return request(app(crossdomain()))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'none')
      .expect('Hello world');
  });

  it('sets X-Permitted-Cross-Domain-Policies: none when called with an empty object', () => {
    return request(app(crossdomain({})))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'none')
      .expect('Hello world');
  });

  it('can explicitly set the policy to "none"', () => {
    return request(app(crossdomain({ permittedPolicies: 'none' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'none')
      .expect('Hello world');
  });

  it('can set the policy to "master-only"', () => {
    return request(app(crossdomain({ permittedPolicies: 'master-only' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'master-only')
      .expect('Hello world');
  });

  it('can set the policy to "by-content-type"', () => {
    return request(app(crossdomain({ permittedPolicies: 'by-content-type' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'by-content-type')
      .expect('Hello world');
  });

  it('can set the policy to "all"', () => {
    return request(app(crossdomain({ permittedPolicies: 'all' })))
      .get('/')
      .expect('X-Permitted-Cross-Domain-Policies', 'all')
      .expect('Hello world');
  });

  it('cannot set the policy to "by-ftp-filename"', () => {
    expect(() => { crossdomain({ permittedPolicies: 'by-ftp-filename' }); }).toThrow();
  });

  it('cannot set the policy to invalid values', () => {
    expect(() => { crossdomain({ permittedPolicies: '' }); }).toThrow();
    expect(() => { crossdomain({ permittedPolicies: 'NONE' }); }).toThrow();
    /* eslint-disable @typescript-eslint/no-explicit-any */
    expect(() => { crossdomain({ permittedPolicies: null } as any); }).toThrow();
    expect(() => { crossdomain({ permittedPolicies: new String('none') } as any); }).toThrow(); // eslint-disable-line no-new-wrappers
    /* eslint-enable @typescript-eslint/no-explicit-any */
  });

  it('names its function and middleware', () => {
    expect(crossdomain.name).toStrictEqual('crossdomain');
    expect(crossdomain().name).toStrictEqual('crossdomain');
  });
});
{'fraction_non_alphanumeric': 0.19772560528246516, 'fraction_numerical': 0.0, 'mean_word_length': 3.636904761904762, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6843456', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1683, 'n_words': 360}