dradis-plugins 4.6.1 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/app/controllers/dradis/plugins/export/base_controller.rb +9 -6
- data/dradis-plugins.gemspec +2 -2
- data/lib/dradis/plugins/content_service/base.rb +2 -0
- data/lib/dradis/plugins/content_service/content_blocks.rb +12 -1
- data/lib/dradis/plugins/content_service/core.rb +5 -3
- data/lib/dradis/plugins/content_service/issues.rb +15 -3
- data/lib/dradis/plugins/export/base.rb +4 -2
- data/lib/dradis/plugins/gem_version.rb +2 -2
- data/lib/dradis/plugins/thor_helper.rb +1 -1
- data/lib/dradis/plugins/upload/importer.rb +7 -4
- data/spec/lib/dradis/plugins/content_service/content_blocks_spec.rb +29 -0
- data/spec/lib/dradis/plugins/content_service/issues_spec.rb +21 -29
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cba7a2e144b2d99cb1cb3ed6433424e6e46c0c9b2ac4b92ba44d2d8c18e22a5
|
4
|
+
data.tar.gz: 63fb037763ed258a8286c01a2430b4c61b8c70a3e79f5bf372f468a679c2dcb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aae6bd486e5d39e78c7cef4731476ec3350a3dd73bd4dfac18061fd3dabd2a9d51a7045fd9c64a967c453000794d1d990a67f4d2ecc3bd77dc3b8646cfdd2039
|
7
|
+
data.tar.gz: 861a9ef7afdcc8450f13abde042710e25770c6edd9ed25d860703180a3b280bdcdf0aca4a7a8e780c3e259c529c1c96a21359ecd6c7c7286974365fadad61a5e
|
data/CHANGELOG.md
CHANGED
@@ -2,15 +2,18 @@ module Dradis
|
|
2
2
|
module Plugins
|
3
3
|
module Export
|
4
4
|
class BaseController < Rails.application.config.dradis.base_export_controller_class_name.to_s.constantize
|
5
|
+
before_action :validate_scope
|
5
6
|
|
6
7
|
protected
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def
|
13
|
-
|
9
|
+
def export_params
|
10
|
+
params.permit(:project_id, :scope, :template)
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate_scope
|
14
|
+
unless Dradis::Plugins::ContentService::Base::VALID_SCOPES.include?(params[:scope])
|
15
|
+
raise 'Something fishy is going on...'
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
data/dradis-plugins.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler', '
|
24
|
-
spec.add_development_dependency 'rake', '
|
23
|
+
spec.add_development_dependency 'bundler', '>= 2.2.33'
|
24
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
25
25
|
spec.add_development_dependency 'rspec-rails'
|
26
26
|
|
27
27
|
# By not including Rails as a dependency, we can use the gem with different
|
@@ -3,23 +3,34 @@ module Dradis::Plugins::ContentService
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
def all_content_blocks
|
6
|
-
|
6
|
+
case scope
|
7
|
+
when :all
|
8
|
+
project.content_blocks
|
9
|
+
when :published
|
10
|
+
project.content_blocks.published
|
11
|
+
else
|
12
|
+
raise 'Unsupported scope!'
|
13
|
+
end
|
7
14
|
end
|
8
15
|
|
9
16
|
def create_content_block(args={})
|
10
17
|
block_group = args.fetch(:block_group, default_content_block_group)
|
11
18
|
content = args.fetch(:content, default_content_block_content)
|
19
|
+
state = args.fetch(:state, :published)
|
12
20
|
user_id = args.fetch(:user_id)
|
13
21
|
|
14
22
|
content_block = ContentBlock.new(
|
15
23
|
content: content,
|
16
24
|
block_group: block_group,
|
17
25
|
project_id: project.id,
|
26
|
+
state: state,
|
18
27
|
user_id: user_id
|
19
28
|
)
|
20
29
|
|
21
30
|
if content_block.valid?
|
22
31
|
content_block.save
|
32
|
+
|
33
|
+
return content_block
|
23
34
|
else
|
24
35
|
try_rescue_from_length_validation(
|
25
36
|
model: content_block,
|
@@ -3,7 +3,7 @@ module Dradis::Plugins::ContentService
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
attr_accessor :logger, :plugin, :project
|
6
|
+
attr_accessor :logger, :plugin, :project, :scope
|
7
7
|
end
|
8
8
|
|
9
9
|
# ----------------------------------------------------------- Initializer
|
@@ -12,9 +12,11 @@ module Dradis::Plugins::ContentService
|
|
12
12
|
# @option plugin [Class] the 'wrapper' module of a plugin, e.g.
|
13
13
|
# Dradis::Plugins::Nessus
|
14
14
|
def initialize(args={})
|
15
|
-
@logger
|
16
|
-
@plugin
|
15
|
+
@logger = args.fetch(:logger, Rails.logger)
|
16
|
+
@plugin = args.fetch(:plugin)
|
17
17
|
@project = args[:project]
|
18
|
+
@scope = args.fetch(:scope, :published)
|
19
|
+
@state = args[:state]
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
@@ -3,7 +3,17 @@ module Dradis::Plugins::ContentService
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
def all_issues
|
6
|
-
|
6
|
+
issues =
|
7
|
+
case scope
|
8
|
+
when :all
|
9
|
+
project.issues
|
10
|
+
when :published
|
11
|
+
project.issues.published
|
12
|
+
else
|
13
|
+
raise 'Unsupported scope!'
|
14
|
+
end
|
15
|
+
|
16
|
+
issues.where(category_id: default_issue_category.id)
|
7
17
|
end
|
8
18
|
|
9
19
|
def create_issue(args={})
|
@@ -11,6 +21,7 @@ module Dradis::Plugins::ContentService
|
|
11
21
|
# NOTE that ID is the unique issue identifier assigned by the plugin,
|
12
22
|
# and is not to be confused with the Issue#id primary key
|
13
23
|
id = args.fetch(:id, default_issue_id)
|
24
|
+
state = args.fetch(:state, @state)
|
14
25
|
|
15
26
|
# Bail if we already have this issue in the cache
|
16
27
|
uuid = [plugin::Engine::plugin_name, id]
|
@@ -25,9 +36,10 @@ module Dradis::Plugins::ContentService
|
|
25
36
|
text << plugin_details
|
26
37
|
|
27
38
|
issue = Issue.new(text: text) do |i|
|
28
|
-
i.author
|
29
|
-
i.node
|
39
|
+
i.author = default_author
|
40
|
+
i.node = project.issue_library
|
30
41
|
i.category = default_issue_category
|
42
|
+
i.state = state
|
31
43
|
end
|
32
44
|
|
33
45
|
if issue.valid?
|
@@ -5,7 +5,7 @@ module Dradis
|
|
5
5
|
module Plugins
|
6
6
|
module Export
|
7
7
|
class Base
|
8
|
-
attr_accessor :content_service, :logger, :options, :plugin, :project
|
8
|
+
attr_accessor :content_service, :logger, :options, :plugin, :project, :scope
|
9
9
|
|
10
10
|
def initialize(args={})
|
11
11
|
# Save everything just in case the implementing class needs any of it.
|
@@ -15,6 +15,7 @@ module Dradis
|
|
15
15
|
@logger = args.fetch(:logger, Rails.logger)
|
16
16
|
@plugin = args[:plugin] || default_plugin
|
17
17
|
@project = args.key?(:project_id) ? Project.find(args[:project_id]) : nil
|
18
|
+
@scope = args.fetch(:scope, :published).to_sym
|
18
19
|
|
19
20
|
@content_service = args.fetch(:content_service, default_content_service)
|
20
21
|
|
@@ -34,7 +35,8 @@ module Dradis
|
|
34
35
|
@content ||= Dradis::Plugins::ContentService::Base.new(
|
35
36
|
logger: logger,
|
36
37
|
plugin: plugin,
|
37
|
-
project: project
|
38
|
+
project: project,
|
39
|
+
scope: scope
|
38
40
|
)
|
39
41
|
end
|
40
42
|
|
@@ -12,6 +12,7 @@ module Dradis
|
|
12
12
|
:options,
|
13
13
|
:plugin,
|
14
14
|
:project,
|
15
|
+
:state,
|
15
16
|
:template_service
|
16
17
|
)
|
17
18
|
|
@@ -22,10 +23,11 @@ module Dradis
|
|
22
23
|
def initialize(args={})
|
23
24
|
@options = args
|
24
25
|
|
25
|
-
@logger = args.fetch(:logger, Rails.logger)
|
26
|
-
@plugin = args[:plugin] || default_plugin
|
27
|
-
@project = args.key?(:project_id) ? Project.find(args[:project_id]) : nil
|
28
26
|
@default_user_id = args[:default_user_id] || -1
|
27
|
+
@logger = args.fetch(:logger, Rails.logger)
|
28
|
+
@plugin = args[:plugin] || default_plugin
|
29
|
+
@project = args.key?(:project_id) ? Project.find(args[:project_id]) : nil
|
30
|
+
@state = args.fetch(:state, :published)
|
29
31
|
|
30
32
|
@content_service = args.fetch(:content_service, default_content_service)
|
31
33
|
@template_service = args.fetch(:template_service, default_template_service)
|
@@ -46,7 +48,8 @@ module Dradis
|
|
46
48
|
@content ||= Dradis::Plugins::ContentService::Base.new(
|
47
49
|
logger: logger,
|
48
50
|
plugin: plugin,
|
49
|
-
project: project
|
51
|
+
project: project,
|
52
|
+
state: state
|
50
53
|
)
|
51
54
|
end
|
52
55
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# To run, execute from Dradis Pro main app folder:
|
4
|
+
# bin/rspec [dradis-plugins path]/spec/lib/dradis/plugins/content_service/content_blocks_spec.rb
|
5
|
+
|
6
|
+
describe 'Content Block content service' do
|
7
|
+
let(:plugin) { Dradis::Plugins::Nessus }
|
8
|
+
let(:plugin_id) { '111' }
|
9
|
+
let(:project) { create(:project) }
|
10
|
+
let(:service) do
|
11
|
+
Dradis::Plugins::ContentService::Base.new(
|
12
|
+
plugin: plugin,
|
13
|
+
logger: Rails.logger,
|
14
|
+
project: project
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#all_content_blocks' do
|
19
|
+
before do
|
20
|
+
@draft_content = create_list(:content_block, 10, project: project, state: :draft)
|
21
|
+
@review_content = create_list(:content_block, 10, project: project, state: :ready_for_review)
|
22
|
+
@published_content = create_list(:content_block, 10, project: project, state: :published)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns only the published content blocks' do
|
26
|
+
expect(service.all_content_blocks.to_a).to match_array(@published_content)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
# These specs are coming from engines/dradispro-rules/spec/content_service_spec.rb
|
4
3
|
# To run, execute from Dradis main app folder:
|
5
4
|
# bin/rspec [dradis-plugins path]/spec/lib/dradis/plugins/content_service/issues_spec.rb
|
6
5
|
|
7
|
-
describe
|
8
|
-
let(:plugin)
|
6
|
+
describe 'Issues content service' do
|
7
|
+
let(:plugin) { Dradis::Plugins::Nessus }
|
8
|
+
let(:plugin_id) { '111' }
|
9
9
|
let(:project) { create(:project) }
|
10
10
|
let(:service) do
|
11
11
|
Dradis::Plugins::ContentService::Base.new(
|
@@ -17,47 +17,39 @@ describe Dradis::Plugins::ContentService::Base do
|
|
17
17
|
|
18
18
|
describe 'Issues' do
|
19
19
|
let(:create_issue) do
|
20
|
-
service.
|
20
|
+
service.create_issue(text: "#[Title]#\nTest Issue\n", id: plugin_id, state: :ready_for_review)
|
21
21
|
end
|
22
22
|
|
23
|
-
# Remember: even though we're calling create_issue_without_callback,
|
24
|
-
# that method will still call issue_cache_with_callback internally.
|
25
|
-
# So when we store an issue in the issue_cache/finding_cache below,
|
26
|
-
# it's being stored within an instance of FindingCache, which
|
27
|
-
# automatically wraps Issues in Findings.
|
28
|
-
|
29
23
|
describe 'when the issue already exists in the cache' do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
it "doesn't create a new issue" do
|
34
|
-
expect{create_issue}.not_to change{Issue.count}
|
24
|
+
before do
|
25
|
+
issue = create(:issue, text: "#[Title]#\nTest Issue\n", id: plugin_id)
|
26
|
+
service.issue_cache.store("nessus-#{plugin_id}", issue)
|
35
27
|
end
|
36
28
|
|
37
|
-
it '
|
38
|
-
|
39
|
-
expect(finding).to be_a(Finding)
|
40
|
-
expect(finding).to eq Finding.from_issue(existing_issue)
|
29
|
+
it 'does not create a new issue' do
|
30
|
+
expect { create_issue }.not_to change { Issue.count }
|
41
31
|
end
|
42
32
|
end
|
43
33
|
|
44
34
|
describe "when the issue doesn't already exist in the cache" do
|
45
35
|
it "creates a new Issue containing 'plugin' and 'plugin_id'" do
|
46
36
|
new_issue = nil
|
47
|
-
|
48
|
-
expect
|
49
|
-
expect(new_issue.
|
37
|
+
plugin_name = "#{plugin}::Engine".constantize.plugin_name
|
38
|
+
expect { new_issue = create_issue }.to change { Issue.count }.by(1)
|
39
|
+
expect(new_issue.text).to match(/#\[plugin\]#\n*#{plugin_name}/)
|
40
|
+
expect(new_issue.text).to match(/#\[plugin_id\]#\n*#{plugin_id}/)
|
50
41
|
end
|
42
|
+
end
|
51
43
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
describe '#all_issues' do
|
45
|
+
before do
|
46
|
+
@draft_issues = create_list(:issue, 10, project: project, state: :draft)
|
47
|
+
@review_issues = create_list(:issue, 10, project: project, state: :ready_for_review)
|
48
|
+
@published_issues = create_list(:issue, 10, project: project, state: :published)
|
56
49
|
end
|
57
50
|
|
58
|
-
it '
|
59
|
-
|
60
|
-
expect(cache[cache_key]).to eq finding
|
51
|
+
it 'returns only the published issues' do
|
52
|
+
expect(service.all_issues.to_a).to match_array(@published_issues)
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dradis-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.8.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:
|
11
|
+
date: 2023-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- spec/engine_spec.rb
|
107
107
|
- spec/internal/log/test.log
|
108
108
|
- spec/lib/dradis/plugins/content_service/boards_spec.rb
|
109
|
+
- spec/lib/dradis/plugins/content_service/content_blocks_spec.rb
|
109
110
|
- spec/lib/dradis/plugins/content_service/issues_spec.rb
|
110
111
|
- spec/settings_spec.rb
|
111
112
|
- spec/spec_helper.rb
|
@@ -136,6 +137,7 @@ test_files:
|
|
136
137
|
- spec/engine_spec.rb
|
137
138
|
- spec/internal/log/test.log
|
138
139
|
- spec/lib/dradis/plugins/content_service/boards_spec.rb
|
140
|
+
- spec/lib/dradis/plugins/content_service/content_blocks_spec.rb
|
139
141
|
- spec/lib/dradis/plugins/content_service/issues_spec.rb
|
140
142
|
- spec/settings_spec.rb
|
141
143
|
- spec/spec_helper.rb
|