def test_cert_auth(self, mocker, x509):
     mocker.patch.object(pipeline_stages_base, "PipelineRootStage")
     auth_provider = X509AuthenticationProvider("somehostname", "somedevice", x509)
     pipeline = IoTHubPipeline(auth_provider)
     op = pipeline._pipeline.run_op.call_args[0][0]
     assert pipeline._pipeline.run_op.call_count == 1
     assert isinstance(op, pipeline_ops_iothub.SetX509AuthProviderOperation)
     assert op.auth_provider is auth_provider
    def test_cert_auth_op_fail(self, mocker, x509):
        mocker.patch.object(pipeline_stages_base, "PipelineRootStage")
        auth_provider = X509AuthenticationProvider("somehostname", "somedevice", x509)
        pipeline = IoTHubPipeline(auth_provider)
        op = pipeline._pipeline.run_op.call_args[0][0]
        op.error = Exception()

        with pytest.raises(Exception):
            op.callback(op)
コード例 #3
0
 def test_cert_auth(self, mocker, x509, pipeline_configuration):
     mocker.spy(pipeline_stages_base.PipelineRootStage, "run_op")
     auth_provider = X509AuthenticationProvider(hostname="somehostname",
                                                device_id="somedevice",
                                                x509=x509)
     pipeline = IoTHubPipeline(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
コード例 #4
0
    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="somedevice", x509=x509
        )
        with pytest.raises(arbitrary_exception.__class__):
            IoTHubPipeline(auth_provider, pipeline_configuration)
コード例 #5
0
    def test_cert_auth_op_fail(self, mocker, x509, fake_exception):
        old_execute_op = pipeline_stages_base.PipelineRootStage._execute_op

        def fail_set_auth_provider(self, op):
            if isinstance(op, pipeline_stages_base.SetX509AuthProviderOperation):
                op.error = fake_exception
                operation_flow.complete_op(stage=self, op=op)
            else:
                old_execute_op(self, op)

        mocker.patch.object(
            pipeline_stages_base.PipelineRootStage,
            "_execute_op",
            side_effect=fail_set_auth_provider,
        )

        auth_provider = X509AuthenticationProvider(
            hostname="somehostname", device_id="somedevice", x509=x509
        )
        with pytest.raises(fake_exception.__class__):
            IoTHubPipeline(auth_provider)