Exemplo n.º 1
0
 def test_receive_text_plain_with_mdn_signed(self):
     headers = TestPartnerReceiveMessage.received_text_plain_headers
     body = TestPartnerReceiveMessage.received_text_plain_content
     pm = PartnerManager(headers, body)
     resp_headers, resp_content = pm.receive()
     assert_not_equal(None, resp_headers)
     assert_not_equal(None, resp_content)
Exemplo n.º 2
0
 def test_send_async_mdn_ok(self):
     headers = TestPartnerBase.mdn_headers
     body = TestPartnerBase.mdn_content
     pm = PartnerManager(headers, body)
     message = jsonserializer.deserialize(TestPartnerMdnMessage.message_json,
                                          AS2Message)
     pm.send_async_mdn(message)
Exemplo n.º 3
0
 def test_save_async_mdn_exception_when_msg_not_found(self):
     self.mock_cloud_data_find.side_effect = Exception('msg not found')
     headers = {'Content-Type': 'application/json', }
     body = None
     pm = PartnerManager(headers, body)
     message = jsonserializer.deserialize(TestPartnerMdnMessage.async_mdn_message_json,
                                          AsyncMdnReceive)
     pm.save_mdn_event_message(message)
Exemplo n.º 4
0
 def test_save_async_mdn_ok(self):
     headers = {'Content-Type': 'application/json', }
     body = None
     pm = PartnerManager(headers, body)
     message = jsonserializer.deserialize(TestPartnerMdnMessage.async_mdn_message_json,
                                          AsyncMdnReceive)
     msg = pm.save_mdn_event_message(message)
     assert_not_equal(None, msg)
     assert_not_equal(None, msg.message_mdn)
Exemplo n.º 5
0
    def test_data_dfs_path_or_data_is_required(self, dfs_path, content):
        pm = PartnerManager(
            {
                'ngas2-business-id': "1",
                'ngas2-agreement-id': "A01",
                'ngas2-data-dfs-path': dfs_path
            },
            content
        )
        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('failed', msg.message_status)
        assert_equal('waiting', msg.message_mdn_status)
        assert_equal(None, msg.message_mdn.mdn_validate_status)
Exemplo n.º 6
0
    def test_send_https_proxy_digest_auth(self):
        pm = PartnerManager(
            {
                'ngas2-business-id': "1_proxy_digest_auth",
                'ngas2-agreement-id': "A03",
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_1"
        )

        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('successful', msg.message_status)
        assert_equal('successful', msg.message_mdn_status)
        assert_equal('successful', msg.message_mdn.mdn_validate_status)
Exemplo n.º 7
0
def post_message_receive_by_id(domain, id):
    logger.debug(
        'received as2 message from domain:{0} , uri:{1} ,query_string:{2}'.
        format(domain, request.url, request.query_string))
    try:
        headers = dict(request.headers)
        body = get_request_body()

        mgr = PartnerManager(headers, body)

        headers, body = mgr.receive(id)

        return build_response(200, headers, body)
    except:
        logger.exception('message receive via agreement-id failed')
        return build_response(500, None, str(sys.exc_info()[1]))
Exemplo n.º 8
0
    def test_agreement_id_is_None(self, case_name, agreement_id):
        pm = PartnerManager(
            {
                'ngas2-business-id': "1",
                'ngas2-agreement-id': agreement_id,
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_1"
        )
        msg = pm.send()

        assert_not_equal(case_name, None)
        assert_not_equal(None, msg)
        assert_equal('failed', msg.message_status)
        assert_equal('waiting', msg.message_mdn_status)
        assert_equal(None, msg.message_mdn.mdn_validate_status)
Exemplo n.º 9
0
    def test_send_ok_without_download_cert(self):
        pm = PartnerManager(
            {
                'ngas2-business-id': "1",
                'ngas2-agreement-id': "A01",
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_1"
        )

        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('successful', msg.message_status)
        assert_equal('successful', msg.message_mdn_status)
        assert_equal('successful', msg.message_mdn.mdn_validate_status)
Exemplo n.º 10
0
def post_async_mdn_receive(domain):
    logger.debug(
        'received mdn from domain:{0} , uri:{1} ,query_string:{2}'.format(
            domain, request.url, request.query_string))
    try:
        headers = dict(request.headers)
        body = get_request_body()

        mgr = PartnerManager(headers, body)

        mgr.receive_async_mdn()

        return build_response(200, None, 'mdn received ok')
    except:
        logger.exception('mdn receive failed')
        return build_response(500, None, str(sys.exc_info()[1]))
Exemplo n.º 11
0
def post_message_save(domain):
    logger.debug(
        'received internal event-message from domain:{0} , uri:{1} ,query_string:{2}'
        .format(domain, request.url, request.query_string))
    try:
        message = get_request_entity(AS2Message)

        PartnerManager.save_event_message(message)

        return build_response(200,
                              resp_entity=GeneralResponse(is_succeed=True))
    except:
        logger.exception('event-message store failed')
        return build_response(500,
                              resp_entity=GeneralResponse(
                                  is_succeed=False,
                                  error_message=str(sys.exc_info()[1])))
Exemplo n.º 12
0
    def test_send_with_service_not_available(self):
        self.mock_http_post.side_effect = TestPartnerSendMessage.fake_http_post_failed

        pm = PartnerManager(
            {
                'ngas2-business-id': "123-456-789-9527",
                'ngas2-agreement-id': "A01",
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_yyyy"
        )

        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('failed', msg.message_status)
        assert_equal('waiting', msg.message_mdn_status)
        assert_equal(None, msg.message_mdn.mdn_validate_status)
Exemplo n.º 13
0
    def test_send_ok_but_sync_mdn_failed(self):
        self.mock_http_post.side_effect = TestPartnerSendMessage.fake_http_post_mdn_content_is_empty

        pm = PartnerManager(
            {
                'ngas2-business-id': "123-456-789",
                'ngas2-agreement-id': "A01",
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_xxxxx"
        )

        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('failed', msg.message_status)
        assert_equal('failed', msg.message_mdn_status)
        assert_equal(None, msg.message_mdn.mdn_validate_status)
Exemplo n.º 14
0
    def test_receive_with_decompress_error(self,
                                           mock_receive_decode,
                                           mock_mdn_encode
                                           ):
        headers = TestPartnerReceiveMessage.received_text_plain_headers
        body = TestPartnerReceiveMessage.received_text_plain_content

        mock_mdn_encode.side_effect = mock.Mock(return_value=({'x': 'x-decompress-error'}, "mdn: decompress error"))
        mock_receive_decode.side_effect = AS2DeCompressException('decompress error')

        pm = PartnerManager(headers, body)

        mdn_header, mdn_content = pm.receive('A01')

        assert_not_equal(mdn_header, None)
        assert_not_equal(mdn_content, None)
        assert_equal(mdn_header, {'x': 'x-decompress-error'})
        assert_equal(mdn_content, "mdn: decompress error")
Exemplo n.º 15
0
    def test_receive_with_verify_error(self,
                                       mock_receive_decode,
                                       mock_mdn_encode
                                       ):
        headers = TestPartnerReceiveMessage.received_text_plain_headers
        body = TestPartnerReceiveMessage.received_text_plain_content

        mock_receive_decode.side_effect = AS2VerifySignatureException('verify signature error')
        mock_mdn_encode.side_effect = mock.Mock(
            return_value=({'x': 'x-verify-signature-error'}, "mdn: verify signature error"))

        pm = PartnerManager(headers, body)

        mdn_header, mdn_content = pm.receive('A01')

        assert_not_equal(mdn_header, None)
        assert_not_equal(mdn_content, None)
        assert_equal(mdn_header, {'x': 'x-verify-signature-error'})
        assert_equal(mdn_content, "mdn: verify signature error")
Exemplo n.º 16
0
    def test_send_ok_with_download_cert(self,
                                        mock_os_path_exists,
                                        mock_dfs_download_to_file):
        mock_os_path_exists.side_effect = TestPartnerSendMessage.fake_os_path_exists
        mock_dfs_download_to_file.return_value = True

        pm = PartnerManager(
            {
                'ngas2-business-id': "1",
                'ngas2-agreement-id': "A01",
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_1"
        )

        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('successful', msg.message_status)
        assert_equal('successful', msg.message_mdn_status)
        assert_equal('successful', msg.message_mdn.mdn_validate_status)
Exemplo n.º 17
0
def post_message_send(domain):
    logger.debug(
        'received as2 sent request from domain:{0} , uri:{1} ,query_string:{2}'
        .format(domain, request.url, request.query_string))
    try:
        headers = dict(request.headers)
        body = get_request_body()

        mgr = PartnerManager(headers, body)

        message = mgr.send()

        return build_response(200,
                              resp_entity=MessageResponse(is_succeed=True,
                                                          message=message))
    except:
        logger.exception('message send failed')
        return build_response(500,
                              resp_entity=GeneralResponse(
                                  is_succeed=False,
                                  error_message=str(sys.exc_info()[1])))
Exemplo n.º 18
0
    def test_send_ok_but_send_mq_failed(self, save_failed_message):
        mock_queue_publish_info = mock.Mock()
        mock_queue_publish_info.succeeded = False
        self.mock_message_queue_send.return_value = mock_queue_publish_info
        save_failed_message.return_value = None

        pm = PartnerManager(
            {
                'ngas2-business-id': "1_proxy_basic_auth",
                'ngas2-agreement-id': "A02",
                'ngas2-data-dfs-path': ""
            },
            "this is test message from tp_1"
        )

        msg = pm.send()

        assert_not_equal(None, msg)
        assert_equal('successful', msg.message_status)
        assert_equal('successful', msg.message_mdn_status)
        assert_equal('successful', msg.message_mdn.mdn_validate_status)
Exemplo n.º 19
0
 def test_async_mdn_receive_ok_with_fixed_agreement(self):
     headers = TestPartnerBase.mdn_headers
     body = TestPartnerBase.mdn_content
     pm = PartnerManager(headers, body)
     pm.receive_async_mdn('A01')
Exemplo n.º 20
0
 def test_receive_failed_when_agreement_not_found(self, headers, body):
     pm = PartnerManager(headers, body)
     with assert_raises(Exception):
         pm.receive()
Exemplo n.º 21
0
 def test_receive_failed_when_agreement_id_not_found(self):
     headers = TestPartnerReceiveMessage.received_text_plain_headers
     body = TestPartnerReceiveMessage.received_text_plain_content
     pm = PartnerManager(headers, body)
     pm.receive(agreement_id='A-ID-Not-Found', is_test=True)
Exemplo n.º 22
0
 def test_async_mdn_receive_ok(self):
     headers = TestPartnerBase.mdn_headers
     body = TestPartnerBase.mdn_content
     pm = PartnerManager(headers, body)
     pm.receive_async_mdn(None)