Exemple #1
0
def test_impersonation():
    from hbased import Hbase as thrift_hbase

    c = make_logged_in_client(username='******', is_superuser=False)
    grant_access('test_hbase', 'test_hbase', 'hbase')
    user = User.objects.get(username='******')

    proto = MockProtocol()
    client = thrift_hbase.Client(proto)

    impersonation_enabled = is_impersonation_enabled()

    get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = 'FALSE'
    try:
        client.getTableNames(doas=user.username)
    except AttributeError:
        pass  # We don't mock everything
    finally:
        get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = impersonation_enabled

    assert_equal({}, proto.get_headers())

    get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = 'TRUE'

    try:
        client.getTableNames(doas=user.username)
    except AttributeError:
        pass  # We don't mock everything
    finally:
        get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = impersonation_enabled

    assert_equal({'doAs': u'test_hbase'}, proto.get_headers())
Exemple #2
0
def test_impersonation():
  from hbased import Hbase as thrift_hbase

  c = make_logged_in_client(username='******', is_superuser=False)
  grant_access('test_hbase', 'test_hbase', 'hbase')
  user = User.objects.get(username='******')

  proto = MockProtocol()
  client = thrift_hbase.Client(proto)

  impersonation_enabled = is_impersonation_enabled()

  get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = 'FALSE'
  try:
    client.getTableNames(doas=user.username)
  except AttributeError:
    pass # We don't mock everything
  finally:
    get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = impersonation_enabled

  assert_equal({}, proto.get_headers())


  get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = 'TRUE'

  try:
    client.getTableNames(doas=user.username)
  except AttributeError:
    pass # We don't mock everything
  finally:
    get_conf()[_CNF_HBASE_IMPERSONATION_ENABLED] = impersonation_enabled

  assert_equal({'doAs': u'test_hbase'}, proto.get_headers())