dradis-plugins 4.7.0 → 4.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a55255c245e1ce6009d032fab79a582b05e760af0942ae7893ee7bb42af99dc
4
- data.tar.gz: 350e48e4f5c7021339e0d542d7d9776bafaf44f78e23b3feae5e7f8e8d8e6d4f
3
+ metadata.gz: 3cba7a2e144b2d99cb1cb3ed6433424e6e46c0c9b2ac4b92ba44d2d8c18e22a5
4
+ data.tar.gz: 63fb037763ed258a8286c01a2430b4c61b8c70a3e79f5bf372f468a679c2dcb6
5
5
  SHA512:
6
- metadata.gz: 91ee0fb58cc17d416a403dd60b9eeae6c106f16fdc4badeda6816f171f5154da7443b0c0b9d96964bf06d32a1f7b41f94db5e7d5c15f7bf3cb4c6ee0a773b643
7
- data.tar.gz: 04af89b9742efb8803f8e8d9c934aea5fa9b38c0fa7dcf16fe0f1d23a270167ef1f2c2e46af93d9e00c47c20618467e07b862b03fb4765e799d45dbcbec8ed8b
6
+ metadata.gz: aae6bd486e5d39e78c7cef4731476ec3350a3dd73bd4dfac18061fd3dabd2a9d51a7045fd9c64a967c453000794d1d990a67f4d2ecc3bd77dc3b8646cfdd2039
7
+ data.tar.gz: 861a9ef7afdcc8450f13abde042710e25770c6edd9ed25d860703180a3b280bdcdf0aca4a7a8e780c3e259c529c1c96a21359ecd6c7c7286974365fadad61a5e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ v4.8.0 (April 2023)
2
+ - Add support for issue and content block states
3
+
1
4
  v4.7.0 (February 2023)
2
5
  - No changes
3
6
 
@@ -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
- # Protected: allows export plugins to access the options sent from the
9
- # framework via the session object (see Export#create).
10
- #
11
- # Returns a Hash with indifferent access.
12
- def export_options
13
- @export_options ||= session[:export_manager].with_indifferent_access
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
@@ -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', '~> 1.6'
24
- spec.add_development_dependency 'rake', '~> 10.0'
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
@@ -10,6 +10,8 @@ require 'dradis/plugins/content_service/properties'
10
10
 
11
11
  module Dradis::Plugins::ContentService
12
12
  class Base
13
+ VALID_SCOPES = %w[all published].freeze
14
+
13
15
  include Core
14
16
 
15
17
  include Boards
@@ -3,23 +3,34 @@ module Dradis::Plugins::ContentService
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def all_content_blocks
6
- project.content_blocks
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 = args.fetch(:logger, Rails.logger)
16
- @plugin = args.fetch(: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
- project.issues.where(category_id: default_issue_category.id)
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 = default_author
29
- i.node = project.issue_library
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
 
@@ -7,7 +7,7 @@ module Dradis
7
7
 
8
8
  module VERSION
9
9
  MAJOR = 4
10
- MINOR = 7
10
+ MINOR = 8
11
11
  TINY = 0
12
12
  PRE = nil
13
13
 
@@ -9,7 +9,7 @@ module Dradis
9
9
  end
10
10
 
11
11
  def task_options
12
- @task_options ||= { logger: logger }
12
+ @task_options ||= { logger: logger, state: :published }
13
13
  end
14
14
 
15
15
  def logger
@@ -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 Dradis::Plugins::ContentService::Base do
8
- let(:plugin) { Dradis::Plugins::Nessus }
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.create_issue_without_callback(id: plugin_id)
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
- let(:existing_issue) { create(:issue, text: cached_issue_text) }
31
- before { cache.store(existing_issue) }
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 'returns the cached issue encapsulated in a finding' do
38
- finding = create_issue
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
- expect{new_issue = create_issue}.to change{Issue.count}.by(1)
48
- expect(new_issue.body).to match(/#\[plugin\]#\n*#{plugin_name}/)
49
- expect(new_issue.body).to match(/#\[plugin_id\]#\n*#{plugin_id}/)
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
- it 'returns the new Issue encapsulated in a Finding' do
53
- finding = create_issue
54
- expect(finding).to be_a(Finding)
55
- expect(finding).to eq Finding.from_issue(Issue.last)
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 'adds the new Finding to the cache' do
59
- finding = create_issue
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.7.0
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Martin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
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: '1.6'
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: '1.6'
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: '10.0'
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: '10.0'
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
@@ -113,7 +114,7 @@ homepage: http://dradisframework.org
113
114
  licenses:
114
115
  - GPL-2
115
116
  metadata: {}
116
- post_install_message:
117
+ post_install_message:
117
118
  rdoc_options: []
118
119
  require_paths:
119
120
  - lib
@@ -128,14 +129,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  - !ruby/object:Gem::Version
129
130
  version: '0'
130
131
  requirements: []
131
- rubygems_version: 3.1.4
132
- signing_key:
132
+ rubygems_version: 3.3.7
133
+ signing_key:
133
134
  specification_version: 4
134
135
  summary: Plugin manager for the Dradis Framework project.
135
136
  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