class TestContext

Public Instance Methods

test_authenticate_with_basic() click to toggle source
# File test/test_context.rb, line 60
def test_authenticate_with_basic
  new_arguments = @splunkrc.clone
  new_arguments[:basic] = true

  new_service = Context.new(new_arguments)
  assert_logged_in(new_service)
  assert_equal(new_service.request(:resource => ["apps", "local"]).code, "200")
end
test_authenticate_with_token() click to toggle source
# File test/test_context.rb, line 46
def test_authenticate_with_token
  service = Context.new(@splunkrc).login()
  token = service.token

  new_arguments = @splunkrc.clone
  new_arguments.delete(:username)
  new_arguments.delete(:password)
  new_arguments[:token] = token

  new_service = Context.new(new_arguments)
  assert_not_nil(new_service.token)
  assert_logged_in(new_service)
end
test_connect() click to toggle source
# File test/test_context.rb, line 96
def test_connect()
  service = Context.new(@splunkrc).login()
  socket = service.connect()
  # Send a manual HTTP request
  socket.write("GET /services/data/indexes HTTP/1.1\r\n")
  socket.write("Authorization: Splunk #{service.token}\r\n")
  socket.write("\r\n")
  response = socket.readlines()
  assert_equal("HTTP/1.1 200 OK", response[0].strip)
end
test_failed_login() click to toggle source
# File test/test_context.rb, line 69
def test_failed_login()
  args = @splunkrc.clone()
  args[:username] = args[:username] + "-boris"
  service = Context.new(args)

  assert_raises(SplunkHTTPError) {service.login()}
end
test_info() click to toggle source
# File test/test_context.rb, line 117
def test_info
  assert_true(@service.info.has_key?("version"))
end
test_login() click to toggle source
# File test/test_context.rb, line 25
def test_login()
  service = Context.new(@splunkrc)
  service.login()
  assert_logged_in(service)
end
test_login_with_encodings() click to toggle source
# File test/test_context.rb, line 31
def test_login_with_encodings()
  ["ASCII", "UTF-8"].each() do |encoding|
    values = {}
    @splunkrc.each() do |key, value|
      if value.is_a?(String)
        values[key] = value.clone().force_encoding(encoding)
      else
        values[key] = value
      end
    end
    service = Context.new(values).login()
    assert_logged_in(service)
  end
end
test_logout() click to toggle source
# File test/test_context.rb, line 85
def test_logout
  service = Context.new(@splunkrc).login()
  assert_logged_in(service)

  service.logout()
  assert_not_logged_in(service)

  service.login()
  assert_logged_in(service)
end
test_multiple_logins_are_nops() click to toggle source
# File test/test_context.rb, line 77
def test_multiple_logins_are_nops()
  service = Context.new(@splunkrc).login()
  assert_logged_in(service)

  assert_nothing_raised() {service.login()}
  assert_logged_in(service)
end
test_server_accepting_connections?() click to toggle source
# File test/test_context.rb, line 107
def test_server_accepting_connections?
  values = @splunkrc.clone()
  values[:port] = 8000
  service = Context.new(values)
  assert_false(service.server_accepting_connections?)

  service = Context.new(@splunkrc)
  assert_true(service.server_accepting_connections?)
end
test_splunk_version() click to toggle source
# File test/test_context.rb, line 121
def test_splunk_version
  version = @service.splunk_version
  assert_true(version.is_a?(Array))
  version.each() do |v|
    assert_true(v.is_a?(Integer))
  end
end
test_url_encoding_of_characters_in_usernames() click to toggle source
# File test/test_context.rb, line 129
def test_url_encoding_of_characters_in_usernames
  name = temporary_name() + "/\4441@"
  begin
    @service.request(:namespace => Splunk::namespace(:sharing => "user", :owner => name, :app => name))
    fail("Didn't receive an error.")
  rescue SplunkHTTPError => err
    assert_equal(404, err.code)
    assert_equal("User does not exist: " + name, err.detail)
  end
end