<commit_before>require 'spec_helper'

describe 'User signs in via shibboleth' do
  subject { page }
  before(:all) {
    @attrs = FactoryGirl.attributes_for(:user, :email => "<EMAIL>")
  }

  context "for the first time when the flag `shib_always_new_account` is set" do
    before {
      enable_shib
      Site.current.update_attributes :shib_always_new_account => true

      setup_shib @attrs[:_full_name], @attrs[:email], @attrs[:email]

      visit shibboleth_path
    }

    it { current_path.should eq(my_home_path) }
    it { should have_content @attrs[:_full_name] }
    it { should have_content @attrs[:email] }
  end

  context "for the first time when the flag `shib_always_new_account` is not set" do
    before {
      enable_shib
      setup_shib @attrs[:_full_name], @attrs[:email], @attrs[:email]
      visit shibboleth_path
    }

    it { current_path.should eq(shibboleth_path) }

    it { should have_content t('shibboleth.associate.existent_account.title') }
    it { should have_button t('shibboleth.associate.existent_account.link_to_this_account') }

    it { should have_content t('shibboleth.associate.new_account.title') }
    it { should have_button t('shibboleth.associate.new_account.create_new_account') }

    context 'and the user wants a new account' do
      before { click_button t('shibboleth.associate.new_account.create_new_account') }

      it { current_path.should eq(my_home_path) }
      it { should have_content @attrs[:_full_name] }
      it { should have_content @attrs[:email] }
    end

    context 'and the user already has another account' do
      context 'and enters valid credentials' do
        let(:user) { FactoryGirl.create(:user) }
        before {
          fill_in 'user[login]', :with => user.username
          fill_in 'user[password]', :with => <PASSWORD>
          click_button t('shibboleth.associate.existent_account.link_to_this_account')
        }

        it { current_path.should eq(my_home_path) }
        it { should have_content user._full_name }
        it { should have_content user.email }
      end

      context "the user enters the wrong credentials in the association page" do
        before { click_button t('shibboleth.associate.existent_account.link_to_this_account') }

        it { has_failure_message }
        it { current_path.should eq(shibboleth_path) }
      end
    end

  end

  context "redirects the user properly" do
    let!(:login_link) { t('devise.shared.links.login.federation') }
    before {
      enable_shib
      Site.current.update_attributes :shib_always_new_account => true
      setup_shib 'a full name', '<EMAIL>', '<EMAIL>'
    }

    context "when he was in the frontpage" do
      before {
        visit root_url
        click_link login_link
      }

      it { current_path.should eq(my_home_path) }
    end

    context "from a space's page" do
      before {
        @space = FactoryGirl.create(:space, :public => true)
        visit space_path(@space)

        # Access sign in path via link
        find("a[href='#{login_path}']").click

        click_link login_link
      }

      it { current_path.should eq(space_path(@space)) }
    end

    context "from the association page" do
      skip
      # the user was in the shibboleth association page "/secure/associate"
      # he user clicks to go to the login page
      # when the user clicks to sign in via shibboleth redirects the user to the association page
      # user clicks to create a new account
      # redirects the user to the space's page
    end
  end
end
<commit_msg>Small additions to shib tests so that they pass with institutions<commit_after>require 'spec_helper'

describe 'User signs in via shibboleth' do
  subject { page }
  before(:all) {
    @institution = FactoryGirl.create(:institution)
    @attrs = FactoryGirl.attributes_for(:user, :email => "<EMAIL>@#{<EMAIL>}")
  }

  context "for the first time when the flag `shib_always_new_account` is set" do
    before {
      enable_shib
      Site.current.update_attributes :shib_always_new_account => true

      setup_shib @attrs[:_full_name], @attrs[:email], @attrs[:email]

      visit shibboleth_path
    }

    it { current_path.should eq(my_home_path) }
    it { should have_content @attrs[:_full_name] }
    it { should have_content @attrs[:email] }
  end

  context "for the first time when the flag `shib_always_new_account` is not set" do
    before {
      enable_shib
      setup_shib @attrs[:_full_name], @attrs[:email], @attrs[:email]
      visit shibboleth_path
    }

    it { current_path.should eq(shibboleth_path) }

    it { should have_content t('shibboleth.associate.existent_account.title') }
    it { should have_button t('shibboleth.associate.existent_account.link_to_this_account') }

    it { should have_content t('shibboleth.associate.new_account.title') }
    it { should have_button t('shibboleth.associate.new_account.create_new_account') }

    context 'and the user wants a new account' do
      before { click_button t('shibboleth.associate.new_account.create_new_account') }

      it { current_path.should eq(my_home_path) }
      it { should have_content @attrs[:_full_name] }
      it { should have_content @attrs[:email] }
    end

    context 'and the user already has another account' do
      context 'and enters valid credentials' do
        let(:user) { FactoryGirl.create(:user) }
        before {
          fill_in 'user[login]', :with => user.username
          fill_in 'user[password]', :with => <PASSWORD>
          click_button t('shibboleth.associate.existent_account.link_to_this_account')
        }

        it { current_path.should eq(my_home_path) }
        it { should have_content user._full_name }
        it { should have_content user.email }
      end

      context "the user enters the wrong credentials in the association page" do
        before { click_button t('shibboleth.associate.existent_account.link_to_this_account') }

        it { has_failure_message }
        it { current_path.should eq(shibboleth_path) }
      end
    end

  end

  context "redirects the user properly" do
    let!(:login_link) { t('devise.shared.links.login.federation') }
    before {
      enable_shib
      Site.current.update_attributes :shib_always_new_account => true
      setup_shib 'a full name', "<EMAIL>@#{<EMAIL>}", "<EMAIL>@#{<EMAIL>}"
    }

    context "when he was in the frontpage" do
      before {
        visit root_url
        click_link t('frontpage.show.login.click_here') # federation login link
      }

      it { current_path.should eq(my_home_path) }
    end

    context "from a space's page" do
      before {
        @space = FactoryGirl.create(:space, :public => true)
        visit space_path(@space)

        # Access sign in path via link
        find("a[href='#{login_path}']").click

        click_link login_link
      }

      it { current_path.should eq(space_path(@space)) }
    end

    context "from the association page" do
      skip
      # the user was in the shibboleth association page "/secure/associate"
      # he user clicks to go to the login page
      # when the user clicks to sign in via shibboleth redirects the user to the association page
      # user clicks to create a new account
      # redirects the user to the space's page
    end
  end
end

{'fraction_non_alphanumeric': 0.09330961827883431, 'fraction_numerical': 0.0, 'mean_word_length': 2.99890590809628, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 26, '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': '6952077', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2257, 'n_words': 611}