Sha256: 58492c205b645140972f1da09a6477136fcc889a5b6894f32795b56dc46a32ba

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require "test/unit"

require "jmx4r"
require "jconsole"

class TestAuthentication < Test::Unit::TestCase

  def setup
    @username = "jmx4r.user"
    @password = "jmx4r.password"

    pwd_path = "/tmp/jmx4r.password"
    @pwd_file = File.new(pwd_path, "w")
    @pwd_file.puts "#{@username} #{@password}"
    @pwd_file.close
    
    # pwd file must be readable only by user
    # but somehow File.chmod is not working
    # with JRuby
    `chmod 0600 #{@pwd_file.path}`
    
    access_path = "/tmp/jmx4r.access"
    @access_file = File.new(access_path, "w")
    @access_file.puts "#{@username} readwrite"
    @access_file.close
    # access file must be readable only by user
    `chmod 0600 #{@access_file.path}`

    JConsole::start :pwd_file => @pwd_file.path, :access_file => @access_file.path
  end

  def teardown
    JMX::MBean.remove_connection
    JConsole::stop
    File.delete @pwd_file.path if File.file? @pwd_file.path
    File.delete @access_file.path if File.file? @access_file.path
  end

  def test_establish_auth_connection_with_correct_credentials
    JMX::MBean.establish_connection :username => @username, :password => @password 
  end

  def test_establish_auth_connection_with_incorrect_credentials
    assert_raise(NativeException) {
      JMX::MBean.establish_connection :username => "not a valid user name", :password => @password
    }
  end

  def test_establish_auth_connection_with_no_credentials
    assert_raise(NativeException) {
      JMX::MBean.establish_connection
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jmx4r-0.0.2 test/tc_auth.rb