Exemplo n.º 1
0
def test_functions_pubsub_publish_should_publish_message():
    request = MagicMock()
    request.body.topic = FUNCTIONS_TOPIC
    request.body.message = "my_message"

    response = main.publish(request)

    assert response == "Message published."
Exemplo n.º 2
0
def test_functions_pubsub_publish_should_publish_message():
    request = MagicMock()
    request.get_json.return_value = {
        "topic": FUNCTIONS_TOPIC,
        "message": "my_message"
    }

    response = main.publish(request)

    assert response == "Message published."
Exemplo n.º 3
0
    def test_publish(self):
        """Test publishing."""
        event = {
            'data': base64.b64encode(_TEST_VULN),
        }

        main.publish(event, None)
        self.mock_post.assert_called_once_with(
            'https://pypi.org/_/vulnerabilities/osv/report',
            data=b'[{"id": "PYSEC-2021-63", "project": "cryptography", '
            b'"versions": ["3.1", "3.1.1", "3.2", "3.2.1", "3.3", "3.3.1"], '
            b'"link": "https://osv.dev/vulnerability/PYSEC-2021-63", '
            b'"aliases": ["CVE-2020-36242"]}]',
            headers={
                'VULN-PUBLIC-KEY-IDENTIFIER':
                '7ef88907d5bba4c0120f82bfd78386a9'
                'd9328fb5d2d112c473ce52add3e4cd5b',
                'VULN-PUBLIC-KEY-SIGNATURE': mock.ANY
            })

        request = self.mock_post.call_args.kwargs['data']
        signature = self.mock_post.call_args.kwargs['headers'][
            'VULN-PUBLIC-KEY-SIGNATURE']
        self._verify_signature(request, signature)
Exemplo n.º 4
0
def test_functions_pubsub_publish_should_fail_without_params():
    request = MagicMock()
    request.body.topic = None
    response = main.publish(request)

    assert 'Missing "topic" and/or "subscription" parameter.' in response
Exemplo n.º 5
0
def test_functions_pubsub_publish_should_fail_without_params():
    request = MagicMock()
    request.get_json.return_value = {}
    response = main.publish(request)

    assert 'Missing "topic" and/or "message" parameter.' in response