<commit_before>import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
import nJwt from 'njwt';
import Boom from 'boom';
import pkg from '../../package.json';
import {register, scheme} from '../../src/scheme';

suite('stormpath scheme', () => {
  let sandbox;

  setup(() => {
    sandbox = sinon.sandbox.create();
  });

  teardown(() => sandbox.restore());

  test('that the plugin is defined', () => {
    assert.deepEqual(register.attributes, {pkg});
  });

  test('that an authentication scheme is registered for stormpath', () => {
    const next = sinon.spy();
    const schemeSpy = sinon.spy();

    register({auth: {scheme: schemeSpy}}, null, next);

    assert.calledWith(schemeSpy, 'stormpath', scheme);
    assert.calledOnce(next);
  });

  // suite('options validation', () => {
  //   test('that an error is thrown if no options are provided', () => {
  //     assert.throws(() => scheme(), '"value" is required');
  //   });
  //
  //   test('that an error is thrown if the application href is not provided', () => {
  //     assert.throws(() => scheme(null, {}), 'child "applicationHref" fails because ["applicationHref" is required]');
  //   });
  //
  //   test('that an error is thrown if the application href is not a url', () => {
  //     assert.throws(() => scheme(null, {
  //       applicationHref: any.string()
  //     }), 'child "applicationHref" fails because ["applicationHref" must be a valid uri]');
  //   });
  //
  //   test('that an error is thrown if the api key id is not provided', () => {
  //     assert.throws(() => scheme(null, {
  //       applicationHref: any.url()
  //     }), 'child "apiKeyId" fails because ["apiKeyId" is required]');
  //   });
  //
  //   test('that an error is thrown if the api key secret is not provided', () => {
  //     assert.throws(() => scheme(null, {
  //       applicationHref: any.url(),
  //       apiKeyId: any.string()
  //     }), 'child "apiKeySecret" fails because ["apiKeySecret" is required]');
  //   });
  //
  //   test('that an error is thrown if the return url is not provided', () => {
  //     assert.throws(() => scheme(null, {
  //       applicationHref: any.url(),
  //       apiKeyId: any.string(),
  //       apiKeySecret: any.string()
  //     }), 'child "returnUrl" fails because ["returnUrl" is required]');
  //   });
  //
  //   test('that an error is thrown if the application href is not a url', () => {
  //     assert.throws(() => scheme(null, {
  //       applicationHref: any.url(),
  //       apiKeyId: any.string(),
  //       apiKeySecret: any.string(),
  //       returnUrl: any.string()
  //     }), 'child "returnUrl" fails because ["returnUrl" must be a valid uri]');
  //   });
  // });

  suite('direct user to ID Site', () => {
    setup(() => sandbox.stub(nJwt, 'create'));

    test('that the request is redirected to ID Site', () => {
      const redirect = sinon.spy();
      const cont = sinon.spy();
      const compact = sinon.stub();
      const compactedJwt = any.word();
      const next = any.string();
      const options = {
        applicationHref: any.url(),
        apiKeyId: any.string(),
        apiKeySecret: any.string(),
        returnUrl: any.url()
      };
      nJwt.create.withArgs({
        iss: options.apiKeyId,
        sub: options.applicationHref,
        cb_uri: options.returnUrl,
        state: JSON.stringify({next})
      }, options.apiKeySecret).returns({compact});
      compact.returns(compactedJwt);<commit_msg>test(joi): re-enabled the tests for the validation of the options<commit_after>import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
import nJwt from 'njwt';
import Boom from 'boom';
import pkg from '../../package.json';
import {register, scheme} from '../../src/scheme';

suite('stormpath scheme', () => {
  let sandbox;

  setup(() => {
    sandbox = sinon.sandbox.create();
  });

  teardown(() => sandbox.restore());

  test('that the plugin is defined', () => {
    assert.deepEqual(register.attributes, {pkg});
  });

  test('that an authentication scheme is registered for stormpath', () => {
    const next = sinon.spy();
    const schemeSpy = sinon.spy();

    register({auth: {scheme: schemeSpy}}, null, next);

    assert.calledWith(schemeSpy, 'stormpath', scheme);
    assert.calledOnce(next);
  });

  suite('options validation', () => {
    test('that an error is thrown if no options are provided', () => {
      assert.throws(() => scheme(), '"value" is required');
    });

    test('that an error is thrown if the application href is not provided', () => {
      assert.throws(() => scheme(null, {}), 'child "applicationHref" fails because ["applicationHref" is required]');
    });

    test('that an error is thrown if the application href is not a url', () => {
      assert.throws(() => scheme(null, {
        applicationHref: any.string()
      }), 'child "applicationHref" fails because ["applicationHref" must be a valid uri]');
    });

    test('that an error is thrown if the api key id is not provided', () => {
      assert.throws(() => scheme(null, {
        applicationHref: any.url()
      }), 'child "apiKeyId" fails because ["apiKeyId" is required]');
    });

    test('that an error is thrown if the api key secret is not provided', () => {
      assert.throws(() => scheme(null, {
        applicationHref: any.url(),
        apiKeyId: any.string()
      }), 'child "apiKeySecret" fails because ["apiKeySecret" is required]');
    });

    test('that an error is thrown if the return url is not provided', () => {
      assert.throws(() => scheme(null, {
        applicationHref: any.url(),
        apiKeyId: any.string(),
        apiKeySecret: any.string()
      }), 'child "returnUrl" fails because ["returnUrl" is required]');
    });

    test('that an error is thrown if the application href is not a url', () => {
      assert.throws(() => scheme(null, {
        applicationHref: any.url(),
        apiKeyId: any.string(),
        apiKeySecret: any.string(),
        returnUrl: any.string()
      }), 'child "returnUrl" fails because ["returnUrl" must be a valid uri]');
    });
  });

  suite('direct user to ID Site', () => {
    setup(() => sandbox.stub(nJwt, 'create'));

    test('that the request is redirected to ID Site', () => {
      const redirect = sinon.spy();
      const cont = sinon.spy();
      const compact = sinon.stub();
      const compactedJwt = any.word();
      const next = any.string();
      const options = {
        applicationHref: any.url(),
        apiKeyId: any.string(),
        apiKeySecret: any.string(),
        returnUrl: any.url()
      };
      nJwt.create.withArgs({
        iss: options.apiKeyId,
        sub: options.applicationHref,
        cb_uri: options.returnUrl,
        state: JSON.stringify({next})
      }, options.apiKeySecret).returns({compact});
      compact.returns(compactedJwt);
{'fraction_non_alphanumeric': 0.17266811279826463, 'fraction_numerical': 0.0, 'mean_word_length': 2.7222820236813776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, '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': '2610565', 'n_tokens_mistral': 2078, 'n_tokens_neox': 2053, 'n_words': 598}