• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tests.reset_all_users函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.reset_all_users函数的典型用法代码示例。如果您正苦于以下问题:Python reset_all_users函数的具体用法?Python reset_all_users怎么用?Python reset_all_users使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reset_all_users函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_add_ldap_groups

def test_add_ldap_groups():
  URL = reverse(add_ldap_groups)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()


  c = make_logged_in_client(username='test', is_superuser=True)

  assert_true(c.get(URL))

  response = c.post(URL, dict(groupname_pattern='TestUsers'))
  assert_true('Location' in response, response)
  assert_true('/useradmin/groups' in response['Location'])

  # Test with space
  response = c.post(URL, dict(groupname_pattern='Test Administrators'))
  assert_true('Location' in response, response)
  assert_true('/useradmin/groups' in response['Location'], response)

  response = c.post(URL, dict(groupname_pattern='toolongnametoolongnametoolongnametoolongnametoolongnametoolongname'
                                                'toolongnametoolongnametoolongnametoolongnametoolongnametoolongname'
                                                'toolongnametoolongnametoolongnametoolongnametoolongnametoolongname'
                                                'toolongnametoolongnametoolongnametoolongnametoolongnametoolongname'))
  assert_true('Ensure this value has at most 256 characters' in response.context['form'].errors['groupname_pattern'][0], response)

  # Test wild card
  response = c.post(URL, dict(groupname_pattern='*r*'))
  assert_true('/useradmin/groups' in response['Location'], response)
开发者ID:QLGu,项目名称:hue,代码行数:32,代码来源:test_ldap_deprecated.py


示例2: test_ensure_home_directory_sync_ldap_users_groups

def test_ensure_home_directory_sync_ldap_users_groups():
  URL = reverse(sync_ldap_users_groups)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  cluster = pseudo_hdfs4.shared_cluster()
  c = make_logged_in_client(cluster.superuser, is_superuser=True)
  cluster.fs.setuser(cluster.superuser)

  reset = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    c.post(reverse(add_ldap_users), dict(server='nonsense', username_pattern='curly', password1='test', password2='test'))
    assert_false(cluster.fs.exists('/user/curly'))
    assert_true(c.post(URL, dict(server='nonsense', ensure_home_directory=True)))
    assert_true(cluster.fs.exists('/user/curly'))
  finally:
    for finish in reset:
      finish()

    if cluster.fs.exists('/user/curly'):
      cluster.fs.rmtree('/user/curly')
开发者ID:neiodavince,项目名称:hue,代码行数:30,代码来源:test_ldap.py


示例3: test_useradmin_ldap_user_group_membership_sync

def test_useradmin_ldap_user_group_membership_sync():
  settings.MIDDLEWARE_CLASSES.append('useradmin.middleware.LdapSynchronizationMiddleware')

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()
  # Make sure LDAP groups exist or they won't sync
  import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=False, import_members_recursive=False, sync_users=False, import_by_dn=False)
  import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'Test Administrators', import_members=False, import_members_recursive=False, sync_users=False, import_by_dn=False)

  reset = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    # Import curly who is part of TestUsers and Test Administrators
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'curly', sync_groups=False, import_by_dn=False)

    # Set a password so that we can login
    user = User.objects.get(username='curly')
    user.set_password('test')
    user.save()

    # Should have 0 groups
    assert_equal(0, user.groups.all().count())

    # Make an authenticated request as curly so that we can see call middleware.
    c = make_logged_in_client('curly', 'test', is_superuser=False)
    grant_access("curly", "test", "useradmin")
    response = c.get('/useradmin/users')

    # Refresh user groups
    user = User.objects.get(username='curly')

    # Should have 3 groups now. 2 from LDAP and 1 from 'grant_access' call.
    assert_equal(3, user.groups.all().count(), user.groups.all())

    # Now remove a group and try again.
    old_group = ldap_access.CACHED_LDAP_CONN._instance.users['curly']['groups'].pop()

    # Make an authenticated request as curly so that we can see call middleware.
    response = c.get('/useradmin/users')

    # Refresh user groups
    user = User.objects.get(username='curly')

    # Should have 2 groups now. 1 from LDAP and 1 from 'grant_access' call.
    assert_equal(3, user.groups.all().count(), user.groups.all())
  finally:
    settings.MIDDLEWARE_CLASSES.remove('useradmin.middleware.LdapSynchronizationMiddleware')

    for finish in reset:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:57,代码来源:test_ldap.py


示例4: test_add_ldap_users

def test_add_ldap_users():
  done = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  done.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    URL = reverse(add_ldap_users)

    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    c = make_logged_in_client('test', is_superuser=True)

    assert_true(c.get(URL))

    response = c.post(URL, dict(server='nonsense', username_pattern='moe', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)

    response = c.post(URL, dict(server='nonsense', username_pattern='bad_name', password1='test', password2='test'))
    assert_true('Could not' in response.context['form'].errors['username_pattern'][0], response)

    # Test wild card
    response = c.post(URL, dict(server='nonsense', username_pattern='*r*', password1='test', password2='test'))
    assert_true('/useradmin/users' in response['Location'], response)

    # Test ignore case
    done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(True))
    User.objects.filter(username='moe').delete()
    assert_false(User.objects.filter(username='Moe').exists())
    assert_false(User.objects.filter(username='moe').exists())
    response = c.post(URL, dict(server='nonsense', username_pattern='Moe', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)
    assert_false(User.objects.filter(username='Moe').exists())
    assert_true(User.objects.filter(username='moe').exists())

    # Test lower case
    done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(True))
    User.objects.filter(username__iexact='Rock').delete()
    assert_false(User.objects.filter(username='Rock').exists())
    assert_false(User.objects.filter(username='rock').exists())
    response = c.post(URL, dict(server='nonsense', username_pattern='rock', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)
    assert_false(User.objects.filter(username='Rock').exists())
    assert_true(User.objects.filter(username='rock').exists())

  finally:
    for finish in done:
      finish()
开发者ID:2013Commons,项目名称:hue,代码行数:56,代码来源:test_ldap.py


示例5: test_ensure_home_directory_add_ldap_users

def test_ensure_home_directory_add_ldap_users():
  URL = reverse(add_ldap_users)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  cluster = pseudo_hdfs4.shared_cluster()
  c = make_logged_in_client(cluster.superuser, is_superuser=True)
  cluster.fs.setuser(cluster.superuser)

  reset = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    assert_true(c.get(URL))

    response = c.post(URL, dict(server='nonsense', username_pattern='moe', password1='test', password2='test'))
    assert_true('/useradmin/users' in response['Location'])
    assert_false(cluster.fs.exists('/user/moe'))

    # Try same thing with home directory creation.
    response = c.post(URL, dict(server='nonsense', username_pattern='curly', password1='test', password2='test', ensure_home_directory=True))
    assert_true('/useradmin/users' in response['Location'])
    assert_true(cluster.fs.exists('/user/curly'))

    response = c.post(URL, dict(server='nonsense', username_pattern='bad_name', password1='test', password2='test'))
    assert_true('Could not' in response.context['form'].errors['username_pattern'][0])
    assert_false(cluster.fs.exists('/user/bad_name'))

    # See if moe, who did not ask for his home directory, has a home directory.
    assert_false(cluster.fs.exists('/user/moe'))

    # Try wild card now
    response = c.post(URL, dict(server='nonsense', username_pattern='*rr*', password1='test', password2='test', ensure_home_directory=True))
    assert_true('/useradmin/users' in response['Location'])
    assert_true(cluster.fs.exists('/user/curly'))
    assert_true(cluster.fs.exists(u'/user/lårry'))
    assert_false(cluster.fs.exists('/user/otherguy'))
  finally:
    # Clean up
    for finish in reset:
      finish()

    if cluster.fs.exists('/user/curly'):
      cluster.fs.rmtree('/user/curly')
    if cluster.fs.exists(u'/user/lårry'):
      cluster.fs.rmtree(u'/user/lårry')
    if cluster.fs.exists('/user/otherguy'):
      cluster.fs.rmtree('/user/otherguy')
开发者ID:neiodavince,项目名称:hue,代码行数:55,代码来源:test_ldap.py


示例6: test_sync_ldap_users_groups

def test_sync_ldap_users_groups():
  URL = reverse(sync_ldap_users_groups)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  c = make_logged_in_client('test', is_superuser=True)

  assert_true(c.get(URL))
  assert_true(c.post(URL))
开发者ID:QLGu,项目名称:hue,代码行数:13,代码来源:test_ldap_deprecated.py


示例7: test_ldap_exception_handling

def test_ldap_exception_handling():
  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  class LdapTestConnectionError(LdapTestConnection):
    def find_users(self, user, find_by_dn=False):
      raise ldap.LDAPError('No such object')
  ldap_access.CACHED_LDAP_CONN = LdapTestConnectionError()

  c = make_logged_in_client('test', is_superuser=True)

  response = c.post(reverse(add_ldap_users), dict(username_pattern='moe', password1='test', password2='test'), follow=True)
  assert_true('There was an error when communicating with LDAP' in response.content, response)
开发者ID:QLGu,项目名称:hue,代码行数:14,代码来源:test_ldap_deprecated.py


示例8: test_useradmin_ldap_user_integration

def test_useradmin_ldap_user_integration():
  done = []
  try:
    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    # Try importing a user
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'lårry', sync_groups=False, import_by_dn=False)
    larry = User.objects.get(username='lårry')
    assert_true(larry.first_name == 'Larry')
    assert_true(larry.last_name == 'Stooge')
    assert_true(larry.email == '[email protected]')
    assert_true(get_profile(larry).creation_method == str(UserProfile.CreationMethod.EXTERNAL))

    # Should be a noop
    sync_ldap_users(ldap_access.CACHED_LDAP_CONN)
    sync_ldap_groups(ldap_access.CACHED_LDAP_CONN)
    assert_equal(User.objects.all().count(), 1)
    assert_equal(Group.objects.all().count(), 0)

    # Make sure that if a Hue user already exists with a naming collision, we
    # won't overwrite any of that user's information.
    hue_user = User.objects.create(username='otherguy', first_name='Different', last_name='Guy')
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'otherguy', sync_groups=False, import_by_dn=False)
    hue_user = User.objects.get(username='otherguy')
    assert_equal(get_profile(hue_user).creation_method, str(UserProfile.CreationMethod.HUE))
    assert_equal(hue_user.first_name, 'Different')

    # Make sure LDAP groups exist or they won't sync
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=False, import_members_recursive=False, sync_users=False, import_by_dn=False)
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'Test Administrators', import_members=False, import_members_recursive=False, sync_users=False, import_by_dn=False)
    # Try importing a user and sync groups
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'curly', sync_groups=True, import_by_dn=False)
    curly = User.objects.get(username='curly')
    assert_equal(curly.first_name, 'Curly')
    assert_equal(curly.last_name, 'Stooge')
    assert_equal(curly.email, '[email protected]')
    assert_equal(get_profile(curly).creation_method, str(UserProfile.CreationMethod.EXTERNAL))
    assert_equal(2, curly.groups.all().count(), curly.groups.all())

    reset_all_users()
    reset_all_groups()
  finally:
    for finish in done:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:48,代码来源:test_ldap_deprecated.py


示例9: test_ensure_home_directory_add_ldap_users

def test_ensure_home_directory_add_ldap_users():
  try:
    URL = reverse(add_ldap_users)

    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    cluster = pseudo_hdfs4.shared_cluster()
    c = make_logged_in_client(cluster.superuser, is_superuser=True)
    cluster.fs.setuser(cluster.superuser)

    assert_true(c.get(URL))

    response = c.post(URL, dict(username_pattern='moe', password1='test', password2='test'))
    assert_true('/useradmin/users' in response['Location'])
    assert_false(cluster.fs.exists('/user/moe'))

    # Try same thing with home directory creation.
    response = c.post(URL, dict(username_pattern='curly', password1='test', password2='test', ensure_home_directory=True))
    assert_true('/useradmin/users' in response['Location'])
    assert_true(cluster.fs.exists('/user/curly'))

    response = c.post(URL, dict(username_pattern='bad_name', password1='test', password2='test'))
    assert_true('Could not' in response.context['form'].errors['username_pattern'][0])
    assert_false(cluster.fs.exists('/user/bad_name'))

    # See if moe, who did not ask for his home directory, has a home directory.
    assert_false(cluster.fs.exists('/user/moe'))

    # Try wild card now
    response = c.post(URL, dict(username_pattern='*rr*', password1='test', password2='test', ensure_home_directory=True))
    assert_true('/useradmin/users' in response['Location'])
    assert_true(cluster.fs.exists('/user/curly'))
    assert_true(cluster.fs.exists(u'/user/lårry'))
    assert_false(cluster.fs.exists('/user/otherguy'))
  finally:
    # Clean up
    if cluster.fs.exists('/user/curly'):
      cluster.fs.rmtree('/user/curly')
    if cluster.fs.exists(u'/user/lårry'):
      cluster.fs.rmtree(u'/user/lårry')
    if cluster.fs.exists('/user/otherguy'):
      cluster.fs.rmtree('/user/otherguy')
开发者ID:QLGu,项目名称:hue,代码行数:46,代码来源:test_ldap_deprecated.py


示例10: test_ensure_home_directory_sync_ldap_users_groups

def test_ensure_home_directory_sync_ldap_users_groups():
  URL = reverse(sync_ldap_users_groups)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  cluster = pseudo_hdfs4.shared_cluster()
  c = make_logged_in_client(cluster.superuser, is_superuser=True)
  cluster.fs.setuser(cluster.superuser)

  c.post(reverse(add_ldap_users), dict(username_pattern='curly', password1='test', password2='test'))
  assert_false(cluster.fs.exists('/user/curly'))
  assert_true(c.post(URL, dict(ensure_home_directory=True)))
  assert_true(cluster.fs.exists('/user/curly'))
开发者ID:QLGu,项目名称:hue,代码行数:17,代码来源:test_ldap_deprecated.py


示例11: test_useradmin_ldap_user_group_membership_sync

def test_useradmin_ldap_user_group_membership_sync():
  settings.MIDDLEWARE_CLASSES.append('useradmin.middleware.LdapSynchronizationMiddleware')

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  try:
    # Import curly who is part of TestUsers and Test Administrators
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'curly', sync_groups=False, import_by_dn=False)

    # Set a password so that we can login
    user = User.objects.get(username='curly')
    user.set_password('test')
    user.save()

    # Should have 0 groups
    assert_equal(0, user.groups.all().count())

    # Make an authenticated request as curly so that we can see call middleware.
    c = make_logged_in_client('curly', 'test', is_superuser=False)
    grant_access("curly", "test", "useradmin")
    response = c.get('/useradmin/users')

    # Refresh user groups
    user = User.objects.get(username='curly')

    # Should have 3 groups now. 2 from LDAP and 1 from 'grant_access' call.
    assert_equal(3, user.groups.all().count(), user.groups.all())

    # Now remove a group and try again.
    old_group = ldap_access.CACHED_LDAP_CONN._instance.users['curly']['groups'].pop()

    # Make an authenticated request as curly so that we can see call middleware.
    response = c.get('/useradmin/users')

    # Refresh user groups
    user = User.objects.get(username='curly')

    # Should have 2 groups now. 1 from LDAP and 1 from 'grant_access' call.
    assert_equal(3, user.groups.all().count(), user.groups.all())
  finally:
    settings.MIDDLEWARE_CLASSES.remove('useradmin.middleware.LdapSynchronizationMiddleware')
开发者ID:OpenPOWER-BigData,项目名称:HDP-hue,代码行数:45,代码来源:test_ldap_deprecated.py


示例12: test_add_ldap_groups

def test_add_ldap_groups():
  URL = reverse(add_ldap_groups)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  c = make_logged_in_client(username='test', is_superuser=True)

  reset = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:

    assert_true(c.get(URL))

    response = c.post(URL, dict(server='nonsense', groupname_pattern='TestUsers'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/groups' in response['Location'])

    # Test with space
    response = c.post(URL, dict(server='nonsense', groupname_pattern='Test Administrators'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/groups' in response['Location'], response)

    response = c.post(URL, dict(server='nonsense', groupname_pattern='toolongnametoolongnametoolongnametoolongname'
                                                                     'toolongnametoolongnametoolongnametoolongname'
                                                                     'toolongnametoolongnametoolongnametoolongname'
                                                                     'toolongnametoolongnametoolongnametoolongname'
                                                                     'toolongnametoolongnametoolongnametoolongname'
                                                                     'toolongnametoolongnametoolongnametoolongname'))
    assert_true('Ensure this value has at most 256 characters' in response.context['form'].errors['groupname_pattern'][0], response)

    # Test wild card
    response = c.post(URL, dict(server='nonsense', groupname_pattern='*r*'))
    assert_true('/useradmin/groups' in response['Location'], response)
  finally:
    for finish in reset:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:44,代码来源:test_ldap.py


示例13: test_add_ldap_users

def test_add_ldap_users():
  done = []
  try:
    URL = reverse(add_ldap_users)

    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    c = make_logged_in_client('test', is_superuser=True)

    assert_true(c.get(URL))

    response = c.post(URL, dict(username_pattern='moe', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)

    response = c.post(URL, dict(username_pattern='bad_name', password1='test', password2='test'))
    assert_true('Could not' in response.context['form'].errors['username_pattern'][0], response)

    # Test wild card
    response = c.post(URL, dict(username_pattern='*rr*', password1='test', password2='test'))
    assert_true('/useradmin/users' in response['Location'], response)

    # Test regular with spaces (should fail)
    response = c.post(URL, dict(username_pattern='user with space', password1='test', password2='test'))
    assert_true("Username must not contain whitespaces and ':'" in response.context['form'].errors['username_pattern'][0], response)

    # Test dn with spaces in username and dn (should fail)
    response = c.post(URL, dict(username_pattern='uid=user with space,ou=People,dc=example,dc=com', password1='test', password2='test', dn=True))
    assert_true("Could not get LDAP details for users in pattern" in response.content, response)
    response = c.get(reverse(desktop.views.log_view))
    assert_true("{username}: Username must not contain whitespaces".format(username='user with space') in response.content, response.content)

    # Test dn with spaces in dn, but not username (should succeed)
    response = c.post(URL, dict(username_pattern='uid=user without space,ou=People,dc=example,dc=com', password1='test', password2='test', dn=True))
    assert_true(User.objects.filter(username='spaceless').exists())

  finally:
    for finish in done:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:43,代码来源:test_ldap_deprecated.py


示例14: test_add_ldap_users_case_sensitivity

def test_add_ldap_users_case_sensitivity():
  if is_live_cluster():
    raise SkipTest('HUE-2897: Cannot yet guarantee database is case sensitive')

  done = []
  try:
    URL = reverse(add_ldap_users)

    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    c = make_logged_in_client('test', is_superuser=True)

    # Test ignore case
    done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(True))
    User.objects.filter(username='moe').delete()
    assert_false(User.objects.filter(username='Moe').exists())
    assert_false(User.objects.filter(username='moe').exists())
    response = c.post(URL, dict(username_pattern='Moe', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)
    assert_false(User.objects.filter(username='Moe').exists())
    assert_true(User.objects.filter(username='moe').exists())

    # Test lower case
    done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(True))
    User.objects.filter(username__iexact='Rock').delete()
    assert_false(User.objects.filter(username='Rock').exists())
    assert_false(User.objects.filter(username='rock').exists())
    response = c.post(URL, dict(username_pattern='rock', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)
    assert_false(User.objects.filter(username='Rock').exists())
    assert_true(User.objects.filter(username='rock').exists())
  finally:
    for finish in done:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:40,代码来源:test_ldap_deprecated.py


示例15: test_sync_ldap_users_groups

def test_sync_ldap_users_groups():
  URL = reverse(sync_ldap_users_groups)

  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  c = make_logged_in_client('test', is_superuser=True)

  reset = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    assert_true(c.get(URL))
    assert_true(c.post(URL))
  finally:
    for finish in reset:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:23,代码来源:test_ldap.py


示例16: test_useradmin_ldap_case_sensitivity

def test_useradmin_ldap_case_sensitivity():
  if is_live_cluster():
    raise SkipTest('HUE-2897: Cannot yet guarantee database is case sensitive')

  done = []
  try:
    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    # Test import case sensitivity
    done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(True))
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Lårry', sync_groups=False, import_by_dn=False)
    assert_false(User.objects.filter(username='Lårry').exists())
    assert_true(User.objects.filter(username='lårry').exists())

    # Test lower case
    User.objects.filter(username__iexact='Rock').delete()
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
    assert_false(User.objects.filter(username='Rock').exists())
    assert_true(User.objects.filter(username='rock').exists())

    done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(True))

    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
    assert_false(User.objects.filter(username='Rock').exists())
    assert_true(User.objects.filter(username='rock').exists())

    User.objects.filter(username='Rock').delete()
    import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
    assert_false(User.objects.filter(username='Rock').exists())
    assert_true(User.objects.filter(username='rock').exists())
  finally:
    for finish in done:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:37,代码来源:test_ldap_deprecated.py


示例17: test_ldap_exception_handling

def test_ldap_exception_handling():
  reset_all_users()
  reset_all_groups()

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  class LdapTestConnectionError(LdapTestConnection):
    def find_users(self, user, find_by_dn=False):
      raise ldap.LDAPError('No such object')
  ldap_access.CACHED_LDAP_CONN = LdapTestConnectionError()

  c = make_logged_in_client('test', is_superuser=True)

  reset = []

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    response = c.post(reverse(add_ldap_users), dict(server='nonsense', username_pattern='moe', password1='test', password2='test'), follow=True)
    assert_true('There was an error when communicating with LDAP' in response.content, response)
  finally:
    for finish in reset:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:24,代码来源:test_ldap.py


示例18: test_useradmin_ldap_nested_group_integration

def test_useradmin_ldap_nested_group_integration():
  if is_live_cluster():
    raise SkipTest('HUE-2897: Skipping because DB may not support unicode')

  reset_all_users()
  reset_all_groups()

  reset = []

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  # Test old subgroups
  reset.append(desktop.conf.LDAP.SUBGROUPS.set_for_testing("nested"))

  # Set to nonsensical value just to force new config usage.
  # Should continue to use cached connection.
  reset.append(desktop.conf.LDAP.LDAP_SERVERS.set_for_testing(get_nonsense_config()))

  try:
    # Import groups only
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=False, import_members_recursive=False, sync_users=False, import_by_dn=False)
    test_users = Group.objects.get(name='TestUsers')
    assert_true(LdapGroup.objects.filter(group=test_users).exists())
    assert_equal(test_users.user_set.all().count(), 0)

    # Import all members of TestUsers
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=True, import_members_recursive=False, sync_users=True, import_by_dn=False)
    test_users = Group.objects.get(name='TestUsers')
    assert_true(LdapGroup.objects.filter(group=test_users).exists())
    assert_equal(test_users.user_set.all().count(), 3)

    # Should import a group, but will only sync already-imported members
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'Test Administrators', import_members=False, import_members_recursive=False, sync_users=True, import_by_dn=False)
    assert_equal(User.objects.all().count(), 3)
    assert_equal(Group.objects.all().count(), 2)
    test_admins = Group.objects.get(name='Test Administrators')
    assert_equal(test_admins.user_set.all().count(), 2)
    larry = User.objects.get(username='lårry')
    assert_equal(test_admins.user_set.all()[0].username, larry.username)

    # Only sync already imported
    assert_equal(test_users.user_set.all().count(), 3)
    ldap_access.CACHED_LDAP_CONN.remove_user_group_for_test('uid=moe,ou=People,dc=example,dc=com', 'TestUsers')
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=False, import_members_recursive=False, sync_users=True, import_by_dn=False)
    assert_equal(test_users.user_set.all().count(), 2)
    assert_equal(User.objects.get(username='moe').groups.all().count(), 0)

    # Import missing user
    ldap_access.CACHED_LDAP_CONN.add_user_group_for_test('uid=moe,ou=People,dc=example,dc=com', 'TestUsers')
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=True, import_members_recursive=False, sync_users=True, import_by_dn=False)
    assert_equal(test_users.user_set.all().count(), 3)
    assert_equal(User.objects.get(username='moe').groups.all().count(), 1)

    # Import all members of TestUsers and not members of suboordinate groups (even though specified)
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=True, import_members_recursive=True, sync_users=True, import_by_dn=False)
    test_users = Group.objects.get(name='TestUsers')
    assert_true(LdapGroup.objects.filter(group=test_users).exists())
    assert_equal(test_users.user_set.all().count(), 3)

    # Nested group import
    # First without recursive import, then with.
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'NestedGroups', import_members=True, import_members_recursive=False, sync_users=True, import_by_dn=False)
    nested_groups = Group.objects.get(name='NestedGroups')
    nested_group = Group.objects.get(name='NestedGroup')
    assert_true(LdapGroup.objects.filter(group=nested_groups).exists())
    assert_true(LdapGroup.objects.filter(group=nested_group).exists())
    assert_equal(nested_groups.user_set.all().count(), 0, nested_groups.user_set.all())
    assert_equal(nested_group.user_set.all().count(), 0, nested_group.user_set.all())

    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'NestedGroups', import_members=True, import_members_recursive=True, sync_users=True, import_by_dn=False)
    nested_groups = Group.objects.get(name='NestedGroups')
    nested_group = Group.objects.get(name='NestedGroup')
    assert_true(LdapGroup.objects.filter(group=nested_groups).exists())
    assert_true(LdapGroup.objects.filter(group=nested_group).exists())
    assert_equal(nested_groups.user_set.all().count(), 0, nested_groups.user_set.all())
    assert_equal(nested_group.user_set.all().count(), 1, nested_group.user_set.all())

    # Make sure Hue groups with naming collisions don't get marked as LDAP groups
    hue_user = User.objects.create(username='otherguy', first_name='Different', last_name='Guy')
    hue_group = Group.objects.create(name='OtherGroup')
    hue_group.user_set.add(hue_user)
    hue_group.save()
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'OtherGroup', import_members=False, import_members_recursive=False, sync_users=True, import_by_dn=False)
    assert_false(LdapGroup.objects.filter(group=hue_group).exists())
    assert_true(hue_group.user_set.filter(username=hue_user.username).exists())
  finally:
    for finish in reset:
      finish()
开发者ID:neiodavince,项目名称:hue,代码行数:89,代码来源:test_ldap.py


示例19: test_add_ldap_users

def test_add_ldap_users():
  done = []
  try:
    URL = reverse(add_ldap_users)

    reset_all_users()
    reset_all_groups()

    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

    c = make_logged_in_client('test', is_superuser=True)

    assert_true(c.get(URL))

    response = c.post(URL, dict(username_pattern='moe', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)

    response = c.post(URL, dict(username_pattern='bad_name', password1='test', password2='test'))
    assert_true('Could not' in response.context['form'].errors['username_pattern'][0], response)

    # Test wild card
    response = c.post(URL, dict(username_pattern='*rr*', password1='test', password2='test'))
    assert_true('/useradmin/users' in response['Location'], response)

    # Test ignore case
    done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(True))
    User.objects.filter(username='moe').delete()
    assert_false(User.objects.filter(username='Moe').exists())
    assert_false(User.objects.filter(username='moe').exists())
    response = c.post(URL, dict(username_pattern='Moe', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)
    assert_false(User.objects.filter(username='Moe').exists())
    assert_true(User.objects.filter(username='moe').exists())

    # Test lower case
    done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(True))
    User.objects.filter(username__iexact='Rock').delete()
    assert_false(User.objects.filter(username='Rock').exists())
    assert_false(User.objects.filter(username='rock').exists())
    response = c.post(URL, dict(username_pattern='rock', password1='test', password2='test'))
    assert_true('Location' in response, response)
    assert_true('/useradmin/users' in response['Location'], response)
    assert_false(User.objects.filter(username='Rock').exists())
    assert_true(User.objects.filter(username='rock').exists())

    # Test regular with spaces (should fail)
    response = c.post(URL, dict(username_pattern='user with space', password1='test', password2='test'))
    assert_true("Username must not contain whitespaces and ':'" in response.context['form'].errors['username_pattern'][0], response)

    # Test dn with spaces in username and dn (should fail)
    response = c.post(URL, dict(username_pattern='uid=user with space,ou=People,dc=example,dc=com', password1='test', password2='test', dn=True))
    assert_true("There was a problem with some of the LDAP information" in response.content, response)
    assert_true("Username must not contain whitespaces" in response.content, response)

    # Test dn with spaces in dn, but not username (should succeed)
    response = c.post(URL, dict(username_pattern='uid=user without space,ou=People,dc=example,dc=com', password1='test', password2='test', dn=True))
    assert_true(User.objects.filter(username='spaceless').exists())

  finally:
    for finish in done:
      finish()
开发者ID:QLGu,项目名称:hue,代码行数:64,代码来源:test_ldap_deprecated.py


示例20: test_useradmin_ldap_suboordinate_group_integration

def test_useradmin_ldap_suboordinate_group_integration():
  reset_all_users()
  reset_all_groups()

  reset = []

  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

  # Test old subgroups
  reset.append(desktop.conf.LDAP.SUBGROUPS.set_for_testing("suboordinate"))

  try:
    # Import groups only
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=False, import_members_recursive=False, sync_users=False, import_by_dn=False)
    test_users = Group.objects.get(name='TestUsers')
    assert_true(LdapGroup.objects.filter(group=test_users).exists())
    assert_equal(test_users.user_set.all().count(), 0)

    # Import all members of TestUsers
    import_ldap_groups(ldap_access.CACHED_LDAP_CONN, 'TestUsers', import_members=True, import_members_recursive=False, sync_users=True, import_by_dn=False)
    test_users = Group.objects.get(name='TestUsers')
    assert_true(LdapGroup.objects.filter(group=test_users).exists())
    assert_equal(test_users.user_set.all().count(), 3)

    # Should import a group, but will only sync already-imported members
    import_ldap_groups(ldap_ 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tests.run_isolated函数代码示例发布时间:2022-05-27
下一篇:
Python tests.reset_all_groups函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap