dradis-projects 5.2.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,175 +0,0 @@
1
- # Run the spec in CE/Pro context with:
2
- # rspec <relative path to dradis-projects>/spec/lib/dradis/plugins/projects/upload/v4/template_spec.rb
3
-
4
- require 'rails_helper'
5
-
6
- describe 'Dradis::Plugins::Projects::Upload::V4::Template::Importer' do
7
- let(:project) { create(:project) }
8
- let(:user) { create(:user) }
9
- let(:importer_class) { Dradis::Plugins::Projects::Upload::Template }
10
- let(:importer) do
11
- importer_class::Importer.new(
12
- default_user_id: user.id,
13
- plugin: importer_class,
14
- project_id: project.id
15
- )
16
- end
17
-
18
- context 'uploading a template with attachments url' do
19
- let(:file_path) do
20
- File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files', 'attachments_url.xml')
21
- end
22
-
23
- it 'converts the urls' do
24
- importer.import(file: file_path)
25
-
26
- p_id = project.id
27
- n_id = project.plugin_uploads_node.id
28
-
29
- expect(project.issues.first.text).to include(
30
- "!/pro/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
31
- "!/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
32
- "!/pro/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
33
- "!/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!"
34
- )
35
- end
36
- end
37
-
38
- context 'uploading a template malformed paths as ids' do
39
- let(:file_path) do
40
- File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files', 'malformed_ids.xml')
41
- end
42
-
43
- it 'returns false' do
44
- expect(importer.import(file: file_path)).to be false
45
- end
46
- end
47
-
48
- context 'uploading a template with attachment but missing node' do
49
- let(:file_path) do
50
- File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files', 'missing_node.xml')
51
- end
52
-
53
- it 'does not modify the attachment' do
54
- logger = double('logger')
55
- allow(logger).to receive_messages(debug: nil, error: nil, fatal: nil, info: nil)
56
- expect(logger).to receive(:error).once
57
-
58
- importer = importer_class::Importer.new(
59
- default_user_id: user.id,
60
- logger: logger,
61
- plugin: importer_class,
62
- project_id: project.id
63
- )
64
-
65
- importer.import(file: file_path)
66
-
67
- expect(project.issues.first.text).to include(
68
- "!/pro/projects/222/nodes/12345/attachments/hello.jpg!"
69
- )
70
- end
71
- end
72
-
73
- context 'uploading a template with comments' do
74
- let(:file_path) do
75
- File.join(
76
- File.dirname(__FILE__),
77
- '../../../../../../',
78
- 'fixtures',
79
- 'files',
80
- 'with_comments.xml'
81
- )
82
- end
83
-
84
- before do
85
- importer.import(file: file_path)
86
- end
87
-
88
- let(:node) { project.nodes.find_by(label: 'Node 1') }
89
-
90
- it 'imports comments in issues' do
91
- issue = project.issues.first
92
- expect(issue.comments.first.content).to include('A comment on an issue')
93
- end
94
-
95
- it 'imports comments in notes' do
96
- note = node.notes.first
97
- expect(note.comments.first.content).to include('A comment on a note')
98
- end
99
-
100
- it 'imports comments in evidence' do
101
- evidence = node.evidence.first
102
- expect(evidence.comments.first.content).to include('A comment on an evidence')
103
- end
104
-
105
- it 'imports comments without user' do
106
- issue = project.issues.first
107
- note = node.notes.first
108
- evidence = node.evidence.first
109
-
110
- aggregate_failures do
111
- expect(issue.comments.first.user).to be_nil
112
- expect(note.comments.first.user).to be_nil
113
- expect(evidence.comments.first.user).to be_nil
114
- end
115
- end
116
- end
117
-
118
-
119
- describe 'states' do
120
- let(:dir) do
121
- File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files')
122
- end
123
-
124
- context 'uploading a template without states' do
125
- it 'imports issues with the published state' do
126
- importer.import(file: File.join(dir, 'with_comments.xml'))
127
- issue = project.issues.first
128
- expect(issue.state).to eq('published')
129
- end
130
- end
131
-
132
- context 'uploading a template with states' do
133
- context 'valid states' do
134
- it 'imports issues with states from the template' do
135
- importer.import(file: File.join(dir, 'with_states.xml'))
136
- issue = project.issues.first
137
- expect(issue.state).to eq('ready_for_review')
138
- end
139
- end
140
-
141
- context 'invalid states' do
142
- it 'does not import the issue' do
143
- importer.import(file: File.join(dir, 'with_invalid_states.xml'))
144
- expect(project.issues.count).to eq(0)
145
- end
146
- end
147
- end
148
- end
149
-
150
- describe 'tags' do
151
- let(:file_path) do
152
- File.join(
153
- File.dirname(__FILE__),
154
- '../../../../../../',
155
- 'fixtures',
156
- 'files',
157
- 'with_tags.xml'
158
- )
159
- end
160
-
161
- it 'updates project tags according to the order in the template' do
162
- importer.import(file: file_path)
163
-
164
- tag_values = project.tags.pluck(:name, :position)
165
- expected_values = [
166
- ["!2ca02c_info", 1],
167
- ["!ff7f0e_medium", 2],
168
- ["!d62728_high", 3],
169
- ["!6baed6_low", 4],
170
- ["!9467bd_critical", 5]
171
- ]
172
- expect(tag_values).to eq(expected_values)
173
- end
174
- end
175
- end