1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-06-26 05:24:49 +02:00
pgpainless/pgpainless-core/src/test/java/org/pgpainless/encryption_signing/EncryptionStreamClosedTest.java

35 lines
1.2 KiB
Java
Raw Normal View History

2021-10-07 15:48:52 +02:00
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
2021-02-12 01:23:32 +01:00
package org.pgpainless.encryption_signing;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.bouncycastle.openpgp.PGPException;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
2021-02-12 01:23:32 +01:00
import org.pgpainless.PGPainless;
import org.pgpainless.util.TestAllImplementations;
import org.pgpainless.s2k.Passphrase;
2021-02-12 01:23:32 +01:00
public class EncryptionStreamClosedTest {
@TestTemplate
@ExtendWith(TestAllImplementations.class)
public void testStreamHasToBeClosedBeforeGetResultCanBeCalled() throws IOException, PGPException {
2021-02-12 01:23:32 +01:00
OutputStream out = new ByteArrayOutputStream();
EncryptionStream stream = PGPainless.encryptAndOrSign()
.onOutputStream(out)
2021-06-29 16:43:37 +02:00
.withOptions(ProducerOptions.encrypt(EncryptionOptions.encryptCommunications()
.addPassphrase(Passphrase.fromPassword("dummy"))));
2021-02-12 01:23:32 +01:00
// No close() called => getResult throws
assertThrows(IllegalStateException.class, stream::getResult);
}
}