Пример #1
0
def _with_temp_user(fn):
    """
    Runs a function in the context of a newly created user.
    It will cleanup the user after fn is run, unless it
    has already been deleted.

    fn - A callable function. First parameter should be
    a unique_id string.
    """
    regi = RegistrarSession.connect(
        _mock_request('/en-US/search?q=David'))
    username = '******' % str(uuid4())[0:8]
    data = dict(first_name='Jane', last_name='Doe',
                email=username, password='******',
                biography='Keeping it real.',
                         irc_nickname='',
                         irc_nickname_unique_id='')
    new_unique_id = regi.create_person(data)
    fn(new_unique_id)

    directory = UserSession.connect(_mock_request('/en-US/search?q=David'))
    try:
        directory.get_by_unique_id(new_unique_id)

        admin = AdminSession.connect(_mock_request('/en-US/search?q=David'))
        admin.delete_person(new_unique_id)
    except:
        pass
    finally:
        pass
Пример #2
0
def _with_temp_user(fn):
    """
    Runs a function in the context of a newly created user.
    It will cleanup the user after fn is run, unless it
    has already been deleted.

    fn - A callable function. First parameter should be
    a unique_id string.
    """
    regi = RegistrarSession.connect(_mock_request('/en-US/search?q=David'))
    username = '******' % str(uuid4())[0:8]
    data = dict(first_name='Jane',
                last_name='Doe',
                email=username,
                password='******',
                biography='Keeping it real.',
                irc_nickname='',
                irc_nickname_unique_id='')
    new_unique_id = regi.create_person(data)
    fn(new_unique_id)

    directory = UserSession.connect(_mock_request('/en-US/search?q=David'))
    try:
        directory.get_by_unique_id(new_unique_id)

        admin = AdminSession.connect(_mock_request('/en-US/search?q=David'))
        admin.delete_person(new_unique_id)
    except:
        pass
    finally:
        pass
Пример #3
0
    def test_connection_pooling(self):
        # Don't use _mock_request, nor TestLarper since we want full control
        # over the request to find pooling bugs
        rf = RequestFactory()
        request = rf.get('/en-US')
        request.session = {}
        request.user = MockUser('*****@*****.**', '7f3a67u000001')

        larper.store_password(request, 'secret')

        R = larper.READ
        W = larper.WRITE

        directory = UserSession.connect(request)
        self.assertFalse(hasattr(request, 'larper_conns'))

        regi = RegistrarSession.connect(request)
        self.assertFalse(hasattr(request, 'larper_conns'))

        regi_W_conn = regi._ensure_conn(W)
        regi_W_conn2 = regi._ensure_conn(W)

        self.assertIs(regi_W_conn, regi_W_conn2)
        self.assertTrue(hasattr(request, 'larper_conns'))
        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 1)

        dir_W_conn = directory._ensure_conn(W)
        dir_W_conn2 = directory._ensure_conn(W)

        self.assertIs(dir_W_conn, dir_W_conn2)
        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 2)

        dir_R_conn = directory._ensure_conn(R)

        admin = AdminSession.connect(request)
        admin_R_conn = admin._ensure_conn(R)
        admin_R_conn2 = admin._ensure_conn(R)
        admin_W_conn = admin._ensure_conn(W)

        self.assertIs(admin_R_conn, admin_R_conn2)
        self.assertIsNot(admin_R_conn, admin_W_conn)

        for conn in (regi_W_conn, dir_R_conn, admin_R_conn, admin_W_conn):
            # nor is it dir_R_conn2 or admin_R_conn2
            self.assertIsNot(dir_W_conn, conn)

        self.assertEqual(len(request.larper_conns[R].keys()), 2)
        self.assertEqual(len(request.larper_conns[W].keys()), 3)

        directory.disconnect(request)

        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 0)
Пример #4
0
    def test_connection_pooling(self):
        # Don't use _mock_request, nor TestLarper since we want full control
        # over the request to find pooling bugs
        rf = RequestFactory()
        request = rf.get('/en-US')
        request.session = {}
        request.user = MockUser('*****@*****.**', '7f3a67u000001')

        larper.store_password(request, 'secret')

        R = larper.READ
        W = larper.WRITE

        directory = UserSession.connect(request)
        self.assertFalse(hasattr(request, 'larper_conns'))

        regi = RegistrarSession.connect(request)
        self.assertFalse(hasattr(request, 'larper_conns'))

        regi_W_conn = regi._ensure_conn(W)
        regi_W_conn2 = regi._ensure_conn(W)

        self.assertIs(regi_W_conn, regi_W_conn2)
        self.assertTrue(hasattr(request, 'larper_conns'))
        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 1)

        dir_W_conn = directory._ensure_conn(W)
        dir_W_conn2 = directory._ensure_conn(W)

        self.assertIs(dir_W_conn, dir_W_conn2)
        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 2)

        dir_R_conn = directory._ensure_conn(R)

        admin = AdminSession.connect(request)
        admin_R_conn = admin._ensure_conn(R)
        admin_R_conn2 = admin._ensure_conn(R)
        admin_W_conn = admin._ensure_conn(W)

        self.assertIs(admin_R_conn, admin_R_conn2)
        self.assertIsNot(admin_R_conn, admin_W_conn)

        for conn in (regi_W_conn, dir_R_conn, admin_R_conn, admin_W_conn):
            # nor is it dir_R_conn2 or admin_R_conn2
            self.assertIsNot(dir_W_conn, conn)

        self.assertEqual(len(request.larper_conns[R].keys()), 2)
        self.assertEqual(len(request.larper_conns[W].keys()), 3)

        directory.disconnect(request)

        self.assertEqual(len(request.larper_conns[R].keys()), 0)
        self.assertEqual(len(request.larper_conns[W].keys()), 0)
Пример #5
0
def delete(request):
    form = forms.DeleteForm(request.POST)
    if form.is_valid() and _user_owns_account(request, form):
        admin_ldap = AdminSession.connect(request)
        admin_ldap.delete_person(form.cleaned_data['unique_id'])
        django.contrib.auth.logout(request)
    else:
        msg = "Unauthorized deletion of account, attempted"
        raise UNAUTHORIZED_DELETE(msg)

    return redirect('home')
Пример #6
0
def delete(request):
    form = forms.DeleteForm(request.POST)
    if form.is_valid() and _user_owns_account(request, form):
        admin_ldap = AdminSession.connect(request)
        admin_ldap.delete_person(form.cleaned_data['unique_id'])
        django.contrib.auth.logout(request)
    else:
        msg = "Unauthorized deletion of account, attempted"
        raise UNAUTHORIZED_DELETE(msg)

    return redirect(reverse('home'))
Пример #7
0
    def test_create_then_delete_person(self):
        regi = self.d = RegistrarSession.connect(
            _mock_request('/en-US/search?q=David'))
        username = '******' % str(uuid4())[0:8]
        data = dict(first_name='Jane', last_name='Doe',
                    email=username, password='******',
                    biography='Keeping it real.',
                         irc_nickname='hobart',
                         irc_nickname_unique_id='')
        new_unique_id = regi.create_person(data)

        directory = UserSession.connect(
            _mock_request('/en-US/search?q=David'))
        newbie = directory.get_by_unique_id(new_unique_id)
        eq_(username, newbie.username)

        admin = AdminSession.connect(
            _mock_request('/en-US/search?q=David'))
        admin.delete_person(new_unique_id)

        self.assertRaises(larper.NO_SUCH_PERSON, lambda:\
                              directory.get_by_unique_id(new_unique_id))
Пример #8
0
    def test_create_then_delete_person(self):
        regi = self.d = RegistrarSession.connect(
            _mock_request('/en-US/search?q=David'))
        username = '******' % str(uuid4())[0:8]
        data = dict(first_name='Jane',
                    last_name='Doe',
                    email=username,
                    password='******',
                    biography='Keeping it real.',
                    irc_nickname='hobart',
                    irc_nickname_unique_id='')
        new_unique_id = regi.create_person(data)

        directory = UserSession.connect(_mock_request('/en-US/search?q=David'))
        newbie = directory.get_by_unique_id(new_unique_id)
        eq_(username, newbie.username)

        admin = AdminSession.connect(_mock_request('/en-US/search?q=David'))
        admin.delete_person(new_unique_id)

        self.assertRaises(larper.NO_SUCH_PERSON, lambda:\
                              directory.get_by_unique_id(new_unique_id))