Sha256: 1d689ad228ee79610b64809a20925a4c915ccd2e16b614f9226bfb19cabaed11

Contents?: true

Size: 1.85 KB

Versions: 15

Compression:

Stored size: 1.85 KB

Contents

require 'rails_helper'

describe 'Nipper upload plugin' do
  describe 'importer' do
    before(:each) do
      # Stub template service
      templates_dir = File.expand_path('../../templates', __FILE__)
      expect_any_instance_of(Dradis::Plugins::TemplateService)
      .to receive(:default_templates_dir).and_return(templates_dir)

      plugin = Dradis::Plugins::Nipper

      @content_service = Dradis::Plugins::ContentService::Base.new(plugin: plugin)

      @importer = plugin::Importer.new(
        content_service: @content_service
      )
    end

    it 'creates an error note when an invalid Nipper XML is uploaded' do
      expect(@content_service).to receive(:create_note) do |args|
        expect(args[:text]).to include('No reports were detected in the uploaded file (/report).')
        OpenStruct.new(args)
      end.once

      @importer.import(file: File.expand_path('../spec/fixtures/files/invalid.xml', __dir__))
    end

    it 'creates nodes, issues, and evidences as needed' do
      expect(@content_service).to receive(:create_node) do |args|
        expect(args[:label]).to eq('PA-200')
        expect(args[:type]).to eq(:host)
        @node = Node.create(label: args[:label])
      end.once
      expect(@content_service).to receive(:create_issue) do |args|
        OpenStruct.new(args)
        @issue = Issue.create(text: args[:text])
      end.exactly(2).times
      expect(@content_service).to receive(:create_evidence) do |args|
        OpenStruct.new(args)
      end.exactly(2).times

      # Run the import
      @importer.import(file: File.expand_path('../spec/fixtures/files/sample.xml', __dir__))

      expect(@node.properties).to eq(
        {
          'device_name'=>'PA-200',
          'device_type'=>'Palo Alto Firewall',
          'os_version'=>'7.0.0'
        }
      )

      expect(@issue.fields['Finding'].lines.count).to eq(2)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dradis-nipper-4.15.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.14.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.13.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.11.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.10.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.9.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.8.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.7.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.6.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.5.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.4.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.3.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.2.0 spec/upload_v2.8_spec.rb
dradis-nipper-4.1.0 spec/upload_spec.rb
dradis-nipper-4.0.0 spec/upload_spec.rb