Page MenuHomeSoftware Heritage

test_npm_adversarial fails
Closed, ResolvedPublic

Description

tests/test_metadata.py:160: AssertionError
_________________________________ TestMetadata.test_npm_adversarial __________________________________

self = <swh.indexer.tests.test_metadata.TestMetadata object at 0x7f26a230fa00>

    @settings(suppress_health_check=[HealthCheck.too_slow])
>   @given(json_document_strategy(keys=list(NpmMapping.mapping)))

tests/test_metadata.py:1114: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_metadata.py:1117: in test_npm_adversarial
    self.npm_mapping.translate(raw)
metadata_dictionary/base.py:179: in translate
    return self._translate_dict(content_dict)
metadata_dictionary/base.py:131: in _translate_dict
    v = normalization_method(v)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <swh.indexer.metadata_dictionary.npm.NpmMapping object at 0x7f2683164d60>, description = False

    def normalize_description(self, description):
        r"""Try to re-decode ``description`` as UTF-16, as this is a somewhat common
        mistake that causes issues in the database because of null bytes in JSON.
    
        >>> NpmMapping().normalize_description("foo bar")
        'foo bar'
        >>> NpmMapping().normalize_description(
        ...     "\ufffd\ufffd#\x00 \x00f\x00o\x00o\x00 \x00b\x00a\x00r\x00\r\x00 \x00"
        ... )
        'foo bar'
        >>> NpmMapping().normalize_description(
        ...     "\ufffd\ufffd\x00#\x00 \x00f\x00o\x00o\x00 \x00b\x00a\x00r\x00\r\x00 "
        ... )
        'foo bar'
        >>> NpmMapping().normalize_description(
        ...     # invalid UTF-16 and meaningless UTF-8:
        ...     "\ufffd\ufffd\x00#\x00\x00\x00 \x00\x00\x00\x00f\x00\x00\x00\x00"
        ... ) is None
        True
        >>> NpmMapping().normalize_description(
        ...     # ditto (ut looks like little-endian at first)
        ...     "\ufffd\ufffd#\x00\x00\x00 \x00\x00\x00\x00f\x00\x00\x00\x00\x00"
        ... ) is None
        True
        >>> NpmMapping().normalize_description(None) is None
        True
        """
        if description is None:
            return None
        # XXX: if this function ever need to support more cases, consider
        # switching to https://pypi.org/project/ftfy/ instead of adding more hacks
>       if description.startswith("\ufffd\ufffd") and "\x00" in description:
E       AttributeError: 'bool' object has no attribute 'startswith'

metadata_dictionary/npm.py:167: AttributeError
--------------------------------------------- Hypothesis ---------------------------------------------
Falsifying example: test_npm_adversarial(
    doc={'description': False},
    self=<swh.indexer.tests.test_metadata.TestMetadata at 0x7f26a230fa00>,
)