<commit_before># encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/common')

describe "profile" do
  include_context "in-process server selenium tests"

  def click_edit
    f('.edit_settings_link').click
    edit_form = f('#update_profile_form')
    keep_trying_until { expect(edit_form).to be_displayed }
    edit_form
  end

  def add_skype_service
    f('#unregistered_service_skype > a').click
    skype_dialog = f('#unregistered_service_skype_dialog')
    skype_dialog.find_element(:id, 'skype_user_service_user_name').send_keys("jakesorce")
    submit_dialog(skype_dialog, '.btn')
    wait_for_ajaximations
    expect(f('#registered_services')).to include_text("Skype")
  end

  def generate_access_token(purpose = 'testing', close_dialog = false)
    f('.add_access_token_link').click
    access_token_form = f('#access_token_form')
    access_token_form.find_element(:id, 'access_token_purpose').send_keys(purpose)
    submit_form(access_token_form)
    wait_for_ajax_requests
    details_dialog = f('#token_details_dialog')
    expect(details_dialog).to be_displayed
    if close_dialog
      close_visible_dialog
    end
  end

  it "should give error - wrong old password" do
    user_with_pseudonym({:active_user => true})
    create_session(@pseudonym)
    get '/profile/settings'
    wrong_old_password = '<PASSWORD>'
    new_password = '<PASSWORD>'
    edit_form = click_edit
    edit_form.find_element(:id, 'change_password_checkbox').click
    edit_form.find_element(:id, 'old_password').send_keys(<PASSWORD>)
    edit_form.find_element(:id, 'pseudonym_password').send_keys(<PASSWORD>)
    edit_form.find_element(:id, 'pseudonym_password_confirmation').send_keys(<PASSWORD>)
    submit_form(edit_form)
    wait_for_ajaximations
    # check to see if error box popped up
    errorboxes = ff('.error_text')
    expect(errorboxes.length).to be > 1
    expect(errorboxes.any? { |errorbox| errorbox.text =~ /Invalid old password for the login/ }).to be_truthy
  end

  it "should change the password" do
    user_with_pseudonym({:active_user => true})
    create_session(@pseudonym)
    get '/profile/settings'
    old_password = '<PASSWORD>'
    new_password = '<PASSWORD>'
    edit_form = click_edit
    edit_form.find_element(:id, 'change_password_checkbox').click
    edit_form.find_element(:id, 'old_password').send_keys(<PASSWORD>)
    edit_form.find_element(:id, 'pseudonym_password').send_keys(<PASSWORD>)
    edit_form.find_element(:id, 'pseudonym_password_confirmation').send_keys(<PASSWORD>)
    submit_form(edit_form)
    wait_for_ajaximations
    #login with new password
    expect(@pseudonym.reload).to be_valid_password(<PASSWORD>)
  end

  context "non password tests" do

    before (:each) do
      course_with_teacher_logged_in
    end
<commit_msg>spec: 840136, 1055503 limit password size 6 to 255 chars<commit_after># encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/common')

describe "profile" do
  include_context "in-process server selenium tests"

  def click_edit
    f('.edit_settings_link').click
    edit_form = f('#update_profile_form')
    keep_trying_until { expect(edit_form).to be_displayed }
    edit_form
  end

  def add_skype_service
    f('#unregistered_service_skype > a').click
    skype_dialog = f('#unregistered_service_skype_dialog')
    skype_dialog.find_element(:id, 'skype_user_service_user_name').send_keys("<PASSWORD>orce")
    submit_dialog(skype_dialog, '.btn')
    wait_for_ajaximations
    expect(f('#registered_services')).to include_text("Skype")
  end

  def generate_access_token(purpose = 'testing', close_dialog = false)
    f('.add_access_token_link').click
    access_token_form = f('#access_token_form')
    access_token_form.find_element(:id, 'access_token_purpose').send_keys(purpose)
    submit_form(access_token_form)
    wait_for_ajax_requests
    details_dialog = f('#token_details_dialog')
    expect(details_dialog).to be_displayed
    if close_dialog
      close_visible_dialog
    end
  end

  def log_in_to_settings
    user_with_pseudonym({active_user: true})
    create_session(@pseudonym)
    get '/profile/settings'
  end

  def change_password(old_password, <PASSWORD>)
    edit_form = click_edit
    edit_form.find_element(:id, 'change_password_checkbox').click
    edit_form.find_element(:id, 'old_password').send_keys(<PASSWORD>)
    edit_form.find_element(:id, 'pseudonym_password').send_keys(<PASSWORD>)
    edit_form.find_element(:id, 'pseudonym_password_confirmation').send_keys(<PASSWORD>)
    submit_form(edit_form)
    wait_for_ajaximations
  end

  it "should give error - wrong old password" do
    log_in_to_settings
    change_password('<PASSWORD>', '<PASSWORD>')
    # check to see if error box popped up
    errorboxes = ff('.error_text')
    expect(errorboxes.length).to be > 1
    expect(errorboxes.any? { |errorbox| errorbox.text =~ /Invalid old password for the login/ }).to be_truthy
  end

  it "should change the password" do
    log_in_to_settings
    change_password('<PASSWORD>', '<PASSWORD>')
    # login with new password
    expect(@pseudonym.reload).to be_valid_password('<PASSWORD>')
  end

  it "rejects passwords longer than 255 characters", priority: "2", test_id: 840136 do
    log_in_to_settings
    change_password('<PASSWORD>', SecureRandom.hex(128))
    errorboxes = ff('.error_text')
    expect(errorboxes.any? { |errorbox| errorbox.text =~ /Can't exceed 255 characters/ }).to be_truthy
  end

  it "rejects passwords shorter than 6 characters", priority: "2", test_id: 1055503 do
    log_in_to_settings
    change_password('<PASSWORD>', SecureRandom.hex(2))
    errorboxes = ff('.error_text')
    expect(errorboxes.any? { |errorbox| errorbox.text =~ /Must be at least 6 characters/ }).to be_truthy
  end

  context "non password tests" do

    before(:each) do
      course_with_teacher_logged_in
    end

{'fraction_non_alphanumeric': 0.10976855003403677, 'fraction_numerical': 0.008168822328114363, 'mean_word_length': 4.733658536585366, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 32, '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': '6861765', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1878, 'n_words': 366}