Sha256: 88b069a4d77f5f382b051b5a8eb96ad7f57ea91553851cf73f1474a0fd28bbeb

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

require File.dirname(__FILE__) + '/../test_helper'

class AuthTest < Test::Unit::TestCase

  def setup
    @handler = Authpipe::Auth.new
    @account = Authpipe::AccountData[:address => 'foo@example.com', :home => '/home/foo', :gid => 1024, :uid => 1024]
  end

  def test_process_validates_auth_type
    auth = "unsupported\nfoo\nbar"
    STDIN.expects(:readbytes).returns(auth)
    @handler.expects(:get_account_data).never
    assert_raises(Authpipe::UnsupportedAuthenticationType) do
      @handler.process(auth.length)
    end

    ['login', 'cram-md5', 'cram-sha1', 'cram-sha256'].each do |authtype|
      auth = "#{authtype}\nfoo\nbar"
      STDIN.expects(:readbytes).returns(auth)
      @handler.expects(:get_account_data).returns(@account)
      assert_nothing_raised do
        @handler.process(auth.length)
      end
    end
  end

  def test_process_fails_auth
    auth = "login\nfoo\nbar"
    STDIN.expects(:readbytes).returns(auth)

    @handler.expects(:get_account_data).returns(nil)
    assert_raises(Authpipe::AuthpipeException) do
      @handler.process(auth.length)
    end
  end

  def test_process_passes_auth
    auth = "login\nfoo\nbar"
    STDIN.expects(:readbytes).returns(auth)

    @handler.expects(:get_account_data).returns(@account)
    assert_nothing_raised do
      assert_equal @account.to_authpipe, @handler.process(auth.length)
    end
  end

  def test_process_calls_get_account_data
    auth = "login\nfoo\nbar"
    STDIN.expects(:readbytes).returns(auth)
    @handler.expects(:get_account_data).with(
      :authtype => 'login', :username => 'foo', :password => 'bar'
    ).returns(@account)
    assert_nothing_raised do
      @handler.process(auth.length)
    end

    auth = "login\nabcdef\nqazwsx"
    STDIN.expects(:readbytes).returns(auth)
    @handler.expects(:get_account_data).with(
      :authtype => 'login', :username => 'abcdef', :password => 'qazwsx'
    ).returns(@account)
    assert_nothing_raised do
      @handler.process(auth.length)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mroch-authpipe-0.1.1 test/authpipe/auth_test.rb