Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
max402 committed Feb 6, 2024
1 parent e4dba7d commit 120b971
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import de.adorsys.datasafe.encrypiton.impl.cmsencryption.exceptions.DecryptionException;
import de.adorsys.datasafe.encrypiton.impl.utils.ProviderUtils;
import de.adorsys.datasafe.types.api.context.annotations.RuntimeDelegate;
import de.adorsys.keymanagement.api.config.keystore.KeyStoreConfig;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
Expand Down Expand Up @@ -82,10 +83,10 @@ private RecipientInfoGenerator getRecipientInfoGenerator(PublicKeyIDWithPublicKe
@SneakyThrows
public JceKeyAgreeRecipientInfoGenerator getJceKeyAgreeRecipientInfoGenerator(KeyPair senderKeyPair, PublicKeyIDWithPublicKey publicKeyWithId) {
var jceKeyAgreeRecipientInfoGenerator = new JceKeyAgreeRecipientInfoGenerator(
CMSAlgorithm.ECDH_SHA1KDF,
CMSAlgorithm.ECDH_SHA256KDF,
senderKeyPair.getPrivate(),
senderKeyPair.getPublic(),
CMSAlgorithm.AES128_WRAP);
encryptionConfig.getAlgorithm());
jceKeyAgreeRecipientInfoGenerator.addRecipient(publicKeyWithId.getKeyID().getValue().getBytes(), publicKeyWithId.getPublicKey());
return jceKeyAgreeRecipientInfoGenerator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import java.io.ByteArrayOutputStream;

import static de.adorsys.datasafe.rest.impl.controller.BaseTokenDatasafeEndpointTest.TEST_PASS;
import static de.adorsys.datasafe.rest.impl.controller.BaseTokenDatasafeEndpointTest.TEST_USER;
import static de.adorsys.datasafe.rest.impl.controller.BaseTokenDatasafeEndpointTest.TEST_USER_RECIPIENT;
import static de.adorsys.datasafe.rest.impl.controller.TestHelper.putFileBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -26,8 +29,6 @@ public class AuthenticateControllerTest extends BaseDatasafeEndpointTest {

private static final String DEFAULT_TEST_USERNAME = "username";
private static final String DEFAULT_TEST_PASSWORD = "password";

private static final String TEST_USER = "test";
private static final String TEST_PATH = "test.txt";

@MockBean
Expand Down Expand Up @@ -81,12 +82,14 @@ void testPutDataWithToken() {
String token = sendAuthenticateRequest(userDTO).getResponse().getHeader(SecurityConstants.TOKEN_HEADER);

mvc.perform(
putFileBuilder("/inbox/document/{path}", TEST_PATH).
contentType(MediaType.MULTIPART_FORM_DATA_VALUE).
content("file content".getBytes()).
header("users", TEST_USER).
header(SecurityConstants.TOKEN_HEADER, token))
.andExpect(status().isOk());
putFileBuilder("/inbox/document/{path}", TEST_PATH)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
.content("file content".getBytes())
.header("user", TEST_USER)
.header("password", TEST_PASS)
.header("recipients", TEST_USER_RECIPIENT)
.header(SecurityConstants.TOKEN_HEADER, token))
.andExpect(status().isOk());
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public abstract class BaseTokenDatasafeEndpointTest extends BaseDatasafeEndpoint
static final String PASSWORD_DESCRIPTION = "datasafe user's password";

static final String TEST_USER = "test";

static final String TEST_USER_RECIPIENT = "recipient";

static final ReadKeyPassword TEST_PASS = ReadKeyPasswordHelper.getForString("test");
String token;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ void writeToInboxTest() {
),
requestHeaders(
headerWithName("token").description(TOKEN_DESCRIPTION),
headerWithName("users").description("recipients array")
headerWithName("user").description(USER_DESCRIPTION),
headerWithName("password").description(PASSWORD_DESCRIPTION),
headerWithName("recipients").description("recipients array")
)
);

mvc.perform(putFileBuilder("/inbox/document/{path}", TEST_PATH)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
.header("users", TEST_USER)
.header("token", token)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
.header("user", TEST_USER)
.header("password", TEST_PASS)
.header("recipients", TEST_USER_RECIPIENT)
.header("token", token)
)
.andExpect(status().isOk())
.andDo(document);
Expand Down

0 comments on commit 120b971

Please sign in to comment.