Skip to content

Commit

Permalink
Merge pull request #626 from pagopa/feature/QA-5209-add-parallel-conf…
Browse files Browse the repository at this point in the history
…ig-interop-tests

Feature/qa 5209 add parallel config interop tests
  • Loading branch information
mmancini95 authored Jan 13, 2025
2 parents 69dec45 + f7c0b4e commit 6f60af0
Show file tree
Hide file tree
Showing 60 changed files with 494 additions and 266 deletions.
13 changes: 13 additions & 0 deletions interop-qa-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<properties>
<configurationParameters>
cucumber.junit-platform.naming-strategy=long
</configurationParameters>
</properties>
</configuration>
</plugin>

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
import it.pagopa.interop.generated.openapi.clients.bff.model.CreatedResource;
import java.io.File;
import java.util.UUID;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class AgreementClientImpl implements IAgreementClient {
private final AgreementsApi agreementsApi;
private final RestTemplate restTemplate;
Expand All @@ -21,7 +27,7 @@ public class AgreementClientImpl implements IAgreementClient {
public AgreementClientImpl(RestTemplate restTemplate, InteropClientConfigs interopClientConfigs) {
this.restTemplate = restTemplate;
this.basePath = interopClientConfigs.getBaseUrl();
this.agreementsApi = new AgreementsApi(createApiClient("bearerToken"));
this.agreementsApi = new AgreementsApi(createApiClient("dummyBearer"));
}

private ApiClient createApiClient(String bearerToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.EservicesApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.*;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import it.pagopa.interop.generated.openapi.clients.bff.model.CreatedEServiceDescriptor;
import it.pagopa.interop.generated.openapi.clients.bff.model.CreatedResource;
import it.pagopa.interop.generated.openapi.clients.bff.model.EServiceSeed;
import it.pagopa.interop.generated.openapi.clients.bff.model.UpdateEServiceDescriptorSeed;
import java.util.UUID;
import org.springframework.web.client.RestTemplate;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class EServiceApiClientImpl implements IEServiceClient {
private final EservicesApi eservicesApi;
private final RestTemplate restTemplate;
Expand All @@ -19,7 +27,7 @@ public class EServiceApiClientImpl implements IEServiceClient {
public EServiceApiClientImpl(RestTemplate restTemplate, InteropClientConfigs interopClientConfigs) {
this.restTemplate = restTemplate;
this.basePath = interopClientConfigs.getBaseUrl();
this.eservicesApi = new EservicesApi(createApiClient("bearerToken"));
this.eservicesApi = new EservicesApi(createApiClient("dummyBearer"));
}

private ApiClient createApiClient(String bearerToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
import it.pagopa.interop.generated.openapi.clients.bff.model.Attributes;
import it.pagopa.interop.generated.openapi.clients.bff.model.CertifiedAttributeSeed;
import java.util.List;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class AttributeApiClientImpl implements IAttributeApiClient {
private final AttributesApi attributesApi;
private final RestTemplate restTemplate;
Expand All @@ -20,7 +26,7 @@ public class AttributeApiClientImpl implements IAttributeApiClient {
public AttributeApiClientImpl(RestTemplate restTemplate, InteropClientConfigs interopClientConfigs) {
this.restTemplate = restTemplate;
this.basePath = interopClientConfigs.getBaseUrl();
this.attributesApi = new AttributesApi(createApiClient("bearerToken"));
this.attributesApi = new AttributesApi(createApiClient("dummyBearer"));
}

private ApiClient createApiClient(String bearerToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
import it.pagopa.interop.authorization.domain.ExternalId;
import it.pagopa.interop.authorization.domain.Tenant;
import it.pagopa.interop.authorization.service.exception.UnsignedSTSGenerationException;
import it.pagopa.interop.authorization.service.utils.ConfigFileReader;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
Expand All @@ -32,6 +39,8 @@
import software.amazon.awssdk.services.kms.model.VerifyResponse;

@Slf4j
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
public class SessionTokenFactory {
private static final Map<String, Map<String, String>> CONFIG = new HashMap<>();
private static final Map<String, Object> SESSION_TOKEN_PAYLOAD_TEMPLATE;
Expand Down Expand Up @@ -71,9 +80,26 @@ public class SessionTokenFactory {
}

private final InteropClientConfigs interopClientConfigs;
@Getter
private Map<String, Map<String, String>> cachedTokens = null;
private ConfigFileReader configFileReader;


public SessionTokenFactory(InteropClientConfigs interopClientConfigs) {
public SessionTokenFactory(InteropClientConfigs interopClientConfigs, ConfigFileReader configFileReader) {
this.interopClientConfigs = interopClientConfigs;
this.configFileReader = configFileReader;
this.cachedTokens = loadToken();
}

private Map<String, Map<String, String>> loadToken() {
try {
if (cachedTokens == null) {
cachedTokens = generateSessionToken(configFileReader.getTenantList());
}
} catch (Exception ex) {
throw new IllegalArgumentException("There was an error while creating the session token: " + ex.getMessage(), ex);
}
return cachedTokens;
}

public Map<String, Map<String, String>> generateSessionToken(List<Tenant> configFile) throws Exception {
Expand Down Expand Up @@ -126,7 +152,6 @@ public Map<String, Map<String, String>> generateSessionToken(List<Tenant> config
log.debug("ST Payload Compiled: {}", stPayloadCompiled);

log.debug("## Step 5. Generate unsigned STs ##");
// Map<String, Map<String, String>> unsignedSTs = unsignedStsGeneration(stHeaderCompiled, stPayloadCompiled, sessionTokenPayloadValues, environment);
Map<String, Map<String, String>> unsignedSTs = unsignedStsGeneration(stHeaderCompiled, stPayloadCompiled, configFile, environment);
log.debug("Unsigned STs: {}", unsignedSTs);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package it.pagopa.interop.authorization.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import it.pagopa.interop.authorization.service.IAuthorizationClient;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
Expand All @@ -19,6 +26,8 @@
import java.util.UUID;
import org.springframework.web.client.RestTemplate;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class AuthorizationClientImpl implements IAuthorizationClient {
private final ClientsApi clientsApi;
private final RestTemplate restTemplate;
Expand All @@ -27,7 +36,7 @@ public class AuthorizationClientImpl implements IAuthorizationClient {
public AuthorizationClientImpl(RestTemplate restTemplate, InteropClientConfigs interopClientConfigs) {
this.restTemplate = restTemplate;
this.basePath = interopClientConfigs.getBaseUrl();
this.clientsApi = new ClientsApi(createApiClient("apiBearerToken"));
this.clientsApi = new ClientsApi(createApiClient("dummyBearer"));
}

private ApiClient createApiClient(String bearerToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.EservicesApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.ProducerEServiceDescriptor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.UUID;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ProducerClientImpl implements IProducerClient {
private final EservicesApi eservicesApi;
private final RestTemplate restTemplate;
Expand All @@ -17,7 +22,7 @@ public class ProducerClientImpl implements IProducerClient {
public ProducerClientImpl(RestTemplate restTemplate, InteropClientConfigs interopClientConfigs) {
this.restTemplate = restTemplate;
this.basePath = interopClientConfigs.getBaseUrl();
this.eservicesApi = new EservicesApi(createApiClient("apiBearerToken"));
this.eservicesApi = new EservicesApi(createApiClient("dummyBearer"));
}

private ApiClient createApiClient(String bearerToken) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package it.pagopa.interop.authorization.service.utils;

import it.pagopa.interop.authorization.domain.Tenant;
import lombok.Getter;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Component
@Getter
public class ConfigFileReader {
private final List<Tenant> tenantList;

public ConfigFileReader() {
this.tenantList = readProperty();
}

private List<Tenant> readProperty() {
String filePath = "config/tenants-ids.yaml";
List<Tenant> tenantList = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
Yaml yaml = new Yaml(new Constructor(Tenant.class));
yaml.loadAll(reader).forEach(i -> tenantList.add((Tenant) i));
} catch (IOException exception) {
exception.printStackTrace();
}
return tenantList;
}

}
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
package it.pagopa.interop.authorization.service.utils;

import it.pagopa.interop.authorization.domain.Tenant;
import it.pagopa.interop.authorization.service.exception.TenantsReadException;
import it.pagopa.interop.authorization.service.factory.SessionTokenFactory;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import it.pagopa.interop.conf.springconfig.InteropClientConfigs;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

@Slf4j
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class IdentityService {
private final SessionTokenFactory sessionTokenFactory;
private final ClientTokenConfigurator clientTokenConfigurator;
private final List<Tenant> configFile;

private Map<String, Map<String, String>> cachedTokens = null;
private final List<Tenant> tenantList;

public IdentityService(SessionTokenFactory sessionTokenFactory,
ClientTokenConfigurator clientTokenConfigurator) {
ConfigFileReader configFileReader) {
this.sessionTokenFactory = sessionTokenFactory;
this.clientTokenConfigurator = clientTokenConfigurator;
this.configFile = readProperty();
this.tenantList = configFileReader.getTenantList();
}

public String getToken(String tenantType, String role) {
try {
if (cachedTokens == null) {
cachedTokens = sessionTokenFactory.generateSessionToken(configFile);
}
} catch (Exception ex) {
throw new IllegalArgumentException("There was an error while creating the session token: " + ex.getMessage(), ex);
}

String token = Optional.ofNullable(cachedTokens)
String token = Optional.ofNullable(sessionTokenFactory.getCachedTokens())
.map(m -> m.get(tenantType))
.map(m -> (role == null) ? m.get("admin") : m.get(role))
.orElse(null);

if (token == null) {
throw new IllegalArgumentException("Token not found for tenant: " + tenantType + " and role: " + role);
}
.filter(Objects::nonNull)
.orElseThrow(() -> new IllegalArgumentException("Token not found for tenant: " + tenantType + " and role: " + role));
return token;
}

public void setBearerToken(String token) {
clientTokenConfigurator.setBearerToken(token);
}

public UUID getUserId(String tenantType, String role) {
return configFile.stream()
return tenantList.stream()
.filter(tenant -> tenantType.equals(tenant.getName()))
.map(Tenant::getUserRoles)
.map(userRole -> userRole.get(role))
Expand All @@ -69,7 +48,7 @@ public UUID getUserId(String tenantType, String role) {
}

public UUID getOrganizationId(String tenantType) {
return configFile.stream()
return tenantList.stream()
.filter(tenant -> tenantType.equals(tenant.getName()))
.map(Tenant::getOrganizationId)
.map(o -> o.get("dev"))
Expand All @@ -78,17 +57,4 @@ public UUID getOrganizationId(String tenantType) {
.orElse(null);
}

private List<Tenant> readProperty() {
InputStream inputStream = null;
List<Tenant> tenantList = new ArrayList<>();
try {
inputStream = new FileInputStream("config/tenants-ids.yaml");
Yaml yaml = new Yaml(new Constructor(Tenant.class));
yaml.loadAll(inputStream).forEach(i -> tenantList.add((Tenant) i));
} catch (Exception e) {
throw new TenantsReadException(e);
}
return tenantList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
import it.pagopa.interop.generated.openapi.clients.bff.ApiClient;
import it.pagopa.interop.generated.openapi.clients.bff.api.DelegationsApi;
import it.pagopa.interop.generated.openapi.clients.bff.model.*;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.io.File;
import java.util.List;
import java.util.UUID;

@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DelegationApiClientImpl implements IDelegationApiClient {
private final DelegationsApi delegationsApi;
private final RestTemplate restTemplate;
Expand All @@ -19,7 +24,7 @@ public class DelegationApiClientImpl implements IDelegationApiClient {
public DelegationApiClientImpl(RestTemplate restTemplate, InteropClientConfigs interopClientConfigs) {
this.restTemplate = restTemplate;
this.basePath = interopClientConfigs.getBaseUrl();
this.delegationsApi = new DelegationsApi(createApiClient("bearerToken"));
this.delegationsApi = new DelegationsApi(createApiClient("dummyBearer"));
}

private ApiClient createApiClient(String bearerToken) {
Expand Down
Loading

0 comments on commit 6f60af0

Please sign in to comment.