Sha256: b3d909315e05fe954b8b1aefe67ec0db1a0fcbdf1b762d0c1d6dbf3620b66f05

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe SSH::Allow::Command do

  context "for a simple command" do
    before(:each) do
      @cmd_text = 'git help'
      @command = SSH::Allow::Command.new(@cmd_text)
    end

    it "returns the correct name" do
      @command.name.should == 'git'
    end

    it "returns the array of arguments" do
      @command.arguments.should == ['help']
    end

    it "returns an empty array for options" do
      @command.options.should == []
    end
  end

  context "for a complex command" do
    before(:each) do
      @cmd_text = %(git log --since="6 months ago" Gemfile)
      @command = SSH::Allow::Command.new(@cmd_text)
    end

    it "returns the array of arguments" do
      @command.arguments.should == ['log', '"6 months ago"', 'Gemfile']
    end

    it "returns the array of options" do
      @command.options.should == ['since']
    end
  end

  describe "#allowed?" do
    context "with 1 'allow' rule, each, for cp and mv commands" do
      before(:each) do
        @cp = mock(:cp_rule)
        @mv = mock(:mv_rule)
        @cp.should_receive(:match?).once.and_return([false, false])
        @rules = [@cp, @mv]
        cmd_text = 'mv /foo/bar /baz/bar'
        @command = SSH::Allow::Command.new(cmd_text)
      end

      context "when the mv command matches" do
        before(:each) do
          @mv.should_receive(:match?).once.and_return([true, true])
        end

        it "returns true" do
          @command.should be_allowed(@rules)
        end
      end

      context "when the mv command doesn't match" do
        before(:each) do
          @mv.should_receive(:match?).once.and_return([false, false])
        end

        it "returns false" do
          @command.should_not be_allowed(@rules)
        end
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ssh-allow-0.6.0 spec/command_spec.rb