Sha256: 26b97f0b0049531305c5796aa99c39b905a942ba606ab9a93e3ff8ca38b5e317

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

module Pagoda::Command
  describe Auth do
    before do
      @cli = prepare_command(Auth)
      @sandbox = "#{Dir.tmpdir}/cli_spec_#{Process.pid}"
      File.open(@sandbox, "w") { |f| f.write "user\npass\n" }
      @cli.stub!(:credentials_file).and_return(@sandbox)
      @cli.stub!(:running_on_a_mac?).and_return(false)
    end

    after do
      FileUtils.rm_rf(@sandbox)
    end

    it "reads credentials from the credentials file" do
      @cli.read_credentials.should == %w(user pass)
    end

    it "takes the user from the first line and the password from the second line" do
      @cli.user.should == 'user'
      @cli.password.should == 'pass'
    end

    it "asks for credentials when the file doesn't exist" do
      FileUtils.rm_rf(@sandbox)
      @cli.should_receive(:ask_for_credentials).and_return([ 'u', 'p'])
      @cli.should_receive(:save_credentials)
      @cli.get_credentials.should == [ 'u', 'p' ]
    end

    it "writes the credentials to a file" do
      @cli.stub!(:credentials).and_return(['one', 'two'])
      @cli.should_receive(:set_credentials_permissions)
      @cli.write_credentials
      File.read(@sandbox).should == "one\ntwo\n"
    end

    it "sets ~/.pagoda/credentials to be readable only by the user" do
      unless RUBY_PLATFORM =~ /mswin32|mingw32/
        sandbox = "#{Dir.tmpdir}/cli_spec_#{Process.pid}"
        FileUtils.rm_rf(sandbox)
        FileUtils.mkdir_p(sandbox)
        fname = "#{sandbox}/file"
        system "touch #{fname}"
        @cli.stub!(:credentials_file).and_return(fname)
        @cli.set_credentials_permissions
        File.stat(sandbox).mode.should == 040700
        File.stat(fname).mode.should == 0100600
      end
    end

    it "deletes the credentials file" do
      FileUtils.should_receive(:rm_f).with(@cli.credentials_file)
      @cli.delete_credentials
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pagoda-0.3.2 spec/commands/auth_spec.rb
pagoda-0.3.1 spec/commands/auth_spec.rb
pagoda-0.3.0 spec/commands/auth_spec.rb
pagoda-0.2.0 spec/commands/auth_spec.rb
pagoda-0.1.0 spec/commands/auth_spec.rb