Exemplo n.º 1
0
def test_user_merge_access_approved(admin_index_request, django_user_model):
    run_minikube_sync()
    primary = django_user_model(
        username="******",
        email="*****@*****.**")
    primary.save()

    ns = KubernetesNamespace(name="default")
    ns.save()
    new_svc = KubernetesServiceAccount(name="foobar", namespace=ns)
    new_svc.save()
    secondary = django_user_model(
        username="******",
        state=User.ACCESS_APPROVED,
        email="*****@*****.**",
        comments="secondary user comment",
        service_account=new_svc)
    secondary.save()

    group1 = PortalGroup(name="testgroup1")
    group1.save()
    group2 = PortalGroup(name="testgroup2")
    group2.save()

    secondary.portal_groups.add(group1)
    secondary.portal_groups.add(group2)
    secondary.save()

    # Build full-fledged request object for logged-in admin
    # approve secondary for cluster access
    secondary.approve(admin_index_request, new_svc)

    # the merge method only accepts a queryset of users since that's what
    # the admin interface creates
    queryset_of_users = django_user_model.objects.filter(
        pk__in=[primary.id, secondary.id])

    # merge both users. shouldn't return anything
    assert(not merge_users(UserAdmin, admin_index_request, queryset_of_users))

    # the primary user has been altered but the old object is still in memory
    # we need to query for the updated user again
    primary = django_user_model.objects.get(pk=primary.id)

    # Does primary have all the values of secondary user?
    assert primary.comments == "secondary user comment"
    assert primary.portal_groups.filter(name=group1.name)
    assert primary.portal_groups.filter(name=group2.name)
    assert primary.has_access_approved
Exemplo n.º 2
0
    def test_user_merge_access_rejected(self):
        request = self._build_full_request_mock('admin:index')

        User = get_user_model()
        primary = User(username="******", email="*****@*****.**")
        primary.save()

        ns = KubernetesNamespace(name="default")
        ns.save()

        new_svc = KubernetesServiceAccount(name="foobar", namespace=ns)
        new_svc.save()
        # Perform approval
        assert (primary.approve(request, new_svc))
        primary.save()

        secondary = User(username="******",
                         state=models.UserState.ACCESS_APPROVED,
                         email="*****@*****.**",
                         comments="secondary user comment",
                         service_account=new_svc)
        secondary.save()

        # Build full-fledged request object for logged-in admin
        request = self._build_full_request_mock('admin:index')
        # reject cluster access for secondary
        secondary.reject(request)

        # the merge method only accepts a queryset of users since that's what
        # the admin interface creates
        queryset_of_users = User.objects.filter(
            pk__in=[primary.id, secondary.id])

        # merge both users. shouldn't return anything
        assert (not merge_users(UserAdmin, request, queryset_of_users))

        # the primary user has been altered but the old object is still in memory
        # we need to query for the updated user again
        primary = User.objects.get(pk=primary.id)

        assert (primary.has_access_rejected)
Exemplo n.º 3
0
def test_user_merge_access_rejected(admin_index_request, django_user_model, random_namespace_name):
    run_minikube_sync()
    primary = django_user_model(
        username="******",
        email="*****@*****.**")
    primary.save()

    ns = KubernetesNamespace(name=random_namespace_name)
    ns.save()

    new_svc = KubernetesServiceAccount(name="foobar", namespace=ns)
    new_svc.save()
    # Perform approval
    assert(primary.approve(admin_index_request, new_svc))

    secondary = django_user_model(
        username="******",
        state=User.ACCESS_APPROVED,
        email="*****@*****.**",
        comments="secondary user comment",
        service_account=new_svc)
    secondary.save()

    # reject cluster access for secondary
    secondary.reject(admin_index_request)

    # the merge method only accepts a queryset of users since that's what
    # the admin interface creates
    queryset_of_users = django_user_model.objects.filter(
        pk__in=[primary.id, secondary.id])

    # merge both users. shouldn't return anything
    assert(not merge_users(UserAdmin, admin_index_request, queryset_of_users))

    # the primary user has been altered but the old object is still in memory
    # we need to query for the updated user again
    primary = django_user_model.objects.get(pk=primary.id)

    assert primary.has_access_rejected