summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/2_plan/issue/check_mentions_for_xss_spec.rb
blob: 784f474a7d5c81f5f5a66404e1969bf61c83496e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module QA
  RSpec.describe 'Plan', :reliable do
    describe 'check xss occurence in @mentions in issues', :requires_admin do
      it 'mentions a user in a comment' do
        QA::Runtime::Env.personal_access_token = QA::Runtime::Env.admin_personal_access_token

        unless QA::Runtime::Env.personal_access_token
          Flow::Login.sign_in_as_admin
        end

        user = Resource::User.fabricate_via_api! do |user|
          user.name = "eve <img src=x onerror=alert(2)&lt;img src=x onerror=alert(1)&gt;"
          user.password = "test1234"
        end

        QA::Runtime::Env.personal_access_token = nil

        Page::Main::Menu.perform(&:sign_out) if Page::Main::Menu.perform { |p| p.has_personal_area?(wait: 0) }

        Flow::Login.sign_in

        project = Resource::Project.fabricate_via_api! do |project|
          project.name = 'xss-test-for-mentions-project'
        end

        Flow::Project.add_member(project: project, username: user.username)

        Resource::Issue.fabricate_via_api! do |issue|
          issue.project = project
        end.visit!

        Page::Project::Issue::Show.perform do |show|
          show.select_all_activities_filter
          show.comment("cc-ing you here @#{user.username}")

          expect do
            expect(show).to have_comment("cc-ing you here")
          end.not_to raise_error # Selenium::WebDriver::Error::UnhandledAlertError
        end
      end
    end
  end
end