<commit_before>require_relative '../spec_helper'
require_relative '../helpers/subdomainless_helper'

require 'fake_net_ldap'
require_relative '../lib/fake_net_ldap_bind_as'

describe SessionsController do
  shared_examples_for 'Google' do
    before(:all) do
      google_plus_config = {
        access_token_field_id: 'atfi',
        iframe_src: '',
        signup_action: '',
        unauthenticated_valid_access_token: ''
      }
      # mocking `:domain` allows lazy loading `user_domain`
      google_plus_config.stubs(:domain).returns { user_domain }
      GooglePlusConfig.stubs(instance: google_plus_config)

      @user = FactoryGirl.create(:carto_user, username: 'google_user')
    end

    after(:all) do
      @user.destroy
    end

    it 'attempts Google authentication if google is enabled and there is a google_access_token param' do
      access_token = '<PASSWORD>'
      GooglePlusAPI.any_instance.stubs(:get_user).with(access_token).once.returns(@user)
      SessionsController.any_instance.expects(:authenticate!).with(:google_access_token, scope: @user.username)
                        .returns(@user).once
      post create_session_url(user_domain: user_domain, google_access_token: access_token)
    end
  end

  describe 'Google authentication' do<commit_msg>Fix username with underscore in sessions controller<commit_after>require_relative '../spec_helper'
require_relative '../helpers/subdomainless_helper'

require 'fake_net_ldap'
require_relative '../lib/fake_net_ldap_bind_as'

describe SessionsController do
  shared_examples_for 'Google' do
    before(:all) do
      google_plus_config = {
        access_token_field_id: 'atfi',
        iframe_src: '',
        signup_action: '',
        unauthenticated_valid_access_token: ''
      }
      # mocking `:domain` allows lazy loading `user_domain`
      google_plus_config.stubs(:domain).returns { user_domain }
      GooglePlusConfig.stubs(instance: google_plus_config)

      @user = FactoryGirl.create(:carto_user, username: 'google-user')
    end

    after(:all) do
      @user.destroy
    end

    it 'attempts Google authentication if google is enabled and there is a google_access_token param' do
      access_token = '<PASSWORD>'
      GooglePlusAPI.any_instance.stubs(:get_user).with(access_token).once.returns(@user)
      SessionsController.any_instance.expects(:authenticate!).with(:google_access_token, scope: @user.username)
                        .returns(@user).once
      post create_session_url(user_domain: user_domain, google_access_token: access_token)
    end
  end

  describe 'Google authentication' do
{'fraction_non_alphanumeric': 0.09470858895705521, 'fraction_numerical': 0.0, 'mean_word_length': 3.7783882783882783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3300945', 'n_tokens_mistral': 784, 'n_tokens_neox': 753, 'n_words': 153}