Sha256: b7a412a636b7d3a94a500a4b9dedaa925bcc8fa5a0b5cec30fe266dc975736a4

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'
require 'ronin/exploits/mixins/file_builder'

require 'ronin/exploits/exploit'
require 'fileutils'
require 'tmpdir'

describe Ronin::Exploits::Mixins::FileBuilder do
  module TestFileBuilder
    class TestExploit < Ronin::Exploits::Exploit
      include Ronin::Exploits::Mixins::FileBuilder
    end
  end

  let(:exploit_class) { TestFileBuilder::TestExploit }

  it "must also include Ronin::Exploits::Params::Filename" do
    expect(exploit_class).to include(Ronin::Exploits::Params::Filename)
  end

  subject { exploit_class.new }

  describe "#build_file" do
    before(:all) do
      @old_cwd = Dir.pwd
      Dir.chdir(Dir.tmpdir)
    end

    let(:contents) { 'hello world' }

    context "when given no arguments are given" do
      context "when #filename returns a filename" do
        let(:filename) { 'test-file.txt' }

        subject do
          exploit_class.new(params: {filename: filename})
        end

        it "must open a file for #filename in the current directory for writing" do
          subject.build_file do |file|
            file.write(contents)
          end

          expect(File.read(filename)).to eq(contents)
        end

        after { FileUtils.rm(filename) }
      end
    end

    context "when a name argument is given" do
      let(:name) { 'explicit-test-file.txt' }

      it "must open a file with the given name in the current directory for writing" do
        subject.build_file(name) do |file|
          file.write(contents)
        end

        expect(File.read(name)).to eq(contents)
      end

      after { FileUtils.rm(name) }
    end

    after { Dir.chdir(@old_cwd) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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