<commit_before>const frisby = require('frisby')
const Joi = frisby.Joi
const insecurity = require('../../lib/insecurity')

const API_URL = 'http://localhost:3000/b2b/v2/orders'

const authHeader = { 'Authorization': 'Bearer ' + insecurity.authorize(), 'content-type': 'application/json' }

describe('/b2b/v2/orders', () => {
  it('POST endless loop exploit in "orderLinesData" will raise explicit error', done => {
    frisby.post(API_URL, {
      headers: authHeader,
      body: {
        orderLinesData: '(function dos() { while(true); })()'
      }
    })
      .expect('status', 500)
      .expect('bodyContains', 'Infinite loop detected - reached max iterations')
      .done(done)
  })

  it('POST busy spinning regex attack does not raise an error', done => {
    frisby.post(API_URL, {
      headers: authHeader,
      body: {
        orderLinesData: '/((a+)+)b/.test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa")'
      }
    })
      .expect('status', 503)
      .done(done)
  })

  it('POST sandbox breakout attack does not kill the server', done => {
    frisby.post(API_URL, {
      headers: authHeader,
      body: {
        orderLinesData: 'this.constructor.constructor("return process")().exit()'
      }
    })
      .expect('status', 200)
      .done(done)
  })
<commit_msg>Fix API test to reflect new error handling<commit_after>const frisby = require('frisby')
const Joi = frisby.Joi
const insecurity = require('../../lib/insecurity')

const API_URL = 'http://localhost:3000/b2b/v2/orders'

const authHeader = { 'Authorization': 'Bearer ' + insecurity.authorize(), 'content-type': 'application/json' }

describe('/b2b/v2/orders', () => {
  it('POST endless loop exploit in "orderLinesData" will raise explicit error', done => {
    frisby.post(API_URL, {
      headers: authHeader,
      body: {
        orderLinesData: '(function dos() { while(true); })()'
      }
    })
      .expect('status', 500)
      .expect('bodyContains', 'Infinite loop detected - reached max iterations')
      .done(done)
  })

  it('POST busy spinning regex attack does not raise an error', done => {
    frisby.post(API_URL, {
      headers: authHeader,
      body: {
        orderLinesData: '/((a+)+)b/.test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa")'
      }
    })
      .expect('status', 503)
      .done(done)
  })

  it('POST sandbox breakout attack in "orderLinesData" will raise explicit error', done => {
    frisby.post(API_URL, {
      headers: authHeader,
      body: {
        orderLinesData: 'this.constructor.constructor("return process")().exit()'
      }
    })
      .expect('status', 500)
      .expect('bodyContains', 'Cannot read property \'constructor\' of undefined')
      .done(done)
  })

{'fraction_non_alphanumeric': 0.15818789454140364, 'fraction_numerical': 0.012625324916450055, 'mean_word_length': 3.0269058295964126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4005462', 'n_tokens_mistral': 876, 'n_tokens_neox': 838, 'n_words': 194}