def test_sas_auth(self, mocker, device_connection_string, pipeline_configuration):
     mocker.spy(pipeline_stages_base.PipelineRootStage, "run_op")
     auth_provider = SymmetricKeyAuthenticationProvider.parse(device_connection_string)
     pipeline = HTTPPipeline(auth_provider, pipeline_configuration)
     op = pipeline._pipeline.run_op.call_args[0][1]
     assert pipeline._pipeline.run_op.call_count == 1
     assert isinstance(op, pipeline_ops_iothub.SetAuthProviderOperation)
     assert op.auth_provider is auth_provider
    def test_sas_auth(self, mocker, pipeline_configuration):
        mocker.spy(pipeline_stages_base.PipelineRootStage, "run_op")

        pipeline = HTTPPipeline(pipeline_configuration)

        op = pipeline._pipeline.run_op.call_args[0][1]
        assert pipeline._pipeline.run_op.call_count == 1
        assert isinstance(op, pipeline_ops_base.InitializePipelineOperation)
 def test_cert_auth(self, mocker, x509, pipeline_configuration):
     mocker.spy(pipeline_stages_base.PipelineRootStage, "run_op")
     auth_provider = X509AuthenticationProvider(
         hostname="somehostname", device_id=fake_device_id, x509=x509
     )
     pipeline = HTTPPipeline(auth_provider, pipeline_configuration)
     op = pipeline._pipeline.run_op.call_args[0][1]
     assert pipeline._pipeline.run_op.call_count == 1
     assert isinstance(op, pipeline_ops_iothub.SetX509AuthProviderOperation)
     assert op.auth_provider is auth_provider
Beispiel #4
0
    def test_pipeline_configuration(self, pipeline_configuration):
        pipeline = HTTPPipeline(pipeline_configuration)
        curr_stage = pipeline._pipeline

        expected_stage_order = [
            pipeline_stages_base.PipelineRootStage,
            pipeline_stages_iothub_http.IoTHubHTTPTranslationStage,
            pipeline_stages_http.HTTPTransportStage,
        ]

        # Assert that all PipelineStages are there, and they are in the right order
        for i in range(len(expected_stage_order)):
            expected_stage = expected_stage_order[i]
            assert isinstance(curr_stage, expected_stage)
            curr_stage = curr_stage.next

        # Assert there are no more additional stages
        assert curr_stage is None
Beispiel #5
0
    def test_sas_auth_op_fail(self, mocker, arbitrary_exception, pipeline_configuration):
        old_run_op = pipeline_stages_base.PipelineRootStage._run_op

        def fail_initialize(self, op):
            if isinstance(op, pipeline_ops_base.InitializePipelineOperation):
                op.complete(error=arbitrary_exception)
            else:
                old_run_op(self, op)

        mocker.patch.object(
            pipeline_stages_base.PipelineRootStage,
            "_run_op",
            side_effect=fail_initialize,
            autospec=True,
        )

        with pytest.raises(arbitrary_exception.__class__) as e_info:
            HTTPPipeline(pipeline_configuration)
        assert e_info.value is arbitrary_exception
    def test_cert_auth_op_fail(self, mocker, x509, arbitrary_exception, pipeline_configuration):
        old_run_op = pipeline_stages_base.PipelineRootStage._run_op

        def fail_set_auth_provider(self, op):
            if isinstance(op, pipeline_ops_iothub.SetX509AuthProviderOperation):
                op.complete(error=arbitrary_exception)
            else:
                old_run_op(self, op)

        mocker.patch.object(
            pipeline_stages_base.PipelineRootStage,
            "_run_op",
            side_effect=fail_set_auth_provider,
            autospec=True,
        )

        auth_provider = X509AuthenticationProvider(
            hostname="somehostname", device_id=fake_device_id, x509=x509
        )
        with pytest.raises(arbitrary_exception.__class__):
            HTTPPipeline(auth_provider, pipeline_configuration)
    def test_sas_auth_op_fail(
        self, mocker, device_connection_string, arbitrary_exception, pipeline_configuration
    ):
        old_run_op = pipeline_stages_base.PipelineRootStage._run_op

        def fail_set_auth_provider(self, op):
            if isinstance(op, pipeline_ops_iothub.SetAuthProviderOperation):
                op.complete(error=arbitrary_exception)
            else:
                old_run_op(self, op)

        mocker.patch.object(
            pipeline_stages_base.PipelineRootStage,
            "_run_op",
            side_effect=fail_set_auth_provider,
            autospec=True,
        )

        auth_provider = SymmetricKeyAuthenticationProvider.parse(device_connection_string)
        with pytest.raises(arbitrary_exception.__class__) as e_info:
            HTTPPipeline(auth_provider, pipeline_configuration)
        assert e_info.value is arbitrary_exception
def pipeline(mocker, pipeline_configuration):
    pipeline = HTTPPipeline(pipeline_configuration)
    mocker.patch.object(pipeline._pipeline, "run_op")
    return pipeline
Beispiel #9
0
    def test_pipeline_nucleus(self, pipeline_configuration):
        pipeline = HTTPPipeline(pipeline_configuration)

        assert isinstance(pipeline._nucleus, pipeline_nucleus.PipelineNucleus)
        assert pipeline._nucleus.pipeline_configuration is pipeline_configuration