<commit_before>var testUtil = require('../../util');

module.exports = function (oa, pageauths, setup) {
  'use strict';
  var oauth;
  var registeredRedirectURIs = [
    "https://willscott.github.io/freedom-oauth-relay/oauth-relay.html"
  ];
  var clientId = "<KEY>";

  beforeEach(function () {
    setup();
    for (var i=0; i<pageauths.length; i++) {
      pageauths[i].register(oa);
    }
    oauth = testUtil.directProviderFor(oa.provider.bind(oa.provider, {}), testUtil.getApis().get(oa.name).definition);
  });

  afterEach(function () {
    oa.reset();
  });

  it("Generates a token", function (done) {
    var o = oauth();
    o.on('oAuthEvent', function (url) {
      expect(url).toEqual(jasmine.any(String));
      var query = url.substr(url.indexOf('#') + 1);
      var params = {};
      var keys = query.split('&');

      for (var i = 0; i < keys.length; i += 1) {
        var param = keys[i].substr(0, keys[i].indexOf('='));
        params[param] = keys[i].substr(keys[i].indexOf('=') + 1);
      }
      expect(params).toEqual(jasmine.objectContaining({
        access_token: jasmine.any(String)
      }));
      done();
    });

    o.initiateOAuth(registeredRedirectURIs).then(function(obj) {
      var url = "https://accounts.google.com/o/oauth2/auth?" +
        "client_id="+clientId+"&" +
        "response_type=token&" +
        "scope=email%20" + encodeURIComponent("https://www.googleapis.com/auth/userinfo.profile") + "&" +
        "redirect_uri=" + encodeURIComponent(obj.redirect) + "&" +
        "state=" + encodeURIComponent(obj.state);
      console.log(url);
      window.open(url);
    }, function (err) {
      expect(err).toBeUndefined();
    });
  });
  
};<commit_msg>bypass Google in core.oauth integration test by calling redirectURI directly<commit_after>var testUtil = require('../../util');

module.exports = function (oa, pageauths, setup) {
  'use strict';
  var oauth;
  var registeredRedirectURIs = [
    "https://willscott.github.io/freedom-oauth-relay/oauth-relay.html"
  ];
  var clientId = "<KEY>";

  beforeEach(function () {
    setup();
    for (var i=0; i<pageauths.length; i++) {
      pageauths[i].register(oa);
    }
    oauth = testUtil.directProviderFor(oa.provider.bind(oa.provider, {}), testUtil.getApis().get(oa.name).definition);
  });

  afterEach(function () {
    oa.reset();
  });

  it("Generates a token", function (done) {
    var o = oauth();
    o.on('oAuthEvent', function (url) {
      console.log(url);
      expect(url).toEqual(jasmine.any(String));
      var query = url.substr(url.indexOf('#') + 1);
      var params = {};
      var keys = query.split('&');

      for (var i = 0; i < keys.length; i += 1) {
        var param = keys[i].substr(0, keys[i].indexOf('='));
        params[param] = keys[i].substr(keys[i].indexOf('=') + 1);
      }
      expect(params).toEqual(jasmine.objectContaining({
        access_token: jasmine.any(String)
      }));
      done();
    });

    o.initiateOAuth(registeredRedirectURIs).then(function(obj) {
      var url = "https://accounts.google.com/o/oauth2/auth?" +
        "client_id="+clientId+"&" +
        "response_type=token&" +
        "scope=email%20" + encodeURIComponent("https://www.googleapis.com/auth/userinfo.profile") + "&" +
        "redirect_uri=" + encodeURIComponent(obj.redirect) + "&" +
        "state=" + encodeURIComponent(obj.state);
      console.log(url);
      // Cheating a little bit to avoid going through Google. 
      // Just call the redirect URL directly e.g.
      // https://willscott.github.io/freedom-oauth-relay/oauth-relay.html#state=freedom.oauth.redirect.handler0.05948500754311681&access_token=ya29.rADhKXAGx0fJfB0Vx5ibQUSmMvcK9GYVZBLId42Tvn9-aQEBD5HEsbKh-5Kj_D-j09wD5axgoIkadA&token_type=Bearer&expires_in=3600
      window.open(obj.redirect+"#state="+encodeURIComponent(obj.state)+
                  "&access_token=<PASSWORD>");
      //window.open(url);
    }, function (err) {
      expect(err).toBeUndefined();
    });
  });
  
};
{'fraction_non_alphanumeric': 0.1816816816816817, 'fraction_numerical': 0.013513513513513514, 'mean_word_length': 3.0869120654396727, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 7, 'lorem ipsum': 0, 'www.': 2, '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': '4149979', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1392, 'n_words': 205}