Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix base64 encoder #57

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public List<Encoding> getEncodings() {
.map(codificheRepository.findAll(), new TypeToken<List<Encoding>>() {}.getType());
}

private Base64.Encoder encoder = Base64.getEncoder().withoutPadding();


private String toXml(TplInformativaPSP element) {
try {
Expand All @@ -663,7 +663,7 @@ private String toXml(TplInformativaPSP element) {
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaInstance);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(informativaPSP, baos);
return encoder.encodeToString(baos.toByteArray());
return Constants.ENCODER.encodeToString(baos.toByteArray());
} catch (Exception e) {
log.error("error creating TplInformativaPSP", e);
return e.toString();
Expand All @@ -680,7 +680,7 @@ private String toXml(CtListaInformativePSP element) {
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaInstance);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(informativaPSP, baos);
return encoder.encodeToString(baos.toByteArray());
return Constants.ENCODER.encodeToString(baos.toByteArray());
} catch (Exception e) {
log.error("error creating CtListaInformativePSP", e);
return e.toString();
Expand All @@ -697,7 +697,7 @@ private String toXml(CtListaInformativeControparte element) {
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaInstance);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshal(informativaPA, baos);
return encoder.encodeToString(baos.toByteArray());
return Constants.ENCODER.encodeToString(baos.toByteArray());
} catch (Exception e) {
log.error("error creating CtListaInformativeControparte", e);
return e.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import lombok.experimental.UtilityClass;

import java.util.Base64;

@UtilityClass
public class Constants {

public static final Base64.Encoder ENCODER = Base64.getEncoder();

public static final String HEADER_REQUEST_ID = "X-Request-Id";
public static final String GZIP_JSON_V1 = "GZIP_JSON-v1";
public static final String FULL = "full";
Expand Down
17 changes: 13 additions & 4 deletions src/test/java/it/gov/pagopa/apiconfig/cache/VerifierTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package it.gov.pagopa.apiconfig.cache;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.mockito.Mockito.when;

import it.gov.pagopa.apiconfig.cache.redis.RedisRepository;
import it.gov.pagopa.apiconfig.cache.repository.VerifierRepository;
import it.gov.pagopa.apiconfig.cache.service.VerifierService;
import java.util.List;
import it.gov.pagopa.apiconfig.cache.util.Constants;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.nio.charset.StandardCharsets;
import java.util.List;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.mockito.Mockito.when;

// @SpringBootTest(classes = Application.class)
@ExtendWith(MockitoExtension.class)
class VerifierTest {
Expand All @@ -33,4 +36,10 @@ void getCacheV1() throws Exception {
List<String> allData = verifierService.getPaV2();
assertThat(allData.containsAll(TestUtils.pastazioniV2));
}

@Test
void encoding() throws Exception {
String s = Constants.ENCODER.encodeToString("listacontroparti>".getBytes(StandardCharsets.UTF_8));
assertThat(s).isEqualTo("bGlzdGFjb250cm9wYXJ0aT4=");
}
}
Loading