Beispiel #1
0
    def test_subscriptions(self):
        pagename = u"Foo:foo 123"
        tagname = u"xxx"
        regexp = r"\d+"
        item = Item.create(pagename)
        item._save({NAMESPACE: u"", TAGS: [tagname]})
        item = Item.create(pagename)
        meta = item.meta

        name = u'bar'
        password = name
        email = "*****@*****.**"
        user.create_user(name, password, email)
        the_user = user.User(name=name, password=password)
        assert not the_user.is_subscribed_to(item)
        the_user.subscribe(NAME, u"SomeOtherPageName", u"")
        result = the_user.unsubscribe(NAME, u"OneMorePageName", u"")
        assert result is False

        subscriptions = [(ITEMID, meta[ITEMID], None),
                         (NAME, pagename, meta[NAMESPACE]),
                         (TAGS, tagname, meta[NAMESPACE]),
                         (NAMEPREFIX, pagename[:4], meta[NAMESPACE]),
                         (NAMERE, regexp, meta[NAMESPACE])]
        for subscription in subscriptions:
            keyword, value, namespace = subscription
            the_user.subscribe(keyword, value, namespace)
            assert the_user.is_subscribed_to(item)
            the_user.unsubscribe(keyword, value, namespace, item)
            assert not the_user.is_subscribed_to(item)
Beispiel #2
0
def test_handle_login():
    # no messages in the beginning
    assert not flaskg._login_messages
    test_user1 = handle_login(flaskg.user,
                              login_username='******',
                              login_password='******',
                              stage='moin')
    test_login_message = [u'Invalid username or password.']
    assert flaskg._login_messages == test_login_message
    assert test_user1.name0 == ANON
    assert not test_user1.valid
    # pop the message
    flaskg._login_messages.pop()
    # try with a valid user
    givenauth_obj = GivenAuth()
    flaskg.user.auth_method = 'given'
    givenauth_obj.user_name = u'Test_User'
    create_user(u'Test_User', u'test_pass', u'*****@*****.**')
    test_user, bool_value = givenauth_obj.request(flaskg.user)
    test_user2 = handle_login(test_user,
                              login_username='******',
                              login_password='******',
                              stage='moin')
    assert not flaskg._login_messages
    assert test_user2.name == [
        u'Test_User',
    ]
    assert test_user2.valid
Beispiel #3
0
    def test_subscriptions(self):
        pagename = u"Foo:foo 123"
        tagname = u"xxx"
        regexp = r"\d+"
        item = Item.create(pagename)
        item._save({NAMESPACE: u"", TAGS: [tagname]})
        item = Item.create(pagename)
        meta = item.meta

        name = u'bar'
        password = name
        email = "*****@*****.**"
        user.create_user(name, password, email)
        the_user = user.User(name=name, password=password)
        assert not the_user.is_subscribed_to(item)
        the_user.subscribe(NAME, u"SomeOtherPageName", u"")
        result = the_user.unsubscribe(NAME, u"OneMorePageName", u"")
        assert result is False

        subscriptions = [(ITEMID, meta[ITEMID], None),
                         (NAME, pagename, meta[NAMESPACE]),
                         (TAGS, tagname, meta[NAMESPACE]),
                         (NAMEPREFIX, pagename[:4], meta[NAMESPACE]),
                         (NAMERE, regexp, meta[NAMESPACE])]
        for subscription in subscriptions:
            keyword, value, namespace = subscription
            the_user.subscribe(keyword, value, namespace)
            assert the_user.is_subscribed_to(item)
            the_user.unsubscribe(keyword, value, namespace, item)
            assert not the_user.is_subscribed_to(item)
Beispiel #4
0
 def test_request(self):
     givenauth_obj = GivenAuth()
     flaskg.user.auth_method = 'given'
     givenauth_obj.user_name = u'testDomain\\[email protected]'
     givenauth_obj.strip_maildomain = True
     givenauth_obj.strip_windomain = True
     givenauth_obj.titlecase = True
     givenauth_obj.remove_blanks = True
     create_user(u'Test_User', u'test_pass', u'*****@*****.**')
     test_user, bool_value = givenauth_obj.request(flaskg.user)
     assert test_user.valid
     assert test_user.name == [u'Test_User', ]
Beispiel #5
0
    def test_request(self):
        # create a new user
        create_user(u'ValidUser', u'test_pass', u'test_email@moinmoin')
        httpauthmoin_obj = HTTPAuthMoin()
        test_user, bool_val = httpauthmoin_obj.request(flaskg.user)
        assert test_user.valid
        assert test_user.name == [u'ValidUser', ]
        assert bool_val

        # when auth_method is not 'http'
        flaskg.user.auth_method = 'invalid'
        test_user, bool_val = httpauthmoin_obj.request(flaskg.user)
        assert not test_user.valid
        assert test_user.name0 == ANON
Beispiel #6
0
 def test_request(self):
     givenauth_obj = GivenAuth()
     flaskg.user.auth_method = 'given'
     givenauth_obj.user_name = u'testDomain\\[email protected]'
     givenauth_obj.strip_maildomain = True
     givenauth_obj.strip_windomain = True
     givenauth_obj.titlecase = True
     givenauth_obj.remove_blanks = True
     create_user(u'Test_User', u'test_pass', u'*****@*****.**')
     test_user, bool_value = givenauth_obj.request(flaskg.user)
     assert test_user.valid
     assert test_user.name == [
         u'Test_User',
     ]
Beispiel #7
0
    def test_request(self):
        # create a new user
        create_user(u"ValidUser", u"test_pass", u"test_email@moinmoin")
        httpauthmoin_obj = HTTPAuthMoin()
        test_user, bool_val = httpauthmoin_obj.request(flaskg.user)
        assert test_user.valid
        assert test_user.name == u"ValidUser"
        assert bool_val

        # when auth_method is not 'http'
        flaskg.user.auth_method = "invalid"
        test_user, bool_val = httpauthmoin_obj.request(flaskg.user)
        assert not test_user.valid
        assert test_user.name == u"anonymous"
Beispiel #8
0
    def test_perf_get_subscribers(self):
        pytest.skip("usually we do no performance tests")
        password = u"password"
        subscriptions = [
            "{0}:{1}".format(ITEMID, self.item.meta[ITEMID]),
            "{0}:{1}:{2}".format(NAME, self.namespace, self.item_name),
            "{0}:{1}:{2}".format(TAGS, self.namespace, self.tagname),
            "{0}:{1}:{2}".format(NAMEPREFIX, self.namespace, u"fo"),
            "{0}:{1}:{2}".format(NAMERE, self.namespace, r"\wo")
        ]
        users = set()
        expected_names = set()
        for i in xrange(10000):
            i = unicode(i)
            user.create_user(username=i,
                             password=password,
                             email="{0}@example.org".format(i),
                             validate=False,
                             locale=u'en')
            user_ = user.User(name=i, password=password)
            users.add(user_)
            expected_names.add(user_.name0)

        users_sliced = list(users)[:100]
        expected_names_sliced = {user_.name0 for user_ in users_sliced}
        tests = [(users_sliced, expected_names_sliced),
                 (users, expected_names)]

        import time
        for users_, expected_names_ in tests:
            print "\nTesting {0} subscribers from a total of {1} users".format(
                len(users_), len(users))
            for subscription in subscriptions:
                for user_ in users_:
                    user_.profile._meta[SUBSCRIPTIONS] = [subscription]
                    user_.save(force=True)
                t = time.time()
                subscribers = get_subscribers(**self.item.meta)
                elapsed_time = time.time() - t
                print "{0}: {1} s".format(
                    subscription.split(':', 1)[0], elapsed_time)
                subscribers_names = {
                    subscriber.name
                    for subscriber in subscribers
                }
                assert subscribers_names == expected_names_
Beispiel #9
0
def test_handle_login():
    # no messages in the beginning
    assert not flaskg._login_messages
    test_user1 = handle_login(flaskg.user, login_username='******', login_password='******', stage='moin')
    test_login_message = [u'Invalid username or password.']
    assert flaskg._login_messages == test_login_message
    assert test_user1.name0 == ANON
    assert not test_user1.valid
    # pop the message
    flaskg._login_messages.pop()
    # try with a valid user
    givenauth_obj = GivenAuth()
    flaskg.user.auth_method = 'given'
    givenauth_obj.user_name = u'Test_User'
    create_user(u'Test_User', u'test_pass', u'*****@*****.**')
    test_user, bool_value = givenauth_obj.request(flaskg.user)
    test_user2 = handle_login(test_user, login_username='******', login_password='******', stage='moin')
    assert not flaskg._login_messages
    assert test_user2.name == [u'Test_User', ]
    assert test_user2.valid
Beispiel #10
0
    def run(self, name, display_name, email, openid, password):
        before_wiki()
        msg = user.create_user(username=name,
                               password=password,
                               email=email,
                               openid=openid)

        if msg:
            print msg
        else:
            u = user.User(auth_username=name)
            print " %-20s %-25s %-35s - created." % (u.itemid, u.name, u.email),
Beispiel #11
0
    def run(self, name, aliasname, email, openid, password):
        flaskg.unprotected_storage = app.storage
        msg = user.create_user(username=name,
                               password=password,
                               email=email,
                               openid=openid)

        if msg:
            print msg
        else:
            u = user.User(auth_username=name)
            print " %-20s %-25s %-35s - created." % (u.itemid, u.name, u.email),
Beispiel #12
0
 def createUser(self,
                name,
                password,
                pwencoded=False,
                email=None,
                validate=False):
     ret = user.create_user(name,
                            password,
                            email,
                            validate=validate,
                            is_encrypted=pwencoded)
     assert ret is None, "create_user returned: {0}".format(ret)
Beispiel #13
0
    def run(self, name, display_name, email, openid, password):
        before_wiki()
        msg = user.create_user(username=name,
                               password=password,
                               email=email,
                               openid=openid)

        if msg:
            print msg
        else:
            u = user.User(auth_username=name)
            print " %-20s %-25s %-35s - created." % (u.itemid, u.name,
                                                     u.email),
    def test_regression_user_password_started_with_sha(self):
        # This is regression test for bug in function 'user.create_user'.
        #
        # This function does not encode passwords which start with '{SHA}'
        # It treats them as already encoded SHA hashes.
        #
        # If user during registration specifies password starting with '{SHA}'
        # this password will not get encoded and user object will get saved with empty enc_password
        # field.
        #
        # Such situation leads to "KeyError: 'enc_password'" during
        # user authentication.

        # Any Password begins with the {SHA} symbols led to
        # "KeyError: 'enc_password'" error during user authentication.
        user_name = u'moin'
        user_password = u'{SHA}LKM56'
        user.create_user(user_name, user_password, u'*****@*****.**', '')

        # Try to "login"
        theuser = user.User(name=user_name, password=user_password)
        assert theuser.valid
Beispiel #15
0
    def test_regression_user_password_started_with_sha(self):
        # This is regression test for bug in function 'user.create_user'.
        #
        # This function does not encode passwords which start with '{SHA}'
        # It treats them as already encoded SHA hashes.
        #
        # If user during registration specifies password starting with '{SHA}'
        # this password will not get encoded and user object will get saved with empty enc_password
        # field.
        #
        # Such situation leads to "KeyError: 'enc_password'" during
        # user authentication.

        # Any Password begins with the {SHA} symbols led to
        # "KeyError: 'enc_password'" error during user authentication.
        user_name = u'moin'
        user_password = u'{SHA}LKM56'
        user.create_user(user_name, user_password, u'*****@*****.**', u'')

        # Try to "login"
        theuser = user.User(name=user_name, password=user_password)
        assert theuser.valid
    def test_perf_get_subscribers(self):
        pytest.skip("usually we do no performance tests")
        password = u"password"
        subscriptions = [
            "{0}:{1}".format(ITEMID, self.item.meta[ITEMID]),
            "{0}:{1}:{2}".format(NAME, self.namespace, self.item_name),
            "{0}:{1}:{2}".format(TAGS, self.namespace, self.tagname),
            "{0}:{1}:{2}".format(NAMEPREFIX, self.namespace, u"fo"),
            "{0}:{1}:{2}".format(NAMERE, self.namespace, r"\wo"),
        ]
        users = set()
        expected_names = set()
        for i in xrange(10000):
            i = unicode(i)
            user.create_user(
                username=i, password=password, email="{0}@example.org".format(i), validate=False, locale=u"en"
            )
            user_ = user.User(name=i, password=password)
            users.add(user_)
            expected_names.add(user_.name0)

        users_sliced = list(users)[:100]
        expected_names_sliced = {user_.name0 for user_ in users_sliced}
        tests = [(users_sliced, expected_names_sliced), (users, expected_names)]

        import time

        for users_, expected_names_ in tests:
            print "\nTesting {0} subscribers from a total of {1} users".format(len(users_), len(users))
            for subscription in subscriptions:
                for user_ in users_:
                    user_.profile._meta[SUBSCRIPTIONS] = [subscription]
                    user_.save(force=True)
                t = time.time()
                subscribers = get_subscribers(**self.item.meta)
                elapsed_time = time.time() - t
                print "{0}: {1} s".format(subscription.split(":", 1)[0], elapsed_time)
                subscribers_names = {subscriber.name for subscriber in subscribers}
                assert subscribers_names == expected_names_
Beispiel #17
0
    def run(self, name, aliasname, email, openid, password):
        flaskg.unprotected_storage = app.unprotected_storage
        msg = user.create_user(username=name,
                               password=password,
                               email=email,
                               openid=openid)

        if msg:
            print msg
        else:
            uid = user.getUserId(name)
            u = user.User(uid)
            print " %-20s %-25s %-35s - created." % (u.id, u.name, u.email),
Beispiel #18
0
    def test_get_subscribers(self, item, item_name, namespace, tag_name):
        users = get_subscribers(**item.meta)
        assert users == set()

        name1 = u'baz'
        password = u'password'
        email1 = u'*****@*****.**'
        name2 = u"bar"
        email2 = u"*****@*****.**"
        name3 = u"barbaz"
        email3 = u"*****@*****.**"
        user.create_user(username=name1,
                         password=password,
                         email=email1,
                         validate=False,
                         locale=u'en')
        user1 = user.User(name=name1, password=password)
        user.create_user(username=name2,
                         password=password,
                         email=email2,
                         validate=False)
        user2 = user.User(name=name2, password=password)
        user.create_user(username=name3,
                         password=password,
                         email=email3,
                         verify_email=True,
                         locale=u"en")
        user3 = user.User(name=name3, password=password, email=email3)
        subscribers = get_subscribers(**item.meta)
        assert subscribers == set()

        namere = r'.*'
        nameprefix = u"fo"
        subscription_lists = [
            ["{0}:{1}".format(ITEMID, item.meta[ITEMID])],
            ["{0}:{1}:{2}".format(TAGS, namespace, tag_name)],
            ["{0}:{1}:{2}".format(NAME, namespace, item_name)],
            ["{0}:{1}:{2}".format(NAMERE, namespace, namere)],
            ["{0}:{1}:{2}".format(NAMEPREFIX, namespace, nameprefix)],
        ]
        users = [user1, user2, user3]
        expected_names = {user1.name0, user2.name0}
        for subscriptions in subscription_lists:
            for user_ in users:
                user_.profile._meta[SUBSCRIPTIONS] = subscriptions
                user_.save(force=True)
            subscribers = get_subscribers(**item.meta)
            subscribers_names = {subscriber.name for subscriber in subscribers}
            assert subscribers_names == expected_names

        meta = {
            CONTENTTYPE: u'text/plain;charset=utf-8',
            ACL: u"{0}: All:read,write".format(user1.name0)
        }
        item._save(meta, comment=u"")
        item = Item.create(item_name)
        subscribers = get_subscribers(**item.meta)
        assert {subscriber.name for subscriber in subscribers} == {user2.name0}
Beispiel #19
0
 def test_create_retrieve(self):
     name = u"foo"
     password = u"barbaz4711"
     email = u"*****@*****.**"
     # nonexisting user
     u = user.User(name=name, password=password)
     assert u.name == [name, ]
     assert not u.valid
     assert not u.exists()
     # create a user
     ret = user.create_user(name, password, email, validate=False)
     assert ret is None, "create_user returned: {0}".format(ret)
     # existing user
     u = user.User(name=name, password=password)
     assert u.name == [name, ]
     assert u.email == email
     assert u.valid
     assert u.exists()
Beispiel #20
0
 def test_create_retrieve(self):
     name = u"foo"
     password = u"barbaz4711"
     email = u"*****@*****.**"
     # nonexisting user
     u = user.User(name=name, password=password)
     assert u.name == [
         name,
     ]
     assert not u.valid
     assert not u.exists()
     # create a user
     ret = user.create_user(name, password, email, validate=False)
     assert ret is None, "create_user returned: {0}".format(ret)
     # existing user
     u = user.User(name=name, password=password)
     assert u.name == [
         name,
     ]
     assert u.email == email
     assert u.valid
     assert u.exists()
Beispiel #21
0
    def test_get_subscribers(self, item, item_name, namespace, tag_name):
        users = get_subscribers(**item.meta)
        assert users == set()

        name1 = u'baz'
        password = u'password'
        email1 = u'*****@*****.**'
        name2 = u"bar"
        email2 = u"*****@*****.**"
        name3 = u"barbaz"
        email3 = u"*****@*****.**"
        user.create_user(username=name1, password=password, email=email1, validate=False, locale=u'en')
        user1 = user.User(name=name1, password=password)
        user.create_user(username=name2, password=password, email=email2, validate=False)
        user2 = user.User(name=name2, password=password)
        user.create_user(username=name3, password=password, email=email3, locale=u"en")
        user3 = user.User(name=name3, password=password, email1=email3)
        subscribers = get_subscribers(**item.meta)
        assert subscribers == set()

        namere = r'.*'
        nameprefix = u"fo"
        subscription_lists = [
            ["{0}:{1}".format(ITEMID, item.meta[ITEMID])],
            ["{0}:{1}:{2}".format(TAGS, namespace, tag_name)],
            ["{0}:{1}:{2}".format(NAME, namespace, item_name)],
            ["{0}:{1}:{2}".format(NAMERE, namespace, namere)],
            ["{0}:{1}:{2}".format(NAMEPREFIX, namespace, nameprefix)],
        ]
        users = [user1, user2, user3]
        expected_names = {user1.name0, user2.name0}
        for subscriptions in subscription_lists:
            for user_ in users:
                user_.profile._meta[SUBSCRIPTIONS] = subscriptions
                user_.save(force=True)
            subscribers = get_subscribers(**item.meta)
            subscribers_names = {subscriber.name for subscriber in subscribers}
            assert subscribers_names == expected_names

        meta = {CONTENTTYPE: u'text/plain;charset=utf-8',
                ACL: u"{0}: All:read,write".format(user1.name0)}
        item._save(meta, comment=u"")
        item = Item.create(item_name)
        subscribers = get_subscribers(**item.meta)
        assert {subscriber.name for subscriber in subscribers} == {user2.name0}
 def createUser(self, name, password, pwencoded=False, email=None):
     """ helper to create test user
     """
     if email is None:
         email = "*****@*****.**"
     user.create_user(name, password, email, is_encrypted=pwencoded)
Beispiel #23
0
 def createUser(self, name, password, pwencoded=False, email=None):
     """ helper to create test user
     """
     if email is None:
         email = "*****@*****.**"
     user.create_user(name, password, email, is_encrypted=pwencoded)
Beispiel #24
0
 def createUser(self, name, password, pwencoded=False, email=None, validate=False):
     ret = user.create_user(name, password, email, validate=validate, is_encrypted=pwencoded)
     assert ret is None, "create_user returned: {0}".format(ret)