Skip to content

Commit

Permalink
[SELC-5037] fix: remove lang from billingUrl in exchange/fatturazione…
Browse files Browse the repository at this point in the history
… API (#459)
  • Loading branch information
giulia-tremolada authored Jun 20, 2024
1 parent 261743a commit a693dc8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public URI billingToken(@ApiParam("${swagger.dashboard.institutions.model.id}")
log.debug("billing exchange institutionId = {}", Encode.forJava(institutionId));
log.info("env parameter: {}", Encode.forJava(environment.orElse("")));

final ExchangedToken exchangedToken = exchangeTokenService.retrieveBillingExchangedToken(institutionId, lang);
final ExchangedToken exchangedToken = exchangeTokenService.retrieveBillingExchangedToken(institutionId);
final URI location = URI.create(exchangedToken.getBackOfficeUrl().replace("<IdentityToken>", exchangedToken.getIdentityToken()));
log.debug(LogUtils.CONFIDENTIAL_MARKER, "billing exchange result = {}", Encode.forJava(String.valueOf(location)));
log.trace("billing exchange end");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public ExchangedToken exchange(String institutionId, String productId, Optional<
return new ExchangedToken(jwts, urlBO);
}

public ExchangedToken retrieveBillingExchangedToken(String institutionId, String lang) {
public ExchangedToken retrieveBillingExchangedToken(String institutionId) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || authentication.getPrincipal() == null || authentication.getCredentials() == null) {
throw new IllegalStateException("Authentication is required");
Expand Down Expand Up @@ -165,9 +165,8 @@ public ExchangedToken retrieveBillingExchangedToken(String institutionId, String
String jwts = createJwts(claims);
log.debug(LogUtils.CONFIDENTIAL_MARKER, "Exchanged token = {}", jwts);
log.trace("exchange end");
final String billingUrlLang = Objects.nonNull(lang) ? billingUrl.concat("?lang=" + lang) : billingUrl;

return new ExchangedToken(jwts, billingUrlLang);
return new ExchangedToken(jwts, billingUrl);
}

private List<String> retrieveInvoiceableProductList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void exchange_emptyIdentityToken() throws Exception {
void billingExchange() throws Exception {
// given
String institutionId = "inst1";
Mockito.when(exchangeTokenServiceMock.retrieveBillingExchangedToken(institutionId, null))
Mockito.when(exchangeTokenServiceMock.retrieveBillingExchangedToken(institutionId))
.thenReturn(new ExchangedToken("token", "urlBO"));
// when
MvcResult result = mockMvc.perform(MockMvcRequestBuilders
Expand All @@ -107,15 +107,15 @@ void billingExchange() throws Exception {
assertNotNull(resource);
assertEquals(resource.toString(), "urlBO");
verify(exchangeTokenServiceMock, Mockito.times(1))
.retrieveBillingExchangedToken(institutionId, null);
.retrieveBillingExchangedToken(institutionId);
verifyNoMoreInteractions(exchangeTokenServiceMock);
}

@Test
void billingExchange_emptyIdentityToken() throws Exception {
// given
String institutionId = "inst1";
Mockito.when(exchangeTokenServiceMock.retrieveBillingExchangedToken(institutionId, null))
Mockito.when(exchangeTokenServiceMock.retrieveBillingExchangedToken(institutionId))
.thenReturn(new ExchangedToken("", ""));
// when
MvcResult result = mockMvc.perform(MockMvcRequestBuilders
Expand All @@ -130,7 +130,7 @@ void billingExchange_emptyIdentityToken() throws Exception {
assertNotNull(resource);
assertEquals(resource.toString(), "");
verify(exchangeTokenServiceMock, Mockito.times(1))
.retrieveBillingExchangedToken(institutionId, null);
.retrieveBillingExchangedToken(institutionId);
verifyNoMoreInteractions(exchangeTokenServiceMock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ void billingExchange_noAuth() throws Exception {
JwtService jwtServiceMock = mock(JwtService.class);
ExchangeTokenServiceV2 ExchangeTokenServiceV2 = new ExchangeTokenServiceV2(jwtServiceMock, null, null, null, properties, null, null, new InstitutionResourceMapperImpl());
// when
Executable executable = () -> ExchangeTokenServiceV2.retrieveBillingExchangedToken(null, null);
Executable executable = () -> ExchangeTokenServiceV2.retrieveBillingExchangedToken(null);
// then
IllegalStateException e = assertThrows(IllegalStateException.class, executable);
assertEquals("Authentication is required", e.getMessage());
Expand Down Expand Up @@ -710,7 +710,7 @@ void billingExchange_noSessionTokenClaims() throws Exception {

ExchangeTokenServiceV2 ExchangeTokenServiceV2 = new ExchangeTokenServiceV2(jwtServiceMock, institutionServiceMock, groupServiceMock, productsConnector, properties, null, userApiConnector, new InstitutionResourceMapperImpl());

Executable executable = () -> ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId, null);
Executable executable = () -> ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId);
// then
RuntimeException e = assertThrows(IllegalArgumentException.class, executable);
assertEquals("Session token claims is required", e.getMessage());
Expand Down Expand Up @@ -753,7 +753,7 @@ void billingExchange_noInstitutionInfo() throws Exception {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(SelfCareUser.builder("ccbc5350-0ba7-47bc-9f61-8c65001939f9").build(), "password", authorities);
TestSecurityContextHolder.setAuthentication(authentication);
// when
Executable executable = () -> ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId, null);
Executable executable = () -> ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId);
// then
RuntimeException e = assertThrows(IllegalArgumentException.class, executable);
assertEquals("Institution info is required", e.getMessage());
Expand Down Expand Up @@ -850,7 +850,7 @@ void billingExchange_nullGroupInfo(PrivateKey privateKey) throws Exception {
when(userApiConnector.getProducts(institutionId, String.valueOf(userId))).thenReturn(userInstitution);
ExchangeTokenServiceV2 ExchangeTokenServiceV2 = new ExchangeTokenServiceV2(jwtServiceMock, institutionServiceMock, groupServiceMock, productsConnectorMock, properties, UserV2Service, userApiConnector, new InstitutionResourceMapperImpl());
// when
final ExchangedToken exchangedToken = ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId, null);
final ExchangedToken exchangedToken = ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId);
// then
assertNotNull(exchangedToken.getIdentityToken());
Jws<Claims> claimsJws = Jwts.parser()
Expand Down Expand Up @@ -892,7 +892,6 @@ void billingExchange_nullGroupInfo(PrivateKey privateKey) throws Exception {
@EnumSource(PrivateKey.class)
void billingExchange_ok(PrivateKey privateKey) throws Exception {
// given
String lang = "en";
String jti = "id";
String credential = "password";
Date iat = Date.from(Instant.now().minusSeconds(1));
Expand Down Expand Up @@ -976,7 +975,7 @@ void billingExchange_ok(PrivateKey privateKey) throws Exception {
when(userApiConnector.getProducts(institutionId, String.valueOf(userId))).thenReturn(userInstitution);
ExchangeTokenServiceV2 ExchangeTokenServiceV2 = new ExchangeTokenServiceV2(jwtServiceMock, institutionServiceMock, groupServiceMock, productsConnectorMock, properties, UserV2Service, userApiConnector, new InstitutionResourceMapperImpl());
// when
final ExchangedToken exchangedToken = ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId, lang);
final ExchangedToken exchangedToken = ExchangeTokenServiceV2.retrieveBillingExchangedToken(institutionId);
// then
assertNotNull(exchangedToken.getIdentityToken());
Jws<Claims> claimsJws = Jwts.parser()
Expand Down

0 comments on commit a693dc8

Please sign in to comment.