Sha256: f5e7dd733226e980e26d198403be40f6fabc622ab176f2cb220b155c36ef6213

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'
require 'ronin/exploits/mixins/build_dir'

require 'ronin/exploits/exploit'

describe Ronin::Exploits::Mixins::BuildDir do
  module TestBuildDirMixin
    class TestExploit < Ronin::Exploits::Exploit
      include Ronin::Exploits::Mixins::BuildDir

      id 'test-exploit'

      def build
        @exploit = 'built exploit'
      end
    end
  end

  let(:exploit_class) { TestBuildDirMixin::TestExploit }
  subject { exploit_class.new }

  describe "#perform_build" do
    it "must set #build_dir to a temporary directory using the exploit ID then build the exploit" do
      expect(subject).to receive(:build)

      subject.perform_build

      expect(subject.build_dir).to match(%r{\A/tmp/ronin-exploit-#{exploit_class.id}-\d+-\d+-[a-z0-9]+\z})
      expect(File.directory?(subject.build_dir)).to be(true)
    end

    context "when the exploit ID contains a '/'" do
      module TestBuildDirmixin
        class TestExploitWithDirSeparatorInID < Ronin::Exploits::Exploit
          include Ronin::Exploits::Mixins::BuildDir

          id 'test/exploit'

          def build
            @exploit = 'built exploit'
          end
        end
      end

      let(:exploit_class) { TestBuildDirmixin::TestExploitWithDirSeparatorInID }

      it "must replace any '/' characters with a '-'" do
        subject.perform_build

        expect(subject.build_dir).to match(%r{\A/tmp/ronin-exploit-test-exploit-\d+-\d+-[a-z0-9]+\z})
      end
    end
  end

  describe "#perform_cleanup" do
    it "must delete #build_dir" do
      subject.perform_build

      build_dir = subject.build_dir

      subject.perform_cleanup

      expect(File.exist?(build_dir)).to be(false)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ronin-exploits-1.0.0.beta2 spec/mixins/build_dir.rb
ronin-exploits-1.0.0.beta1 spec/mixins/build_dir.rb