dradis-projects 3.9.0 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b132456fc52c60a49be0e8fcb92b42d05874c1d
4
- data.tar.gz: d240988d1166f96509d3c483a6cc2179dad5d86c
3
+ metadata.gz: 0256537152511bdd57bd8bda059eecd5adfaf3d4
4
+ data.tar.gz: a456a38a9168d70a77266162a18844308314c479
5
5
  SHA512:
6
- metadata.gz: 7ac336d9eb5203fd73f23b3ccc2ef60d78c3f401fc4d8401b3e5c4cbd88090893fefea25fced73dcf08dcccd5a57ce43a83ef8e4a7f11cd24c404a4b2be241b4
7
- data.tar.gz: b6da1f393598f2cac694b55955c17117b4d7cccb2e2a2de1f8bc6a3c786604119fc8f692c2c64c8a7e2d1c7465f41906b848a025b8bff343b12fd415a9a03ce9
6
+ metadata.gz: 603efc920654a2a403a74094f036f742a0b02250e4fc030f10a4d25acdcce08b138b510fca6bfc30a82071a87f308990969e7cdf3a659cd0ed66bd1a09848432
7
+ data.tar.gz: 460caa7831aa233b2ada3e90333c1f2e4e9bdcaf7ee61b6ba323bf8b226722b1a4daf44062cdc5a5b6d0a477cebd9ffe156151cff381cdad0a28d79395a3324b
@@ -1,3 +1,13 @@
1
+ ## Dradis Framework 3.10 (August, 2018) ##
2
+
3
+ * Use project scopes
4
+
5
+ * Check project existence for default user id
6
+
7
+ * Comments export import
8
+
9
+ * Replace Node methods that are now Project methods
10
+
1
11
  ## Dradis Framework 3.9 (January, 2018) ##
2
12
 
3
13
  * Fix nodes upload
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rspec'
27
27
 
28
28
  spec.add_dependency 'dradis-plugins', '~> 3.7'
29
- spec.add_dependency 'rubyzip', '~> 1.2.1'
29
+ spec.add_dependency 'rubyzip', '~> 1.2.2'
30
30
  end
@@ -18,8 +18,8 @@ module Dradis
18
18
 
19
19
  initializer "dradis-projects.set_configs" do |app|
20
20
  options = app.config.dradis.projects
21
- options.template_exporter ||= Dradis::Plugins::Projects::Export::V1::Template
22
- options.template_uploader ||= Dradis::Plugins::Projects::Upload::V1::Template::Importer
21
+ options.template_exporter ||= Dradis::Plugins::Projects::Export::V2::Template
22
+ options.template_uploader ||= Dradis::Plugins::Projects::Upload::V2::Template::Importer
23
23
  end
24
24
 
25
25
 
@@ -15,7 +15,7 @@ module Dradis::Plugins::Projects::Export
15
15
  logger.debug{ "Creating a new Zip file in #{filename}..." }
16
16
 
17
17
  Zip::File.open(filename, Zip::File::CREATE) do |zipfile|
18
- Node.all.each do |node|
18
+ @project.nodes.each do |node|
19
19
  node_path = Attachment.pwd.join(node.id.to_s)
20
20
 
21
21
  Dir["#{node_path}/**/**"].each do |file|
@@ -28,3 +28,4 @@ module Dradis::Plugins::Projects::Export
28
28
  end
29
29
 
30
30
  require_relative 'v1/template'
31
+ require_relative 'v2/template'
@@ -50,7 +50,7 @@ module Dradis::Plugins::Projects::Export::V1
50
50
  end
51
51
 
52
52
  def build_issues(builder)
53
- @issues = Issue.where(node_id: Node.issue_library).includes(:activities)
53
+ @issues = Issue.where(node_id: project.issue_library).includes(:activities)
54
54
 
55
55
  builder.issues do |issues_builder|
56
56
  @issues.each do |issue|
@@ -67,7 +67,7 @@ module Dradis::Plugins::Projects::Export::V1
67
67
  end
68
68
 
69
69
  def build_methodologies(builder)
70
- methodologies = Node.methodology_library.notes
70
+ methodologies = project.methodology_library.notes
71
71
  builder.methodologies do |methodologies_builder|
72
72
  methodologies.each do |methodology|
73
73
  methodologies_builder.methodology(version: VERSION) do |methodology_builder|
@@ -80,7 +80,7 @@ module Dradis::Plugins::Projects::Export::V1
80
80
  end
81
81
 
82
82
  def build_nodes(builder)
83
- @nodes = Node.includes(:activities, :evidence, :notes, evidence: [:activities], notes: [:activities, :category]).all.reject do |node|
83
+ @nodes = project.nodes.includes(:activities, :evidence, :notes, evidence: [:activities], notes: [:activities, :category]).all.reject do |node|
84
84
  [Node::Types::METHODOLOGY,
85
85
  Node::Types::ISSUELIB].include?(node.type_id)
86
86
  end
@@ -125,7 +125,7 @@ module Dradis::Plugins::Projects::Export::V1
125
125
  def build_report_content(builder); end
126
126
 
127
127
  def build_tags(builder)
128
- tags = Tag.all
128
+ tags = project.tags
129
129
  builder.tags do |tags_builder|
130
130
  tags.each do |tag|
131
131
  tags_builder.tag do |tag_builder|
@@ -0,0 +1,40 @@
1
+ module Dradis::Plugins::Projects::Export::V2
2
+ class Template < Dradis::Plugins::Projects::Export::V1::Template
3
+ VERSION = 2
4
+
5
+ protected
6
+
7
+ def build_comments_for(builder, commentable)
8
+ builder.comments do |comments_builder|
9
+ commentable.comments.each do |comment|
10
+ comments_builder.comment do |comment_builder|
11
+ comment_builder.content do
12
+ comment_builder.cdata!(comment.content)
13
+ end
14
+ comment_builder.author(comment.user.email)
15
+ comment_builder.created_at(comment.created_at.to_i)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def build_issues(builder)
22
+ @issues = Issue.where(node_id: project.issue_library).includes(:activities)
23
+
24
+ builder.issues do |issues_builder|
25
+ @issues.each do |issue|
26
+ issues_builder.issue do |issue_builder|
27
+ issue_builder.id(issue.id)
28
+ issue_builder.author(issue.author)
29
+ issue_builder.text do
30
+ issue_builder.cdata!(issue.text)
31
+ end
32
+ build_activities_for(issue_builder, issue)
33
+ build_comments_for(issue_builder, issue)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -8,7 +8,7 @@ module Dradis
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 3
11
- MINOR = 9
11
+ MINOR = 10
12
12
  TINY = 0
13
13
  PRE = nil
14
14
 
@@ -88,3 +88,4 @@ module Dradis::Plugins::Projects::Upload
88
88
  end
89
89
 
90
90
  require_relative 'v1/template'
91
+ require_relative 'v2/template'
@@ -5,6 +5,8 @@ module Dradis::Plugins::Projects::Upload::V1
5
5
 
6
6
  attr_accessor :attachment_notes, :logger, :pending_changes
7
7
 
8
+ ATTACHMENT_URL = %r{^!(/[a-z]+)?/(?:projects/\d+/)?nodes/(\d+)/attachments/(.+)!$}
9
+
8
10
  def post_initialize(args={})
9
11
  @lookup_table = {
10
12
  categories: {},
@@ -50,11 +52,28 @@ module Dradis::Plugins::Projects::Upload::V1
50
52
  created_at: Time.at(xml_activity.at_xpath("created_at").text.to_i)
51
53
  )
52
54
 
55
+ activity.project_id = project.id if activity.respond_to?(:project)
56
+
53
57
  set_activity_user(activity, xml_activity.at_xpath("user_email").text)
54
58
 
55
59
  validate_and_save(activity)
56
60
  end
57
61
 
62
+ def create_issue(issue, xml_issue)
63
+ # TODO: Need to find some way of checking for dups
64
+ # May be combination of text, category_id and created_at
65
+ issue.author = xml_issue.at_xpath('author').text.strip
66
+ issue.text = xml_issue.at_xpath('text').text
67
+ issue.node = project.issue_library
68
+ issue.category = Category.issue
69
+
70
+ return false unless validate_and_save(issue)
71
+
72
+ return false unless create_activities(issue, xml_issue)
73
+
74
+ true
75
+ end
76
+
58
77
  def finalize(template)
59
78
  logger.info { 'Wrapping up...' }
60
79
 
@@ -72,10 +91,9 @@ module Dradis::Plugins::Projects::Upload::V1
72
91
 
73
92
  logger.info { "Adjusting screenshot URLs: #{item.class.name} ##{item.id}" }
74
93
 
75
- new_text = item.send(text_attr).gsub(%r{^!(.*)/nodes/(\d+)/attachments/(.+)!$}) do |_|
76
- "!%s/nodes/%d/attachments/%s!" % [$1, lookup_table[:nodes][$2], $3]
94
+ new_text = item.send(text_attr).gsub(ATTACHMENT_URL) do |_|
95
+ "!%s/projects/%d/nodes/%d/attachments/%s!" % [$1, project.id, lookup_table[:nodes][$2], $3]
77
96
  end
78
-
79
97
  item.send(text_attr.to_s + "=", new_text)
80
98
 
81
99
  raise "Couldn't save note attachment URL for #{item.class.name} ##{item.id}" unless validate_and_save(item)
@@ -89,8 +107,8 @@ module Dradis::Plugins::Projects::Upload::V1
89
107
  logger.info { "Setting issue_id for evidence" }
90
108
  evidence.issue_id = lookup_table[:issues][evidence.issue_id.to_s]
91
109
 
92
- new_content = evidence.content.gsub(%r{^!(.*)/nodes/(\d+)/attachments/(.+)!$}) do |_|
93
- "!%s/nodes/%d/attachments/%s!" % [$1, lookup_table[:nodes][$2], $3]
110
+ new_content = evidence.content.gsub(ATTACHMENT_URL) do |_|
111
+ "!%s/projects/%d/nodes/%d/attachments/%s!" % [$1, project.id, lookup_table[:nodes][$2], $3]
94
112
  end
95
113
  evidence.content = new_content
96
114
 
@@ -137,30 +155,19 @@ module Dradis::Plugins::Projects::Upload::V1
137
155
  # Will need to adjust node ID after generating node structure
138
156
  def parse_issues(template)
139
157
  issue = nil
140
- issue_category = Category.issue
141
- issue_library = Node.issue_library
142
158
 
143
159
  logger.info { 'Processing Issues...' }
144
160
 
145
161
  template.xpath('dradis-template/issues/issue').each do |xml_issue|
146
- old_id = xml_issue.at_xpath('id').text.strip
147
-
148
- # TODO: Need to find some way of checking for dups
149
- # May be combination of text, category_id and created_at
150
162
  issue = Issue.new
151
- issue.author = xml_issue.at_xpath('author').text.strip
152
- issue.text = xml_issue.at_xpath('text').text
153
- issue.node = issue_library
154
- issue.category = issue_category
155
-
156
- return false unless validate_and_save(issue)
157
163
 
158
- return false unless create_activities(issue, xml_issue)
164
+ return false unless create_issue(issue, xml_issue)
159
165
 
160
166
  if issue.text =~ %r{^!(.*)/nodes/(\d+)/attachments/(.+)!$}
161
167
  pending_changes[:attachment_notes] << issue
162
168
  end
163
169
 
170
+ old_id = xml_issue.at_xpath('id').text.strip
164
171
  lookup_table[:issues][old_id] = issue.id
165
172
  logger.info{ "New issue detected: #{issue.title}" }
166
173
  end
@@ -171,7 +178,7 @@ module Dradis::Plugins::Projects::Upload::V1
171
178
 
172
179
  def parse_methodologies(template)
173
180
  methodology_category = Category.default
174
- methodology_library = Node.methodology_library
181
+ methodology_library = project.methodology_library
175
182
 
176
183
  logger.info { 'Processing Methodologies...' }
177
184
 
@@ -220,10 +227,10 @@ module Dradis::Plugins::Projects::Upload::V1
220
227
  # - the Configuration.uploadsNode node (detected by its label)
221
228
  # - any nodes with type different from DEFAULT or HOST
222
229
  if label == Configuration.plugin_uploads_node
223
- node = Node.create_with(type_id: type_id, parent_id: parent_id)
230
+ node = project.nodes.create_with(type_id: type_id, parent_id: parent_id)
224
231
  .find_or_create_by!(label: label)
225
232
  elsif Node::Types::USER_TYPES.exclude?(type_id.to_i)
226
- node = Node.create_with(label: label)
233
+ node = project.nodes.create_with(label: label)
227
234
  .find_or_create_by!(type_id: type_id)
228
235
  else
229
236
  # We don't want to validate child nodes here yet since they always
@@ -231,14 +238,14 @@ module Dradis::Plugins::Projects::Upload::V1
231
238
  # finalize_nodes method.
232
239
  has_nil_parent = !parent_id
233
240
  node =
234
- Node.new(
241
+ project.nodes.new(
235
242
  type_id: type_id,
236
243
  label: label,
237
244
  parent_id: parent_id,
238
245
  position: position
239
246
  )
240
247
  node.save!(validate: has_nil_parent)
241
- pending_changes[:orphan_nodes] << node if parent_id
248
+ pending_changes[:orphan_nodes] << node if parent_id
242
249
  end
243
250
 
244
251
  if properties
@@ -291,7 +298,7 @@ module Dradis::Plugins::Projects::Upload::V1
291
298
  evidence.update_attribute(:updated_at, updated_at.text.strip) if updated_at
292
299
 
293
300
  pending_changes[:evidence] << evidence
294
- pending_changes[:evidence_activity] << xml_evidence.xpath("activities/activity")
301
+ pending_changes[:evidence_activity] << xml_evidence.xpath('activities/activity')
295
302
 
296
303
  logger.info { "\tNew evidence added." }
297
304
  end
@@ -339,7 +346,9 @@ module Dradis::Plugins::Projects::Upload::V1
339
346
 
340
347
  template.xpath('dradis-template/tags/tag').each do |xml_tag|
341
348
  name = xml_tag.at_xpath('name').text()
342
- tag = Tag.find_or_create_by!(name: name)
349
+ tag_params = { name: name }
350
+ tag_params[:project_id] = project.id if Tag.has_attribute?(:project_id)
351
+ tag = Tag.where(tag_params).first_or_create
343
352
  logger.info { "New tag detected: #{name}" }
344
353
 
345
354
  xml_tag.xpath('./taggings/tagging').each do |xml_tagging|
@@ -0,0 +1,37 @@
1
+ module Dradis::Plugins::Projects::Upload::V2
2
+ module Template
3
+ class Importer < Dradis::Plugins::Projects::Upload::V1::Template::Importer
4
+ private
5
+
6
+ def create_comments(commentable, xml_comments)
7
+ return true if xml_comments.empty?
8
+
9
+ xml_comments.each do |xml_comment|
10
+ author_email = xml_comment.at_xpath('author').text
11
+ comment = Comment.new(
12
+ commentable_id: commentable.id,
13
+ commentable_type: commentable.class.to_s,
14
+ content: xml_comment.at_xpath('content').text,
15
+ created_at: Time.at(xml_comment.at_xpath('created_at').text.to_i),
16
+ user_id: user_id_for_email(author_email)
17
+ )
18
+
19
+ if comment.user.email != author_email
20
+ comment.content = comment.content +
21
+ "\n\nOriginal author not available in this Dradis instance: "\
22
+ "#{author_email}."
23
+ end
24
+
25
+ return false unless validate_and_save(comment)
26
+ end
27
+ end
28
+
29
+ def create_issue(issue, xml_issue)
30
+ return false unless super
31
+ return false unless create_comments(issue, xml_issue.xpath('comments/comment'))
32
+
33
+ true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -79,7 +79,7 @@ class UploadTasks < Thor
79
79
 
80
80
  detect_and_set_project_scope
81
81
 
82
- default_user_id = @project.owners.first.id
82
+ default_user_id = @project ? @project.owners.first.id : User.first.id
83
83
 
84
84
  task_options.merge!({
85
85
  plugin: Dradis::Plugins::Projects::Upload::Template,
@@ -105,7 +105,7 @@ class UploadTasks < Thor
105
105
 
106
106
  detect_and_set_project_scope
107
107
 
108
- default_user_id = @project.owners.first.id
108
+ default_user_id = @project ? @project.owners.first.id : User.first.id
109
109
 
110
110
  task_options.merge!({
111
111
  plugin: Dradis::Plugins::Projects::Upload::Package,
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?><dradis-template version="2"><nodes><node><id>5</id><label>Uploaded files</label><parent-id/><position>0</position><properties><![CDATA[{
2
+ }]]></properties><type-id>0</type-id><notes></notes><evidence></evidence><activities></activities></node></nodes><issues><issue><id>2</id><author>admin@securityroots.com</author><text><![CDATA[#[Title]#
3
+ Test Issue
4
+
5
+ #[Description]#
6
+ !/pro/projects/222/nodes/5/attachments/hello.jpg!
7
+
8
+ !/projects/222/nodes/5/attachments/hello.jpg!
9
+
10
+ !/pro/nodes/5/attachments/hello.jpg!
11
+
12
+ !/nodes/5/attachments/hello.jpg!
13
+
14
+ ]]></text><activities></activities><comments></comments></issue></issues><methodologies></methodologies><categories>
15
+ <category><id>2</id><name>Issue description</name></category></categories><tags><tag><id>1</id><name>!9467bd_critical</name><taggings></taggings></tag><tag><id>2</id><name>!d62728_high</name><taggings></taggings></tag><tag><id>3</id><name>!ff7f0e_medium</name><taggings></taggings></tag><tag><id>4</id><name>!6baed6_low</name><taggings></taggings></tag><tag><id>5</id><name>!2ca02c_info</name><taggings></taggings></tag></tags></dradis-template>
@@ -0,0 +1,33 @@
1
+ require 'rails_helper'
2
+
3
+ describe Dradis::Plugins::Projects::Upload::V1::Template::Importer do
4
+
5
+ let(:project) { create(:project) }
6
+ let(:user) { create(:user) }
7
+ let(:importer_class) { Dradis::Plugins::Projects::Upload::Template }
8
+ let(:file_path) {
9
+ File.join(File.dirname(__FILE__), '../../../../../../', 'fixtures', 'files', 'attachments_url.xml')
10
+ }
11
+
12
+ context 'uploading a template with attachments url' do
13
+ it 'converts the urls' do
14
+ importer = importer_class::Importer.new(
15
+ default_user_id: user.id,
16
+ plugin: importer_class,
17
+ project_id: project.id
18
+ )
19
+
20
+ importer.import(file: file_path)
21
+
22
+ p_id = project.id
23
+ n_id = project.plugin_uploads_node.id
24
+
25
+ expect(project.issues.first.text).to include(
26
+ "!/pro/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
27
+ "!/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
28
+ "!/pro/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!\n\n" +
29
+ "!/projects/#{p_id}/nodes/#{n_id}/attachments/hello.jpg!"
30
+ )
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dradis-projects
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-08 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.2.1
89
+ version: 1.2.2
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.2.1
96
+ version: 1.2.2
97
97
  description: This plugin allows you to dump the contents of the repo into a zip archive
98
98
  and restore the state from one of them.
99
99
  email:
@@ -120,12 +120,16 @@ files:
120
120
  - lib/dradis/plugins/projects/export/package.rb
121
121
  - lib/dradis/plugins/projects/export/template.rb
122
122
  - lib/dradis/plugins/projects/export/v1/template.rb
123
+ - lib/dradis/plugins/projects/export/v2/template.rb
123
124
  - lib/dradis/plugins/projects/gem_version.rb
124
125
  - lib/dradis/plugins/projects/upload/package.rb
125
126
  - lib/dradis/plugins/projects/upload/template.rb
126
127
  - lib/dradis/plugins/projects/upload/v1/template.rb
128
+ - lib/dradis/plugins/projects/upload/v2/template.rb
127
129
  - lib/dradis/plugins/projects/version.rb
128
130
  - lib/tasks/thorfile.rb
131
+ - spec/fixtures/files/attachments_url.xml
132
+ - spec/lib/dradis/plugins/projects/upload/v1/template_spec.rb
129
133
  homepage: http://dradisframework.org
130
134
  licenses:
131
135
  - GPL-2
@@ -146,8 +150,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
150
  version: '0'
147
151
  requirements: []
148
152
  rubyforge_project:
149
- rubygems_version: 2.4.5
153
+ rubygems_version: 2.6.8
150
154
  signing_key:
151
155
  specification_version: 4
152
156
  summary: Project export/upload for the Dradis Framework.
153
- test_files: []
157
+ test_files:
158
+ - spec/fixtures/files/attachments_url.xml
159
+ - spec/lib/dradis/plugins/projects/upload/v1/template_spec.rb