issue_detail_spec.rb 1.58 KB
Newer Older
1
2
require 'rails_helper'

3
describe 'Issue Detail', :js do
4
5
6
  let(:user)     { create(:user) }
  let(:project)  { create(:project, :public) }
  let(:issue)    { create(:issue, project: project, author: user) }
7
8
9
10
11
12
13
14
15
16
17
18
19
20

  context 'when user displays the issue' do
    before do
      visit project_issue_path(project, issue)
      wait_for_requests
    end

    it 'shows the issue' do
      page.within('.issuable-details') do
        expect(find('h2')).to have_content(issue.title)
      end
    end
  end

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  context 'when issue description has xss snippet' do
    before do
      issue.update!(description: '![xss" onload=alert(1);//](a)')
      sign_in(user)
      visit project_issue_path(project, issue)
      wait_for_requests
    end

    it 'should encode the description to prevent xss issues' do
      page.within('.issuable-details .detail-page-description') do
        expect(page).to have_selector('img', count: 1)
        expect(find('img')['onerror']).to be_nil
        expect(find('img')['src']).to end_with('/a')
      end
    end
  end

38
39
40
41
42
43
  context 'when edited by a user who is later deleted' do
    before do
      sign_in(user)
      visit project_issue_path(project, issue)
      wait_for_requests

44
      page.find('.js-issuable-edit').click
45
      fill_in 'issuable-title', with: 'issue title'
46
      click_button 'Save'
47
      wait_for_requests
48

49
      Users::DestroyService.new(user).execute(user)
50
51
52
53
54
55
56
57
58
59
60

      visit project_issue_path(project, issue)
    end

    it 'shows the issue' do
      page.within('.issuable-details') do
        expect(find('h2')).to have_content(issue.reload.title)
      end
    end
  end
end