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;
|
2021-12-14 16:55:04 +01:00
|
|
|
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;
|
2021-12-14 16:56:29 +01:00
|
|
|
import org.pgpainless.util.TestAllImplementations;
|
2021-02-12 01:23:32 +01:00
|
|
|
import org.pgpainless.util.Passphrase;
|
|
|
|
|
|
|
|
public class EncryptionStreamClosedTest {
|
|
|
|
|
2021-12-14 16:55:04 +01:00
|
|
|
@TestTemplate
|
2021-12-14 16:56:29 +01:00
|
|
|
@ExtendWith(TestAllImplementations.class)
|
2021-12-14 16:55:04 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|