def test_read_bytes_non_framed(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor(source=pt_stream, key_provider=self.mock_key_provider) test_encryptor.content_type = ContentType.NO_FRAMING test_encryptor._read_bytes(5) assert not mock_read_framed.called mock_read_non_framed.assert_called_once_with(5)
def test_read_bytes_completed(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor(source=pt_stream, key_provider=self.mock_key_provider) test_encryptor._StreamEncryptor__message_complete = True test_encryptor._read_bytes(5) assert not mock_read_non_framed.called assert not mock_read_framed.called
def test_read_bytes_less_than_buffer(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor(source=pt_stream, key_provider=self.mock_key_provider) test_encryptor.output_buffer = b"1234567" test_encryptor._read_bytes(5) assert not mock_read_non_framed.called assert not mock_read_framed.called
def test_read_bytes_closed(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor(source=pt_stream, key_provider=self.mock_key_provider) test_encryptor.source_stream.close() test_encryptor._read_bytes(5) assert not mock_read_non_framed.called assert not mock_read_framed.called
def test_read_bytes_framed(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, materials_manager=self.mock_materials_manager, commitment_policy=self.mock_commitment_policy, ) test_encryptor.content_type = ContentType.FRAMED_DATA test_encryptor._read_bytes(5) assert not mock_read_non_framed.called mock_read_framed.assert_called_once_with(5)
def test_read_bytes_unsupported_type(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor(source=pt_stream, key_provider=self.mock_key_provider) test_encryptor._encryption_materials = self.mock_encryption_materials test_encryptor._header = MagicMock() test_encryptor.content_type = None with pytest.raises(NotSupportedError) as excinfo: test_encryptor._read_bytes(5) excinfo.match("Unsupported content type") assert not mock_read_non_framed.called assert not mock_read_framed.called
def test_read_bytes_completed(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, materials_manager=self.mock_materials_manager, commitment_policy=self.mock_commitment_policy, ) test_encryptor._StreamEncryptor__message_complete = True test_encryptor._read_bytes(5) assert not mock_read_non_framed.called assert not mock_read_framed.called
def test_read_bytes_less_than_buffer(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, materials_manager=self.mock_materials_manager, commitment_policy=self.mock_commitment_policy, ) test_encryptor.output_buffer = b"1234567" test_encryptor._read_bytes(5) assert not mock_read_non_framed.called assert not mock_read_framed.called
def test_read_bytes_unsupported_type(self, mock_read_non_framed, mock_read_framed): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, key_provider=self.mock_key_provider ) test_encryptor._encryption_materials = self.mock_encryption_materials test_encryptor._header = MagicMock() test_encryptor.content_type = None with six.assertRaisesRegex(self, NotSupportedError, 'Unsupported content type'): test_encryptor._read_bytes(5) assert not mock_read_non_framed.called assert not mock_read_framed.called