{"size": 1023, "ext": "js", "max_stars_repo_path": "server/filter/origin-whitelist-403.spec.js", "max_stars_repo_name": "Alorel/heroku-cors-proxy", "max_stars_repo_stars_event_min_datetime": "2017-11-04T03:29:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-17T19:57:19.000Z", "max_issues_repo_path": "server/filter/origin-whitelist-403.spec.js", "max_issues_repo_name": "Alorel/heroku-cors-proxy", "max_issues_repo_issues_event_min_datetime": "2017-11-08T23:08:18.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-25T09:45:03.000Z", "max_forks_repo_path": "server/filter/origin-whitelist-403.spec.js", "max_forks_repo_name": "Alorel/heroku-cors-proxy", "max_forks_repo_forks_event_min_datetime": "2017-10-23T17:19:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T21:16:32.000Z"}
{"max_stars_count": 4, "max_issues_count": 24, "max_forks_count": 6, "avg_line_length": 28.4166666667, "max_line_length": 70, "alphanum_fraction": 0.5698924731}
const originalWhitelist = process.env.ORIGIN_WHITELIST;

describe("Origin whitelist filter", () => {
  let app;
  
  before(() => {
    process.env.ORIGIN_WHITELIST = '127.0.0.1,localhost';
    delete require.cache[require.resolve('../conf/origin-whitelist')];
    delete require.cache[require.resolve('./origin-whitelist-403')];
    delete require.cache[require.resolve('../extend-express')];
    
    app = require('../extend-express')();
    app.use(require('./origin-whitelist-403'));
    app.get('/', (req, res) => res.end(''));
  });
  
  after(() => process.env.ORIGIN_WHITELIST = originalWhitelist);
  
  it("Disallowed origin", done => {
    request(app)
      .get('/')
      .set('Origin', 'https://foo.bar')
      .expect(403, 'Origin foo.bar not allowed')
      .end(done);
  });
  
  for (const allow of ['127.0.0.1', 'localhost']) {
    it(`Allow ${allow}`, done => {
      request(app)
        .get('/')
        .set('Origin', `https://${allow}`)
        .expect(200, '')
        .end(done);
    });
  }
});