Skip to content

Commit

Permalink
[PAGOPA-2066] fix: Add key suffix when GenericPair is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Aug 30, 2024
1 parent bac3d03 commit 92f568d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/it/gov/pagopa/authorizer/util/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static String extractMetadataAsString(@NonNull List<Metadata> metadata) {
List<GenericPair> content = singleMetadata.getContent();
if (content.size() == 1) {
GenericPair metadataPair = content.get(0);
builder.append(metadataPair.getKey()).append(":");
builder.append(getMetadataValueAsString(metadataPair));
} else {
Iterator<GenericPair> it = content.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class CacheServiceTest {
@SneakyThrows
@ParameterizedTest
@CsvSource(delimiterString = "/", value = {
"0/{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=pagoPA;;\"}",
"1/{\"key\":\"domain_1\",\"value\":\"entity1#entity2|sub-entity\",\"metadata\":\"_o=pagoPA;;\"}",
"0/{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}",
"1/{\"key\":\"domain_1\",\"value\":\"entity1#entity2|sub-entity\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}",
"3/{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"\"}"
})
void addAuthConfigurationToAPIMAuthorizer_OK(int id, String subkeyDomainAsString) {

// Mocking passed values
SubscriptionKeyDomain subkeyDomain = getSubscriptionKeyDomains().get(id);
//String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=pagoPA;;\"}";
//String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}";
MockHttpResponse mockedHttpResponse = MockHttpResponse.builder().statusCode(200).uri(new URI("")).build();

// Mocking execution for service's internal component
Expand All @@ -76,7 +76,7 @@ void addAuthConfigurationToAPIMAuthorizer_OK_noAuthorizationEntities() {
// Mocking passed values
SubscriptionKeyDomain subkeyDomain = getSubscriptionKeyDomains().get(0);
subkeyDomain.setAuthorizedEntities(List.of());
String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"\",\"metadata\":\"_o=pagoPA;;\"}";
String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}";
MockHttpResponse mockedHttpResponse = MockHttpResponse.builder().statusCode(200).uri(new URI("")).build();

// Mocking execution for service's internal component
Expand All @@ -98,7 +98,7 @@ void addAuthConfigurationToAPIMAuthorizer_KO_communicationError() {

// Mocking passed values
SubscriptionKeyDomain subkeyDomain = getSubscriptionKeyDomains().get(0);
String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=pagoPA;;\"}";
String subkeyDomainAsString = "{\"key\":\"domain_1\",\"value\":\"entity1#entity2#entity3\",\"metadata\":\"_o=not-visible-key:pagoPA;;\"}";

// Mocking execution for service's internal component
HttpClient realHttpClient = spy(HttpClient.newHttpClient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void convertListToString_KO_nullParameter() {

@Test
void extractMetadataAsString_OK() {
String expectedResult = "_md1=single-value;;_md2=value1,value2;;_md3=multiple-object-1:single-value;multiple-object-2:value1,value2;;";
String expectedResult = "_md1=single-object:single-value;;_md2=single-object-with-multiple-values:value1,value2;;_md3=multiple-object-1:single-value;multiple-object-2:value1,value2;;";
String result = Utility.extractMetadataAsString(getMetadataList());
assertEquals(expectedResult, result);
}
Expand Down

0 comments on commit 92f568d

Please sign in to comment.