summaryrefslogtreecommitdiff
path: root/test/authentication/methods/test_none.rb
blob: bc715056a095a5bc3cd652c0b0f5c44ed5467b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'common'
require 'net/ssh/authentication/methods/none'
require 'authentication/methods/common'

module Authentication
  module Methods
    class TestNone < NetSSHTest
      include Common

      def test_authenticate_should_raise_if_none_disallowed
        transport.expect do |t,packet|
          assert_equal USERAUTH_REQUEST, packet.type
          assert_equal "jamis", packet.read_string
          assert_equal "ssh-connection", packet.read_string
          assert_equal "none", packet.read_string

          t.return(USERAUTH_FAILURE, :string, "publickey")
        end

        assert_raises Net::SSH::Authentication::DisallowedMethod do
          subject.authenticate("ssh-connection", "jamis", "pass")
        end
      end

      def test_authenticate_should_return_true
        transport.expect do |t,packet|
          assert_equal USERAUTH_REQUEST, packet.type
          t.return(USERAUTH_SUCCESS)
        end

        assert subject.authenticate("ssh-connection", "", "")
      end

      private

      def subject(options={})
        @subject ||= Net::SSH::Authentication::Methods::None.new(session(options), options)
      end
    end
  end
end