<commit_before>require "spec_helper"

describe "Data Access workflow", reset: false do
  downloadable_dataset_id = 'C179003030-ORNL_DAAC'
  downloadable_dataset_title = '15 Minute Stream Flow Data: USGS (FIFE)'

  non_downloadable_dataset_id = 'C179001887-SEDAC'
  non_downloadable_dataset_title = '2000 Pilot Environmental Sustainability Index (ESI)'

  context "when a malicious user attempts an XSS attack using the data access back link" do
    before(:each) do
      load_page :root
      login
      visit "/data/configure?p=!#{downloadable_dataset_id}&back=javascript:alert(%27ohai%27)//"
    end

    it "uses a safe back link" do
      expect(page).to have_link("Back to Search Session")
      expect(page).to have_css("a[href^=\"/search/datasets?p=!#{downloadable_dataset_id}\"]")
    end
  end

  context "when the user is not logged in" do
    before(:each) do
      load_page :search, project: [downloadable_dataset_id, non_downloadable_dataset_id], view: :project
      wait_for_xhr
      click_link "Retrieve project data"
    end

    after :each do
      Capybara.reset_sessions!
    end

    it "forces the user to login before showing data access page" do
      expect(page).to have_content('EOSDIS User Registration System')
    end<commit_msg>Fix spec failure caused by previous spec's session state<commit_after>require "spec_helper"

describe "Data Access workflow", reset: false do
  downloadable_dataset_id = 'C179003030-ORNL_DAAC'
  downloadable_dataset_title = '15 Minute Stream Flow Data: USGS (FIFE)'

  non_downloadable_dataset_id = 'C179001887-SEDAC'
  non_downloadable_dataset_title = '2000 Pilot Environmental Sustainability Index (ESI)'

  context "when a malicious user attempts an XSS attack using the data access back link" do
    before(:each) do
      load_page :root
      login
      visit "/data/configure?p=!#{downloadable_dataset_id}&back=javascript:alert(%27ohai%27)//"
    end

    after :each do
      Capybara.reset_sessions!
    end

    it "uses a safe back link" do
      expect(page).to have_link("Back to Search Session")
      expect(page).to have_css("a[href^=\"/search/datasets?p=!#{downloadable_dataset_id}\"]")
    end
  end

  context "when the user is not logged in" do
    before(:each) do
      load_page :search, project: [downloadable_dataset_id, non_downloadable_dataset_id], view: :project
      wait_for_xhr
      click_link "Retrieve project data"
    end

    after :each do
      Capybara.reset_sessions!
    end

    it "forces the user to login before showing data access page" do
      expect(page).to have_content('EOSDIS User Registration System')
    end
{'fraction_non_alphanumeric': 0.08745247148288973, 'fraction_numerical': 0.02129277566539924, 'mean_word_length': 3.908582089552239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367287', 'n_tokens_mistral': 862, 'n_tokens_neox': 805, 'n_words': 242}