dradis-projects 5.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/dradis/plugins/projects/export/package.rb +1 -1
- data/lib/dradis/plugins/projects/export/v4/template.rb +1 -0
- data/lib/dradis/plugins/projects/gem_version.rb +1 -1
- data/lib/dradis/plugins/projects/upload/v4/template.rb +32 -31
- metadata +2 -45
- data/.github/pull_request_template.md +0 -45
- data/.gitignore +0 -12
- data/.ruby-version +0 -1
- data/CHANGELOG.template +0 -12
- data/CONTRIBUTING.md +0 -3
- data/Gemfile +0 -17
- data/dradis-projects.gemspec +0 -29
- data/spec/fixtures/files/attachments_url.xml +0 -15
- data/spec/fixtures/files/invalid_byte_recoverable.xml +0 -19
- data/spec/fixtures/files/malformed_ids.xml +0 -14
- data/spec/fixtures/files/missing_node.xml +0 -11
- data/spec/fixtures/files/package_with_recoverable_error.zip +0 -0
- data/spec/fixtures/files/package_with_unrecoverable_error.zip +0 -0
- data/spec/fixtures/files/truncated_unrecoverable.xml +0 -9
- data/spec/fixtures/files/with_comments.xml +0 -110
- data/spec/fixtures/files/with_invalid_states.xml +0 -111
- data/spec/fixtures/files/with_states.xml +0 -111
- data/spec/fixtures/files/with_tags.xml +0 -64
- data/spec/lib/dradis/plugins/projects/export/v2/template_spec.rb +0 -72
- data/spec/lib/dradis/plugins/projects/export/v4/template_spec.rb +0 -84
- data/spec/lib/dradis/plugins/projects/upload/package_spec.rb +0 -58
- data/spec/lib/dradis/plugins/projects/upload/template_spec.rb +0 -80
- data/spec/lib/dradis/plugins/projects/upload/v1/template_spec.rb +0 -84
- data/spec/lib/dradis/plugins/projects/upload/v2/template_spec.rb +0 -65
- data/spec/lib/dradis/plugins/projects/upload/v4/template_spec.rb +0 -175
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<dradis-template version="4">
|
|
3
|
-
<nodes>
|
|
4
|
-
<node>
|
|
5
|
-
<id>3</id>
|
|
6
|
-
<label>Node 1</label>
|
|
7
|
-
<parent-id/>
|
|
8
|
-
<position>0</position>
|
|
9
|
-
<properties><![CDATA[{
|
|
10
|
-
}]]></properties>
|
|
11
|
-
<type-id>1</type-id>
|
|
12
|
-
<notes>
|
|
13
|
-
<note>
|
|
14
|
-
<id>2</id>
|
|
15
|
-
<author>xavi</author>
|
|
16
|
-
<category-id>2</category-id>
|
|
17
|
-
<text><![CDATA[#[Title]#
|
|
18
|
-
Note 1
|
|
19
|
-
|
|
20
|
-
#[Description]#
|
|
21
|
-
|
|
22
|
-
]]></text>
|
|
23
|
-
<activities>
|
|
24
|
-
<activity>
|
|
25
|
-
<action>create</action>
|
|
26
|
-
<user_email>xavi</user_email>
|
|
27
|
-
<created_at>1538467955</created_at>
|
|
28
|
-
</activity>
|
|
29
|
-
</activities>
|
|
30
|
-
<comments>
|
|
31
|
-
<comment>
|
|
32
|
-
<content><![CDATA[A comment on a note]]></content>
|
|
33
|
-
<author>xavi</author>
|
|
34
|
-
<created_at>1538467968</created_at>
|
|
35
|
-
</comment>
|
|
36
|
-
</comments>
|
|
37
|
-
</note>
|
|
38
|
-
</notes>
|
|
39
|
-
<evidence>
|
|
40
|
-
<evidence>
|
|
41
|
-
<id>386</id>
|
|
42
|
-
<author>xavi</author>
|
|
43
|
-
<issue-id>586</issue-id>
|
|
44
|
-
<content><![CDATA[#[Location]#
|
|
45
|
-
A
|
|
46
|
-
]]></content>
|
|
47
|
-
<activities>
|
|
48
|
-
<activity>
|
|
49
|
-
<action>create</action>
|
|
50
|
-
<user_email>xavi</user_email>
|
|
51
|
-
<created_at>1538549260</created_at>
|
|
52
|
-
</activity>
|
|
53
|
-
</activities>
|
|
54
|
-
<comments>
|
|
55
|
-
<comment>
|
|
56
|
-
<content><![CDATA[A comment on an evidence]]></content>
|
|
57
|
-
<author>xavi</author>
|
|
58
|
-
<created_at>1538549286</created_at>
|
|
59
|
-
</comment>
|
|
60
|
-
</comments>
|
|
61
|
-
</evidence>
|
|
62
|
-
</evidence>
|
|
63
|
-
<activities>
|
|
64
|
-
<activity>
|
|
65
|
-
<action>create</action>
|
|
66
|
-
<user_email>xavi</user_email>
|
|
67
|
-
<created_at>1538467945</created_at>
|
|
68
|
-
</activity>
|
|
69
|
-
</activities>
|
|
70
|
-
</node>
|
|
71
|
-
</nodes>
|
|
72
|
-
<issues>
|
|
73
|
-
<issue>
|
|
74
|
-
<id>586</id>
|
|
75
|
-
<author>xavi</author>
|
|
76
|
-
<state>fakestate</state>
|
|
77
|
-
<text><![CDATA[#[Title]#
|
|
78
|
-
Issue 1
|
|
79
|
-
|
|
80
|
-
#[Description]#
|
|
81
|
-
|
|
82
|
-
]]></text>
|
|
83
|
-
<activities>
|
|
84
|
-
<activity>
|
|
85
|
-
<action>create</action>
|
|
86
|
-
<user_email>xavi</user_email>
|
|
87
|
-
<created_at>1538467938</created_at>
|
|
88
|
-
</activity>
|
|
89
|
-
</activities>
|
|
90
|
-
<comments>
|
|
91
|
-
<comment>
|
|
92
|
-
<content><![CDATA[A comment on an issue]]></content>
|
|
93
|
-
<author>xavi</author>
|
|
94
|
-
<created_at>1538467997</created_at>
|
|
95
|
-
</comment>
|
|
96
|
-
</comments>
|
|
97
|
-
</issue>
|
|
98
|
-
</issues>
|
|
99
|
-
<methodologies/>
|
|
100
|
-
<categories>
|
|
101
|
-
<category>
|
|
102
|
-
<id>1</id>
|
|
103
|
-
<name>Issue description</name>
|
|
104
|
-
</category>
|
|
105
|
-
<category>
|
|
106
|
-
<id>2</id>
|
|
107
|
-
<name>Default category</name>
|
|
108
|
-
</category>
|
|
109
|
-
</categories>
|
|
110
|
-
<tags/>
|
|
111
|
-
</dradis-template>
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<dradis-template version="4">
|
|
3
|
-
<nodes>
|
|
4
|
-
<node>
|
|
5
|
-
<id>3</id>
|
|
6
|
-
<label>Node 1</label>
|
|
7
|
-
<parent-id/>
|
|
8
|
-
<position>0</position>
|
|
9
|
-
<properties><![CDATA[{
|
|
10
|
-
}]]></properties>
|
|
11
|
-
<type-id>1</type-id>
|
|
12
|
-
<notes>
|
|
13
|
-
<note>
|
|
14
|
-
<id>2</id>
|
|
15
|
-
<author>xavi</author>
|
|
16
|
-
<category-id>2</category-id>
|
|
17
|
-
<text><![CDATA[#[Title]#
|
|
18
|
-
Note 1
|
|
19
|
-
|
|
20
|
-
#[Description]#
|
|
21
|
-
|
|
22
|
-
]]></text>
|
|
23
|
-
<activities>
|
|
24
|
-
<activity>
|
|
25
|
-
<action>create</action>
|
|
26
|
-
<user_email>xavi</user_email>
|
|
27
|
-
<created_at>1538467955</created_at>
|
|
28
|
-
</activity>
|
|
29
|
-
</activities>
|
|
30
|
-
<comments>
|
|
31
|
-
<comment>
|
|
32
|
-
<content><![CDATA[A comment on a note]]></content>
|
|
33
|
-
<author>xavi</author>
|
|
34
|
-
<created_at>1538467968</created_at>
|
|
35
|
-
</comment>
|
|
36
|
-
</comments>
|
|
37
|
-
</note>
|
|
38
|
-
</notes>
|
|
39
|
-
<evidence>
|
|
40
|
-
<evidence>
|
|
41
|
-
<id>386</id>
|
|
42
|
-
<author>xavi</author>
|
|
43
|
-
<issue-id>586</issue-id>
|
|
44
|
-
<content><![CDATA[#[Location]#
|
|
45
|
-
A
|
|
46
|
-
]]></content>
|
|
47
|
-
<activities>
|
|
48
|
-
<activity>
|
|
49
|
-
<action>create</action>
|
|
50
|
-
<user_email>xavi</user_email>
|
|
51
|
-
<created_at>1538549260</created_at>
|
|
52
|
-
</activity>
|
|
53
|
-
</activities>
|
|
54
|
-
<comments>
|
|
55
|
-
<comment>
|
|
56
|
-
<content><![CDATA[A comment on an evidence]]></content>
|
|
57
|
-
<author>xavi</author>
|
|
58
|
-
<created_at>1538549286</created_at>
|
|
59
|
-
</comment>
|
|
60
|
-
</comments>
|
|
61
|
-
</evidence>
|
|
62
|
-
</evidence>
|
|
63
|
-
<activities>
|
|
64
|
-
<activity>
|
|
65
|
-
<action>create</action>
|
|
66
|
-
<user_email>xavi</user_email>
|
|
67
|
-
<created_at>1538467945</created_at>
|
|
68
|
-
</activity>
|
|
69
|
-
</activities>
|
|
70
|
-
</node>
|
|
71
|
-
</nodes>
|
|
72
|
-
<issues>
|
|
73
|
-
<issue>
|
|
74
|
-
<id>586</id>
|
|
75
|
-
<author>xavi</author>
|
|
76
|
-
<state>ready_for_review</state>
|
|
77
|
-
<text><![CDATA[#[Title]#
|
|
78
|
-
Issue 1
|
|
79
|
-
|
|
80
|
-
#[Description]#
|
|
81
|
-
|
|
82
|
-
]]></text>
|
|
83
|
-
<activities>
|
|
84
|
-
<activity>
|
|
85
|
-
<action>create</action>
|
|
86
|
-
<user_email>xavi</user_email>
|
|
87
|
-
<created_at>1538467938</created_at>
|
|
88
|
-
</activity>
|
|
89
|
-
</activities>
|
|
90
|
-
<comments>
|
|
91
|
-
<comment>
|
|
92
|
-
<content><![CDATA[A comment on an issue]]></content>
|
|
93
|
-
<author>xavi</author>
|
|
94
|
-
<created_at>1538467997</created_at>
|
|
95
|
-
</comment>
|
|
96
|
-
</comments>
|
|
97
|
-
</issue>
|
|
98
|
-
</issues>
|
|
99
|
-
<methodologies/>
|
|
100
|
-
<categories>
|
|
101
|
-
<category>
|
|
102
|
-
<id>1</id>
|
|
103
|
-
<name>Issue description</name>
|
|
104
|
-
</category>
|
|
105
|
-
<category>
|
|
106
|
-
<id>2</id>
|
|
107
|
-
<name>Default category</name>
|
|
108
|
-
</category>
|
|
109
|
-
</categories>
|
|
110
|
-
<tags/>
|
|
111
|
-
</dradis-template>
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<dradis-template version="2">
|
|
3
|
-
<nodes>
|
|
4
|
-
<node>
|
|
5
|
-
<id>5</id>
|
|
6
|
-
<label>Uploaded files</label>
|
|
7
|
-
<parent-id />
|
|
8
|
-
<position>0</position>
|
|
9
|
-
<properties><![CDATA[{
|
|
10
|
-
}]]></properties>
|
|
11
|
-
<type-id>0</type-id>
|
|
12
|
-
<notes></notes>
|
|
13
|
-
<evidence></evidence>
|
|
14
|
-
<activities></activities>
|
|
15
|
-
</node>
|
|
16
|
-
</nodes>
|
|
17
|
-
<issues>
|
|
18
|
-
<issue>
|
|
19
|
-
<id>2</id>
|
|
20
|
-
<author>admin@securityroots.com</author>
|
|
21
|
-
<text><![CDATA[#[Title]#
|
|
22
|
-
Test Issue
|
|
23
|
-
#[Description]#
|
|
24
|
-
hello world]]>
|
|
25
|
-
</text>
|
|
26
|
-
<activities></activities>
|
|
27
|
-
<comments></comments>
|
|
28
|
-
</issue>
|
|
29
|
-
</issues>
|
|
30
|
-
<methodologies></methodologies>
|
|
31
|
-
<categories>
|
|
32
|
-
<category>
|
|
33
|
-
<id>2</id>
|
|
34
|
-
<name>Issue description</name>
|
|
35
|
-
</category>
|
|
36
|
-
</categories>
|
|
37
|
-
<tags>
|
|
38
|
-
<tag>
|
|
39
|
-
<id>1</id>
|
|
40
|
-
<name>!2ca02c_info</name>
|
|
41
|
-
<taggings></taggings>
|
|
42
|
-
</tag>
|
|
43
|
-
<tag>
|
|
44
|
-
<id>2</id>
|
|
45
|
-
<name>!ff7f0e_medium</name>
|
|
46
|
-
<taggings></taggings>
|
|
47
|
-
</tag>
|
|
48
|
-
<tag>
|
|
49
|
-
<id>3</id>
|
|
50
|
-
<name>!d62728_high</name>
|
|
51
|
-
<taggings></taggings>
|
|
52
|
-
</tag>
|
|
53
|
-
<tag>
|
|
54
|
-
<id>4</id>
|
|
55
|
-
<name>!6baed6_low</name>
|
|
56
|
-
<taggings></taggings>
|
|
57
|
-
</tag>
|
|
58
|
-
<tag>
|
|
59
|
-
<id>5</id>
|
|
60
|
-
<name>!9467bd_critical</name>
|
|
61
|
-
<taggings></taggings>
|
|
62
|
-
</tag>
|
|
63
|
-
</tags>
|
|
64
|
-
</dradis-template>
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# DEPRECATED - this class is v2 of the Template Importer and shouldn't be updated.
|
|
2
|
-
# V4 released on Apr 2022
|
|
3
|
-
# V2 can be removed on Apr 2024
|
|
4
|
-
#
|
|
5
|
-
# We're duplicating this file for v4, and even though the code lives in two
|
|
6
|
-
# places now, this file isn't expected to evolve and is now frozen to V2
|
|
7
|
-
# behavior.
|
|
8
|
-
|
|
9
|
-
require 'rails_helper'
|
|
10
|
-
|
|
11
|
-
describe 'Dradis::Plugins::Projects::Export::V2::Template' do
|
|
12
|
-
let(:project) { create(:project) }
|
|
13
|
-
let(:user) { create(:user) }
|
|
14
|
-
let(:export) do
|
|
15
|
-
described_class.new(
|
|
16
|
-
default_user_id: user.id,
|
|
17
|
-
plugin: Dradis::Plugins::Projects,
|
|
18
|
-
project_id: project.id
|
|
19
|
-
).export
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context 'exporting a project' do
|
|
23
|
-
before do
|
|
24
|
-
@node = create(:node, project: project)
|
|
25
|
-
@issue = create(:issue, text: 'Issue 1', node: project.issue_library)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'with comments in an issue' do
|
|
29
|
-
before do
|
|
30
|
-
create(:comment, content: 'A comment on an issue', commentable: @issue)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'exports comments in the issue' do
|
|
34
|
-
expect(export).to include('A comment on an issue')
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'with comments in a note' do
|
|
39
|
-
before do
|
|
40
|
-
note = create(:note, text: 'Note 1', node: @node)
|
|
41
|
-
create(:comment, content: 'A comment on a note', commentable: note)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'exports comments in the note' do
|
|
45
|
-
expect(export).to include('A comment on a note')
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context 'with comments in an evidence' do
|
|
50
|
-
before do
|
|
51
|
-
evidence = create(:evidence, content: 'Test evidence', node: @node, issue: @issue)
|
|
52
|
-
create(:comment, content: 'A comment on an evidence', commentable: evidence)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'exports comments in the evidence' do
|
|
56
|
-
expect(export).to include('A comment on an evidence')
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context 'with comments with a deleted author' do
|
|
61
|
-
before do
|
|
62
|
-
note = create(:note, text: 'Note 1', node: @node)
|
|
63
|
-
comment = create(:comment, content: 'Deleted user', commentable: note)
|
|
64
|
-
comment.update_attribute :user, nil
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it 'exports the comment without errors' do
|
|
68
|
-
expect(export).to include('Deleted user')
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# Run the spec in CE/Pro context with:
|
|
2
|
-
# rspec <relative path to dradis-projects>/spec/lib/dradis/plugins/projects/export/v4/template_spec.rb
|
|
3
|
-
|
|
4
|
-
require 'rails_helper'
|
|
5
|
-
|
|
6
|
-
describe 'Dradis::Plugins::Projects::Export::V4::Template' do
|
|
7
|
-
let(:project) { create(:project) }
|
|
8
|
-
let(:user) { create(:user) }
|
|
9
|
-
let(:exporter) { 'Dradis::Plugins::Projects::Export::V4::Template' }
|
|
10
|
-
let(:export) do
|
|
11
|
-
exporter.constantize.new(
|
|
12
|
-
default_user_id: user.id,
|
|
13
|
-
plugin: Dradis::Plugins::Projects,
|
|
14
|
-
project_id: project.id
|
|
15
|
-
).export
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'exporting a project' do
|
|
19
|
-
before do
|
|
20
|
-
@node = create(:node, project: project)
|
|
21
|
-
@issue = create(:issue, text: 'Issue 1', node: project.issue_library)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe 'comments' do
|
|
25
|
-
context 'with comments in an issue' do
|
|
26
|
-
before do
|
|
27
|
-
create(:comment, content: 'A comment on an issue', commentable: @issue)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'exports comments in the issue' do
|
|
31
|
-
expect(export).to include('A comment on an issue')
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context 'with comments in a note' do
|
|
36
|
-
before do
|
|
37
|
-
note = create(:note, text: 'Note 1', node: @node)
|
|
38
|
-
create(:comment, content: 'A comment on a note', commentable: note)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'exports comments in the note' do
|
|
42
|
-
expect(export).to include('A comment on a note')
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'with comments in an evidence' do
|
|
47
|
-
before do
|
|
48
|
-
evidence = create(:evidence, content: 'Test evidence', node: @node, issue: @issue)
|
|
49
|
-
create(:comment, content: 'A comment on an evidence', commentable: evidence)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'exports comments in the evidence' do
|
|
53
|
-
expect(export).to include('A comment on an evidence')
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context 'with comments with a deleted author' do
|
|
58
|
-
before do
|
|
59
|
-
note = create(:note, text: 'Note 1', node: @node)
|
|
60
|
-
comment = create(:comment, content: 'Deleted user', commentable: note)
|
|
61
|
-
comment.update_attribute :user, nil
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'exports the comment without errors' do
|
|
65
|
-
expect(export).to include('Deleted user')
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe 'states' do
|
|
71
|
-
before do
|
|
72
|
-
Issue.states.each do |state|
|
|
73
|
-
create(:issue, text: 'Issue 1', node: project.issue_library, state: state[0])
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'export issues with states' do
|
|
78
|
-
Issue.states.each do |state|
|
|
79
|
-
expect(export).to include("<state>#{state[0]}</state>")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# Run the spec in CE/Pro context with:
|
|
2
|
-
# rspec <relative path to dradis-projects>/spec/lib/dradis/plugins/projects/upload/package_spec.rb
|
|
3
|
-
|
|
4
|
-
require 'rails_helper'
|
|
5
|
-
|
|
6
|
-
describe 'Dradis::Plugins::Projects::Upload::Package::Importer' do
|
|
7
|
-
let(:project) { create(:project) }
|
|
8
|
-
let(:user) { create(:user) }
|
|
9
|
-
let(:importer_class) { Dradis::Plugins::Projects::Upload::Package }
|
|
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
|
-
let(:dir) do
|
|
18
|
-
File.join(File.dirname(__FILE__), '../../../../../', 'fixtures', 'files')
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'when the packaged template has a recoverable XML error' do
|
|
22
|
-
let(:file_path) { File.join(dir, 'package_with_recoverable_error.zip') }
|
|
23
|
-
|
|
24
|
-
it 'imports the package successfully' do
|
|
25
|
-
expect(importer.import(file: file_path)).to be true
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'creates the issue from the package' do
|
|
29
|
-
importer.import(file: file_path)
|
|
30
|
-
|
|
31
|
-
expect(project.issues.count).to eq(1)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context 'when the packaged template has an unrecoverable XML error' do
|
|
36
|
-
let(:file_path) { File.join(dir, 'package_with_unrecoverable_error.zip') }
|
|
37
|
-
|
|
38
|
-
it 'returns false instead of raising an unhandled error' do
|
|
39
|
-
expect { importer.import(file: file_path) }.not_to raise_error
|
|
40
|
-
expect(importer.import(file: file_path)).to be false
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'logs a clear error message' do
|
|
44
|
-
logger = double('logger')
|
|
45
|
-
allow(logger).to receive_messages(debug: nil, error: nil, fatal: nil, info: nil, warn: nil)
|
|
46
|
-
expect(logger).to receive(:error).with('Failed to import the project template file.')
|
|
47
|
-
|
|
48
|
-
importer = importer_class::Importer.new(
|
|
49
|
-
default_user_id: user.id,
|
|
50
|
-
logger: logger,
|
|
51
|
-
plugin: importer_class,
|
|
52
|
-
project_id: project.id
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
importer.import(file: file_path)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Run the spec in CE/Pro context with:
|
|
2
|
-
# rspec <relative path to dradis-projects>/spec/lib/dradis/plugins/projects/upload/template_spec.rb
|
|
3
|
-
|
|
4
|
-
require 'rails_helper'
|
|
5
|
-
|
|
6
|
-
describe 'Dradis::Plugins::Projects::Upload::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
|
-
let(:dir) do
|
|
18
|
-
File.join(File.dirname(__FILE__), '../../../../../', 'fixtures', 'files')
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context 'uploading a template with a recoverable XML error (e.g. an invalid UTF-8 byte)' do
|
|
22
|
-
let(:file_path) { File.join(dir, 'invalid_byte_recoverable.xml') }
|
|
23
|
-
|
|
24
|
-
it 'still imports the template' do
|
|
25
|
-
expect(importer.import(file: file_path)).not_to be false
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'creates the issue with its content scrubbed instead of being dropped' do
|
|
29
|
-
importer.import(file: file_path)
|
|
30
|
-
|
|
31
|
-
expect(project.issues.count).to eq(1)
|
|
32
|
-
expect(project.issues.first.text).to include('Sample Issue')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'logs a warning instead of a fatal error' do
|
|
36
|
-
logger = double('logger')
|
|
37
|
-
allow(logger).to receive_messages(debug: nil, error: nil, fatal: nil, info: nil, warn: nil)
|
|
38
|
-
expect(logger).to receive(:warn).at_least(:once)
|
|
39
|
-
expect(logger).not_to receive(:error)
|
|
40
|
-
|
|
41
|
-
importer = importer_class::Importer.new(
|
|
42
|
-
default_user_id: user.id,
|
|
43
|
-
logger: logger,
|
|
44
|
-
plugin: importer_class,
|
|
45
|
-
project_id: project.id
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
importer.import(file: file_path)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'uploading a template with an unrecoverable XML error (e.g. a truncated file)' do
|
|
53
|
-
let(:file_path) { File.join(dir, 'truncated_unrecoverable.xml') }
|
|
54
|
-
|
|
55
|
-
it 'returns false' do
|
|
56
|
-
expect(importer.import(file: file_path)).to be false
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'does not import anything' do
|
|
60
|
-
importer.import(file: file_path)
|
|
61
|
-
|
|
62
|
-
expect(project.issues.count).to eq(0)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'logs a fatal error' do
|
|
66
|
-
logger = double('logger')
|
|
67
|
-
allow(logger).to receive_messages(debug: nil, error: nil, fatal: nil, info: nil, warn: nil)
|
|
68
|
-
expect(logger).to receive(:error).at_least(:once)
|
|
69
|
-
|
|
70
|
-
importer = importer_class::Importer.new(
|
|
71
|
-
default_user_id: user.id,
|
|
72
|
-
logger: logger,
|
|
73
|
-
plugin: importer_class,
|
|
74
|
-
project_id: project.id
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
importer.import(file: file_path)
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
# DEPRECATED - this class is v1 of the Template Importer and shouldn't be updated.
|
|
2
|
-
# V4 released on Apr 2022
|
|
3
|
-
# V1 can be removed on Apr 2024
|
|
4
|
-
#
|
|
5
|
-
# We're duplicating this file for v4, and even though the code lives in two
|
|
6
|
-
# places now, this file isn't expected to evolve and is now frozen to V1
|
|
7
|
-
# behavior.
|
|
8
|
-
|
|
9
|
-
# frozen_string_literal: true
|
|
10
|
-
|
|
11
|
-
require 'rails_helper'
|
|
12
|
-
|
|
13
|
-
describe Dradis::Plugins::Projects::Upload::V1::Template::Importer do
|
|
14
|
-
let(:project) { create(:project) }
|
|
15
|
-
let(:user) { create(:user) }
|
|
16
|
-
let(:importer_class) { Dradis::Plugins::Projects::Upload::Template }
|
|
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 = importer_class::Importer.new(
|
|
25
|
-
default_user_id: user.id,
|
|
26
|
-
plugin: importer_class,
|
|
27
|
-
project_id: project.id
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
importer.import(file: file_path)
|
|
31
|
-
|
|
32
|
-
p_id = project.id
|
|
33
|
-
n_id = project.plugin_uploads_node.id
|
|
34
|
-
|
|
35
|
-
expect(project.issues.first.text).to include(
|
|
36
|
-
"!/pro/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
|
|
37
|
-
"!/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
|
|
38
|
-
"!/pro/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
|
|
39
|
-
"!/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!"
|
|
40
|
-
)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'uploading a template malformed paths as ids' do
|
|
45
|
-
let(:file_path) do
|
|
46
|
-
File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files', 'malformed_ids.xml')
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'returns false' do
|
|
50
|
-
importer = importer_class::Importer.new(
|
|
51
|
-
default_user_id: user.id,
|
|
52
|
-
plugin: importer_class,
|
|
53
|
-
project_id: project.id
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
expect(importer.import(file: file_path)).to be false
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context 'uploading a template with attachment but missing node' do
|
|
61
|
-
let(:file_path) do
|
|
62
|
-
File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files', 'missing_node.xml')
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'does not modify the attachment' do
|
|
66
|
-
logger = double('logger')
|
|
67
|
-
allow(logger).to receive_messages(debug: nil, error: nil, fatal: nil, info: nil)
|
|
68
|
-
expect(logger).to receive(:error).once
|
|
69
|
-
|
|
70
|
-
importer = importer_class::Importer.new(
|
|
71
|
-
default_user_id: user.id,
|
|
72
|
-
logger: logger,
|
|
73
|
-
plugin: importer_class,
|
|
74
|
-
project_id: project.id
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
importer.import(file: file_path)
|
|
78
|
-
|
|
79
|
-
expect(project.issues.first.text).to include(
|
|
80
|
-
"!/pro/projects/222/nodes/12345/attachments/hello.jpg!"
|
|
81
|
-
)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|