Ejemplo n.º 1
0
def test_users_list():
    u1 = UserProfile(username='******', display_name='John Connor', pk=1)
    u2 = UserProfile(username='******', display_name='Sarah Connor', pk=2)
    assert users_list([u1, u2]) == ', '.join((user_link(u1), user_link(u2)))

    # handle None gracefully
    assert user_link(None) == ''
Ejemplo n.º 2
0
def test_user_link():
    u = UserProfile(username='******', display_name='John Connor', pk=1)
    assert user_link(u) == ('<a href="%s" title="%s">John Connor</a>' %
                            (u.get_url_path(), u.name))

    # handle None gracefully
    assert user_link(None) == ''
Ejemplo n.º 3
0
def test_users_list():
    u1 = UserProfile(username='******', display_name='John Connor', pk=1)
    u2 = UserProfile(username='******', display_name='Sarah Connor', pk=2)
    assert users_list([u1, u2]) == ', '.join((user_link(u1), user_link(u2)))

    # handle None gracefully
    assert user_link(None) == ''
Ejemplo n.º 4
0
def test_short_users_list():
    """Test the option to shortened the users list to a certain size."""
    # short list with 'others'
    u1 = UserProfile(username='******', display_name='Oscar the Grouch', pk=1)
    u2 = UserProfile(username='******', display_name='Grover', pk=2)
    u3 = UserProfile(username='******', display_name='Cookie Monster', pk=3)
    shortlist = users_list([u1, u2, u3], size=2)
    assert shortlist == ', '.join((user_link(u1), user_link(u2))) + ', others'
Ejemplo n.º 5
0
def test_short_users_list():
    """Test the option to shortened the users list to a certain size."""
    # short list with 'others'
    u1 = UserProfile(username='******', display_name='Oscar the Grouch', pk=1)
    u2 = UserProfile(username='******', display_name='Grover', pk=2)
    u3 = UserProfile(username='******', display_name='Cookie Monster', pk=3)
    shortlist = users_list([u1, u2, u3], size=2)
    assert shortlist == ', '.join((user_link(u1), user_link(u2))) + ', others'
Ejemplo n.º 6
0
def test_user_link():
    u = UserProfile(username='******', display_name='John Connor', pk=1)
    assert user_link(u) == (
        '<a href="%s" title="%s">John Connor</a>' % (u.get_url_path(),
                                                     u.name))

    # handle None gracefully
    assert user_link(None) == ''
Ejemplo n.º 7
0
def test_user_link_unicode():
    """make sure helper won't choke on unicode input"""
    u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1)
    assert user_link(u) == (u'<a href="%s" title="%s">Jürgen Müller</a>' %
                            (u.get_url_path(), u.name))

    u = UserProfile(username='******', pk=1)
    assert user_link(u) == (u'<a href="%s" title="%s">%s</a>' %
                            (u.get_url_path(), u.name, u.username))
Ejemplo n.º 8
0
def test_user_link_unicode():
    """make sure helper won't choke on unicode input"""
    u = UserProfile(username=u'jmüller', display_name=u'Jürgen Müller', pk=1)
    assert user_link(u) == (
        u'<a href="%s" title="%s">Jürgen Müller</a>' % (
            u.get_url_path(), u.name))

    u = UserProfile(username='******', pk=1)
    assert user_link(u) == (
        u'<a href="%s" title="%s">%s</a>' % (u.get_url_path(), u.name,
                                             u.username))
Ejemplo n.º 9
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>', pk=1)
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    assert user_link(u) == '<a href="%s" title="%s">%s</a>' % (
        u.get_url_path(), html, html)

    u = UserProfile(username='******',
                    display_name="""xss"'><iframe onload=alert(3)>""", pk=1)
    html = """xss&#34;&#39;&gt;&lt;iframe onload=alert(3)&gt;"""
    assert user_link(u) == '<a href="%s" title="%s">%s</a>' % (
        u.get_url_path(), html, html)
Ejemplo n.º 10
0
def test_user_link_xss():
    u = UserProfile(username='******',
                    display_name='<script>alert(1)</script>',
                    pk=1)
    html = "&lt;script&gt;alert(1)&lt;/script&gt;"
    assert user_link(
        u) == '<a href="%s" title="%s">%s</a>' % (u.get_url_path(), html, html)

    u = UserProfile(username='******',
                    display_name="""xss"'><iframe onload=alert(3)>""",
                    pk=1)
    html = """xss&#34;&#39;&gt;&lt;iframe onload=alert(3)&gt;"""
    assert user_link(
        u) == '<a href="%s" title="%s">%s</a>' % (u.get_url_path(), html, html)
Ejemplo n.º 11
0
    def to_string(self, type_=None):
        log_type = amo.LOG_BY_ID[self.action]
        if type_ and hasattr(log_type, "%s_format" % type_):
            format = getattr(log_type, "%s_format" % type_)
        else:
            format = log_type.format

        # We need to copy arguments so we can remove elements from it
        # while we loop over self.arguments.
        arguments = copy(self.arguments)
        addon = None
        review = None
        version = None
        collection = None
        tag = None
        group = None
        file_ = None

        for arg in self.arguments:
            if isinstance(arg, Addon) and not addon:
                if arg.is_listed:
                    addon = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name)
                else:
                    addon = self.f(u"{0}", arg.name)
                arguments.remove(arg)
            if isinstance(arg, Review) and not review:
                review = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), _("Review"))
                arguments.remove(arg)
            if isinstance(arg, Version) and not version:
                text = _("Version {0}")
                if arg.is_listed:
                    version = self.f(u'<a href="{1}">%s</a>' % text, arg.version, arg.get_url_path())
                else:
                    version = self.f(text, arg.version)
                arguments.remove(arg)
            if isinstance(arg, Collection) and not collection:
                collection = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.name)
                arguments.remove(arg)
            if isinstance(arg, Tag) and not tag:
                if arg.can_reverse():
                    tag = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(), arg.tag_text)
                else:
                    tag = self.f("{0}", arg.tag_text)
            if isinstance(arg, Group) and not group:
                group = arg.name
                arguments.remove(arg)
            if isinstance(arg, File) and not file_:
                validation = "passed"
                if self.action == amo.LOG.BETA_SIGNED_VALIDATION_FAILED.id:
                    validation = "failed"

                file_ = self.f(
                    u'<a href="{0}">{1}</a> (validation {2})',
                    reverse("files.list", args=[arg.pk]),
                    arg.filename,
                    validation,
                )
                arguments.remove(arg)

        user = user_link(self.user)

        try:
            kw = dict(
                addon=addon,
                review=review,
                version=version,
                collection=collection,
                tag=tag,
                user=user,
                group=group,
                file=file_,
            )
            return self.f(format, *arguments, **kw)
        except (AttributeError, KeyError, IndexError):
            log.warning("%d contains garbage data" % (self.id or 0))
            return "Something magical happened."
Ejemplo n.º 12
0
    def to_string(self, type_=None):
        log_type = amo.LOG_BY_ID[self.action]
        if type_ and hasattr(log_type, '%s_format' % type_):
            format = getattr(log_type, '%s_format' % type_)
        else:
            format = log_type.format

        # We need to copy arguments so we can remove elements from it
        # while we loop over self.arguments.
        arguments = copy(self.arguments)
        addon = None
        review = None
        version = None
        collection = None
        tag = None
        group = None
        file_ = None

        for arg in self.arguments:
            if isinstance(arg, Addon) and not addon:
                if arg.is_listed:
                    addon = self.f(u'<a href="{0}">{1}</a>',
                                   arg.get_url_path(), arg.name)
                else:
                    addon = self.f(u'{0}', arg.name)
                arguments.remove(arg)
            if isinstance(arg, Review) and not review:
                review = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(),
                                _('Review'))
                arguments.remove(arg)
            if isinstance(arg, Version) and not version:
                text = _('Version {0}')
                if arg.is_listed:
                    version = self.f(u'<a href="{1}">%s</a>' % text,
                                     arg.version, arg.get_url_path())
                else:
                    version = self.f(text, arg.version)
                arguments.remove(arg)
            if isinstance(arg, Collection) and not collection:
                collection = self.f(u'<a href="{0}">{1}</a>',
                                    arg.get_url_path(), arg.name)
                arguments.remove(arg)
            if isinstance(arg, Tag) and not tag:
                if arg.can_reverse():
                    tag = self.f(u'<a href="{0}">{1}</a>', arg.get_url_path(),
                                 arg.tag_text)
                else:
                    tag = self.f('{0}', arg.tag_text)
            if isinstance(arg, Group) and not group:
                group = arg.name
                arguments.remove(arg)
            if isinstance(arg, File) and not file_:
                validation = 'passed'
                if self.action == amo.LOG.BETA_SIGNED_VALIDATION_FAILED.id:
                    validation = 'failed'

                file_ = self.f(u'<a href="{0}">{1}</a> (validation {2})',
                               reverse('files.list', args=[arg.pk]),
                               arg.filename, validation)
                arguments.remove(arg)

        user = user_link(self.user)

        try:
            kw = dict(addon=addon,
                      review=review,
                      version=version,
                      collection=collection,
                      tag=tag,
                      user=user,
                      group=group,
                      file=file_)
            return self.f(format, *arguments, **kw)
        except (AttributeError, KeyError, IndexError):
            log.warning('%d contains garbage data' % (self.id or 0))
            return 'Something magical happened.'
Ejemplo n.º 13
0
    def to_string(self, type_=None):
        log_type = amo.LOG_BY_ID[self.action]
        if type_ and hasattr(log_type, '%s_format' % type_):
            format = getattr(log_type, '%s_format' % type_)
        else:
            format = log_type.format

        # We need to copy arguments so we can remove elements from it
        # while we loop over self.arguments.
        arguments = copy(self.arguments)
        addon = None
        review = None
        version = None
        collection = None
        tag = None
        group = None
        file_ = None

        for arg in self.arguments:
            if isinstance(arg, Addon) and not addon:
                if arg.has_listed_versions():
                    addon = self.f(u'<a href="{0}">{1}</a>',
                                   arg.get_url_path(), arg.name)
                else:
                    addon = self.f(u'{0}', arg.name)
                arguments.remove(arg)
            if isinstance(arg, Review) and not review:
                review = self.f(u'<a href="{0}">{1}</a>',
                                arg.get_url_path(), _('Review'))
                arguments.remove(arg)
            if isinstance(arg, Version) and not version:
                text = _('Version {0}')
                if arg.channel == amo.RELEASE_CHANNEL_LISTED:
                    version = self.f(u'<a href="{1}">%s</a>' % text,
                                     arg.version, arg.get_url_path())
                else:
                    version = self.f(text, arg.version)
                arguments.remove(arg)
            if isinstance(arg, Collection) and not collection:
                collection = self.f(u'<a href="{0}">{1}</a>',
                                    arg.get_url_path(), arg.name)
                arguments.remove(arg)
            if isinstance(arg, Tag) and not tag:
                if arg.can_reverse():
                    tag = self.f(u'<a href="{0}">{1}</a>',
                                 arg.get_url_path(), arg.tag_text)
                else:
                    tag = self.f('{0}', arg.tag_text)
            if isinstance(arg, Group) and not group:
                group = arg.name
                arguments.remove(arg)
            if isinstance(arg, File) and not file_:
                validation = 'passed'
                if self.action in (
                        amo.LOG.BETA_SIGNED.id,
                        amo.LOG.BETA_SIGNED_VALIDATION_FAILED.id,
                        amo.LOG.UNLISTED_SIGNED.id,
                        amo.LOG.UNLISTED_SIGNED_VALIDATION_FAILED.id):
                    validation = 'ignored'

                file_ = self.f(u'<a href="{0}">{1}</a> (validation {2})',
                               reverse('files.list', args=[arg.pk]),
                               arg.filename,
                               validation)
                arguments.remove(arg)

        user = user_link(self.user)

        try:
            kw = dict(addon=addon, review=review, version=version,
                      collection=collection, tag=tag, user=user, group=group,
                      file=file_)
            return self.f(format, *arguments, **kw)
        except (AttributeError, KeyError, IndexError):
            log.warning('%d contains garbage data' % (self.id or 0))
            return 'Something magical happened.'