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

Python views.import_ldap_users函数代码示例

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

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



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

示例1: process_request

  def process_request(self, request):
    user = request.user
    server = None

    # Used by tests only
    if request.method == "GET":
      server = request.GET.get('server')

    if not user or not user.is_authenticated():
      return

    if not User.objects.filter(username=user.username, userprofile__creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
      LOG.warn("User %s is not an Ldap user" % user.username)
      return

    # Cache should be cleared when user logs out.
    if self.USER_CACHE_NAME not in request.session:
      if LDAP.LDAP_SERVERS.get():
        connection = ldap_access.get_connection_from_server(next(LDAP.LDAP_SERVERS.__iter__()))
      else:
        connection = ldap_access.get_connection_from_server()

      import_ldap_users(connection, user.username, sync_groups=True, import_by_dn=False, server=server)

      request.session[self.USER_CACHE_NAME] = True
      request.session.modified = True
开发者ID:cloudera,项目名称:hue,代码行数:26,代码来源:middleware.py


示例2: test_useradmin_ldap_force_uppercase

  def test_useradmin_ldap_force_uppercase(self):
    if is_live_cluster():
      raise SkipTest('HUE-2897: Skipping because the DB may not be case sensitive')

    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:
      # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
      ldap_access.CACHED_LDAP_CONN = LdapTestConnection()

      # Test upper case
      User.objects.filter(username__iexact='Rock').delete()
      done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(False))
      done.append(desktop.conf.LDAP.FORCE_USERNAME_LOWERCASE.set_for_testing(False))
      done.append(desktop.conf.LDAP.FORCE_USERNAME_UPPERCASE.set_for_testing(True))

      import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'Rock', sync_groups=False, import_by_dn=False)
      assert_true(User.objects.filter(username='ROCK').exists())
    finally:
      for finish in done:
        finish()
开发者ID:10sr,项目名称:hue,代码行数:25,代码来源:test_ldap.py


示例3: test_useradmin_ldap_integration

def test_useradmin_ldap_integration():
  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('larry', import_by_dn=False)
  larry = User.objects.get(username='larry')
  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()
  sync_ldap_groups()
  assert_equal(len(User.objects.all()), 1)
  assert_equal(len(Group.objects.all()), 0)

  # Should import a group, but will only sync already-imported members
  import_ldap_groups('Test Administrators', import_members=False, import_by_dn=False)
  assert_equal(len(User.objects.all()), 1)
  assert_equal(len(Group.objects.all()), 1)
  test_admins = Group.objects.get(name='Test Administrators')
  assert_equal(len(test_admins.user_set.all()), 1)
  assert_equal(test_admins.user_set.all()[0].username, larry.username)

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

  ldap_access.CACHED_LDAP_CONN.remove_user_group_for_test('moe', 'TestUsers')
  import_ldap_groups('TestUsers', import_members=False, import_by_dn=False)
  assert_equal(len(test_users.user_set.all()), 2)
  assert_equal(len(User.objects.get(username='moe').groups.all()), 0)

  ldap_access.CACHED_LDAP_CONN.add_user_group_for_test('moe', 'TestUsers')
  import_ldap_groups('TestUsers', import_members=False, import_by_dn=False)
  assert_equal(len(test_users.user_set.all()), 3)
  assert_equal(len(User.objects.get(username='moe').groups.all()), 1)

  # 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('otherguy', 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 Hue groups with naming collisions don't get marked as LDAP groups
  hue_group = Group.objects.create(name='OtherGroup')
  hue_group.user_set.add(hue_user)
  hue_group.save()
  import_ldap_groups('OtherGroup', import_members=False, 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())
开发者ID:icheckmate,项目名称:hue,代码行数:60,代码来源:tests.py


示例4: test_useradmin_ldap_user_integration

def test_useradmin_ldap_user_integration():
  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('larry', import_by_dn=False)
  larry = User.objects.get(username='larry')
  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()
  sync_ldap_groups()
  assert_equal(len(User.objects.all()), 1)
  assert_equal(len(Group.objects.all()), 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('otherguy', 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')
开发者ID:joey,项目名称:hue,代码行数:28,代码来源:tests.py


示例5: 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


示例6: test_useradmin_ldap_user_group_membership_sync

def test_useradmin_ldap_user_group_membership_sync():
    reset = [
        desktop.conf.AUTH.USER_GROUP_MEMBERSHIP_SYNCHRONIZATION_BACKEND.set_for_testing(
            "desktop.auth.backend.LdapSynchronizationBackend"
        )
    ]
    settings.MIDDLEWARE_CLASSES.append("desktop.middleware.UserGroupSynchronizationMiddleware")

    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("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:
        for finish in reset:
            finish()
        settings.MIDDLEWARE_CLASSES.remove("desktop.middleware.UserGroupSynchronizationMiddleware")
开发者ID:ronglei,项目名称:hue,代码行数:52,代码来源:tests.py


示例7: test_useradmin_ldap_case_sensitivity

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

    done = []
    try:
      # 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:mapr,项目名称:hue,代码行数:34,代码来源:test_ldap_deprecated.py


示例8: 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('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:Web5design,项目名称:hue,代码行数:45,代码来源:tests.py


示例9: process_request

  def process_request(self, request):
    user = request.user

    if not user or not user.is_authenticated():
      return

    if not User.objects.filter(username=user.username, userprofile__creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():
      LOG.warn("User %s is not an Ldap user" % user.username)
      return

    # Cache should be cleared when user logs out.
    if self.USER_CACHE_NAME not in request.session:
      request.session[self.USER_CACHE_NAME] = import_ldap_users(user.username, sync_groups=True, import_by_dn=False)
      request.session.modified = True
开发者ID:Web5design,项目名称:hue,代码行数:14,代码来源:middleware.py


示例10: test_useradmin_ldap_user_integration

def test_useradmin_ldap_user_integration():
  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('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()
  sync_ldap_groups()
  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('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')

  # Try importing a user and sync groups
  import_ldap_users('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()

  # Test import case sensitivity
  reset = desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(True)
  import_ldap_users('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())
  reset()
开发者ID:elisbyberi,项目名称:hue,代码行数:47,代码来源:tests.py


示例11: 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


示例12: test_useradmin_ldap_user_integration

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

  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:
    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()

    # 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,代码行数:79,代码来源:test_ldap.py


示例13: 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("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()
        sync_ldap_groups()
        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("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")

        # Try importing a user and sync groups
        import_ldap_users("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()

        # Test import case sensitivity
        done.append(desktop.conf.LDAP.IGNORE_USERNAME_CASE.set_for_testing(True))
        import_ldap_users("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("Rock", sync_groups=False, import_by_dn=False)
        assert_true(User.objects.filter(username="Rock").exists())
        assert_false(User.objects.filter(username="rock").exists())

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

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

        User.objects.filter(username="Rock").delete()
        import_ldap_users("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:jekey,项目名称:hue,代码行数:68,代码来源:tests.py



注:本文中的views.import_ldap_users函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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