From e59e245f5b9f5a99ff1211356a47af5bf63effbb Mon Sep 17 00:00:00 2001 From: Dominik Pinsel Date: Fri, 2 Feb 2024 09:24:51 +0100 Subject: [PATCH] chore: add smoke tests for generated api clients Signed-off-by: Dominik Pinsel --- documentation/api/v2/Apis/AdministratorApi.md | 18 ++--- documentation/api/v2/Apis/UserApi.md | 24 +++--- documentation/api/v2/README.md | 5 +- .../api/v2/ApiRolesV2.java | 4 +- .../config/ApplicationConfig.java | 11 ++- .../src/main/resources/static/openapi_v2.yaml | 47 ++++++++++- .../user/GetWalletUserApiHandlerTest.java | 1 + .../client/okhttp3/OkHttp3ClientV2Test.java | 73 +++++++++++++++-- .../RestTemplateClientV2Test.java | 80 +++++++++++++++++++ .../test/util/TestAuthV2Util.java | 17 ++-- 10 files changed, 230 insertions(+), 50 deletions(-) diff --git a/documentation/api/v2/Apis/AdministratorApi.md b/documentation/api/v2/Apis/AdministratorApi.md index 997e3c900..9578e4347 100644 --- a/documentation/api/v2/Apis/AdministratorApi.md +++ b/documentation/api/v2/Apis/AdministratorApi.md @@ -35,7 +35,7 @@ Create Verifiable Credential ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -62,7 +62,7 @@ Create Wallet for User ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -89,7 +89,7 @@ null (empty response body) ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -116,7 +116,7 @@ null (empty response body) ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -143,7 +143,7 @@ Get Verifiable Credentials by Id ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -175,7 +175,7 @@ Get Verifiable Credentials ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -202,7 +202,7 @@ Get Wallet for User ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -230,7 +230,7 @@ Get All Wallets ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -257,7 +257,7 @@ Update Wallet for User ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/documentation/api/v2/Apis/UserApi.md b/documentation/api/v2/Apis/UserApi.md index 415105b0a..d8631f39f 100644 --- a/documentation/api/v2/Apis/UserApi.md +++ b/documentation/api/v2/Apis/UserApi.md @@ -38,7 +38,7 @@ Create Verifiable Credential ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -65,7 +65,7 @@ null (empty response body) ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -94,7 +94,7 @@ Get Issued Verifiable Credentials ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -121,7 +121,7 @@ Get Verifiable Credential by ID ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -151,7 +151,7 @@ Get Verifiable Credentials ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -175,7 +175,7 @@ This endpoint does not need any parameter. ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -202,7 +202,7 @@ Issue Verifiable Credential ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -229,7 +229,7 @@ Issue Verifiable Presentation ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -256,7 +256,7 @@ Issue Verifiable Presentation as JWT ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -283,7 +283,7 @@ Validate Verifiable Credential ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -310,7 +310,7 @@ Validate Verifiable JWT Presentation ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers @@ -337,7 +337,7 @@ Validate Verifiable Presentation ### Authorization -No authorization required +[OAuth2](../README.md#OAuth2) ### HTTP request headers diff --git a/documentation/api/v2/README.md b/documentation/api/v2/README.md index 49bbb58fb..8018fc2f4 100644 --- a/documentation/api/v2/README.md +++ b/documentation/api/v2/README.md @@ -72,7 +72,6 @@ All URIs are relative to */api/v2* - **Flow**: accessCode - **Authorization URL**: https://example.com/oauth/authorize - **Scopes**: - - read: Grants read access - - write: Grants write access - - admin: Grants access to admin operations + - miw:admin: Grants access to admin operations + - miw:user: Grants access to user operations diff --git a/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/api/v2/ApiRolesV2.java b/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/api/v2/ApiRolesV2.java index a0ff5ee57..cfec0c22d 100644 --- a/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/api/v2/ApiRolesV2.java +++ b/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/api/v2/ApiRolesV2.java @@ -4,8 +4,8 @@ @NoArgsConstructor(access = lombok.AccessLevel.PRIVATE) public class ApiRolesV2 { - public static final String ADMIN = "MIW_ADMIN"; + public static final String ADMIN = "miw:admin"; public static final String ADMIN_ROLE = "ROLE_" + ADMIN; - public static final String WALLET_OWNER = "MIW_WALLET_OWNER"; + public static final String WALLET_OWNER = "miw:user"; public static final String WALLET_OWNER_ROLE = "ROLE_" + WALLET_OWNER; } diff --git a/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/ApplicationConfig.java b/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/ApplicationConfig.java index 2909ae3d7..6df51fcb6 100644 --- a/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/ApplicationConfig.java +++ b/managed-identity-wallets-app/src/main/java/org/eclipse/tractusx/managedidentitywallets/config/ApplicationConfig.java @@ -23,8 +23,11 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.smartsensesolutions.java.commons.specification.SpecificationUtil; @@ -80,8 +83,8 @@ public ObjectMapper objectMapper() { SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer() { @Override - public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { - jsonGenerator.writeString(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(offsetDateTime)); + public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeString(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetDateTime)); } }); objectMapper.registerModule(simpleModule); diff --git a/managed-identity-wallets-app/src/main/resources/static/openapi_v2.yaml b/managed-identity-wallets-app/src/main/resources/static/openapi_v2.yaml index c06176dbf..3d0d993d4 100644 --- a/managed-identity-wallets-app/src/main/resources/static/openapi_v2.yaml +++ b/managed-identity-wallets-app/src/main/resources/static/openapi_v2.yaml @@ -16,6 +16,8 @@ paths: - User summary: Get Wallet description: Retrieves wallet information. + security: + - OAuth2: [ miw:user ] responses: '200': description: Successful response with wallet information. @@ -31,6 +33,8 @@ paths: - User summary: Get Verifiable Credentials description: Retrieves a list of Verifiable Credentials from the wallet. + security: + - OAuth2: [ miw:user ] parameters: - $ref: '#/components/parameters/Query_Page' - $ref: '#/components/parameters/Query_Per_Page' @@ -49,6 +53,8 @@ paths: - User summary: Create Verifiable Credential description: Stores the Verifiable Credential in the wallet. + security: + - OAuth2: [ miw:user ] requestBody: required: true content: @@ -72,6 +78,8 @@ paths: - User summary: Get Verifiable Credential by ID description: Retrieves a verifiable credential from the wallet by ID. + security: + - OAuth2: [ miw:user ] parameters: - $ref: '#/components/parameters/Path_Verifiable_Credential_Id' responses: @@ -89,6 +97,8 @@ paths: - User summary: Delete Verifiable Credential description: Removes Verifiable Credential from the wallet by ID. + security: + - OAuth2: [ miw:user ] parameters: - $ref: '#/components/parameters/Path_Verifiable_Credential_Id' responses: @@ -104,6 +114,8 @@ paths: - User summary: Issue Verifiable Presentation description: Issues a new Verifiable Presentation. + security: + - OAuth2: [ miw:user ] requestBody: content: application/json: @@ -126,6 +138,8 @@ paths: - User summary: Issue Verifiable Presentation as JWT description: Issues a new Verifiable Presentation as JWT. + security: + - OAuth2: [ miw:user ] requestBody: content: application/json: @@ -148,6 +162,8 @@ paths: - User summary: Get Issued Verifiable Credentials description: Retrieves a list of issued Verifiable Credentials. These Verifiable Credentials may or may not be stored in the wallet. + security: + - OAuth2: [ miw:user ] parameters: - $ref: '#/components/parameters/Query_Page' - $ref: '#/components/parameters/Query_Per_Page' @@ -165,6 +181,8 @@ paths: - User summary: Issue Verifiable Credential description: Issues a new Verifiable Credential. + security: + - OAuth2: [ miw:user ] requestBody: content: application/json: @@ -186,6 +204,8 @@ paths: - User summary: Validate Verifiable Credential description: Validates a Verifiable Credential + security: + - OAuth2: [ miw:user ] requestBody: content: application/json: @@ -207,6 +227,8 @@ paths: - User summary: Validate Verifiable Presentation description: Validates a Verifiable Presentation + security: + - OAuth2: [ miw:user ] requestBody: content: application/json: @@ -228,6 +250,8 @@ paths: - User summary: Validate Verifiable JWT Presentation description: Validates a Verifiable JWT Presentation + security: + - OAuth2: [ miw:user ] requestBody: content: application/json: @@ -253,6 +277,8 @@ paths: - $ref: '#/components/parameters/Query_Page' - $ref: '#/components/parameters/Query_Per_Page' description: Retrieves a list of wallets. + security: + - OAuth2: [ miw:admin ] responses: '200': description: Successful response with a list of wallets. @@ -266,6 +292,8 @@ paths: - Administrator summary: Create Wallet for User description: Creates a wallet for a user. + security: + - OAuth2: [ miw:admin ] requestBody: required: true content: @@ -290,6 +318,8 @@ paths: - Administrator summary: Update Wallet for User description: Updates a wallet for a user by user ID. + security: + - OAuth2: [ miw:admin ] requestBody: required: true content: @@ -313,6 +343,8 @@ paths: - Administrator summary: Get Wallet for User description: Retrieves a wallet for a user by user ID. + security: + - OAuth2: [ miw:admin ] parameters: - $ref: '#/components/parameters/Path_Wallet_Id' responses: @@ -330,6 +362,8 @@ paths: - Administrator summary: Delete Wallet for User description: Deletes a wallet for by wallet ID. + security: + - OAuth2: [ miw:admin ] parameters: - $ref: '#/components/parameters/Path_Wallet_Id' responses: @@ -343,6 +377,8 @@ paths: - Administrator summary: Get Verifiable Credentials description: Retrieves a list of verifiable credentials + security: + - OAuth2: [ miw:admin ] parameters: - $ref: '#/components/parameters/Query_Page' - $ref: '#/components/parameters/Query_Per_Page' @@ -363,6 +399,8 @@ paths: - Administrator summary: Create Verifiable Credential description: Creates a verifiable credential + security: + - OAuth2: [ miw:admin ] requestBody: required: true content: @@ -386,6 +424,8 @@ paths: - Administrator summary: Get Verifiable Credentials by Id description: Retrieves a list of verifiable credentials for a user by user ID. + security: + - OAuth2: [ miw:admin ] parameters: - $ref: '#/components/parameters/Path_Verifiable_Credential_Id' responses: @@ -403,6 +443,8 @@ paths: - Administrator summary: Delete Verifiable Credential description: Deletes a verifiable credential + security: + - OAuth2: [ miw:admin ] parameters: - $ref: '#/components/parameters/Path_Verifiable_Credential_Id' responses: @@ -804,6 +846,5 @@ components: authorizationUrl: https://example.com/oauth/authorize tokenUrl: https://example.com/oauth/token scopes: - read: Grants read access - write: Grants write access - admin: Grants access to admin operations + miw:admin: Grants access to admin operations + miw:user: Grants access to user operations diff --git a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/api/v2/delegate/user/GetWalletUserApiHandlerTest.java b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/api/v2/delegate/user/GetWalletUserApiHandlerTest.java index 087b6b7d8..bdc13cf11 100644 --- a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/api/v2/delegate/user/GetWalletUserApiHandlerTest.java +++ b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/api/v2/delegate/user/GetWalletUserApiHandlerTest.java @@ -82,6 +82,7 @@ public void testGetWalletUserApiSuccess() { .when() .get("/api/v2/wallet") .then() + .log().all() .statusCode(200) .body("id", equalTo(bpn)); } diff --git a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/okhttp3/OkHttp3ClientV2Test.java b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/okhttp3/OkHttp3ClientV2Test.java index 9221286cb..2d2166d08 100644 --- a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/okhttp3/OkHttp3ClientV2Test.java +++ b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/okhttp3/OkHttp3ClientV2Test.java @@ -1,35 +1,92 @@ package org.eclipse.tractusx.managedidentitywallets.client.okhttp3; +import io.restassured.http.Header; import lombok.SneakyThrows; +import org.eclipse.tractusx.managedidentitywallets.api.v2.ApiRolesV2; +import org.eclipse.tractusx.managedidentitywallets.client.v2.okhttp3.ApiClient; +import org.eclipse.tractusx.managedidentitywallets.client.v2.okhttp3.ApiException; +import org.eclipse.tractusx.managedidentitywallets.client.v2.okhttp3.controllers.AdministratorManagedIdentityWalletApiV2; import org.eclipse.tractusx.managedidentitywallets.client.v2.okhttp3.controllers.UserManagedIdentityWalletApiV2; +import org.eclipse.tractusx.managedidentitywallets.models.Wallet; import org.eclipse.tractusx.managedidentitywallets.test.MiwTestCase; +import org.eclipse.tractusx.managedidentitywallets.test.util.TestAuthV2Util; +import org.eclipse.tractusx.managedidentitywallets.test.util.TestPersistenceUtil; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.server.LocalServerPort; +import java.util.List; + /** * Test class for the API v2 client generated by OpenAPI Generator project 'managed-identity-wallets-client-okhttp3-v2'. + *

+ * This class does not test the whole API, it functions mainly as simple functional/smoke test for the generated client. The actual tests for the API are more contract like written in rest assured. */ public class OkHttp3ClientV2Test extends MiwTestCase { private UserManagedIdentityWalletApiV2 userManagedIdentityWalletApiV2 = null; + private AdministratorManagedIdentityWalletApiV2 administratorManagedIdentityWalletApiV2 = null; + + @Autowired + private TestAuthV2Util testAuthV2Util; + + @Autowired + private TestPersistenceUtil testPersistenceUtil; @LocalServerPort private int port; - @BeforeEach - public void setUp() { - userManagedIdentityWalletApiV2 = new UserManagedIdentityWalletApiV2(); - userManagedIdentityWalletApiV2.setCustomBaseUrl("http://localhost:" + port); - } - @Test @SneakyThrows - public void getWalletTest() { + public void getWalletTestSuccess() { + initializeClient(ApiRolesV2.WALLET_OWNER); var userWallet = userManagedIdentityWalletApiV2.userGetWallet(); Assertions.assertNotNull(userWallet.getId()); } + + @Test + @SneakyThrows + public void getWalletTestUnauthorized() { + initializeClient(ApiRolesV2.ADMIN); + + Assertions.assertThrows(ApiException.class, () -> + userManagedIdentityWalletApiV2.userGetWallet()); + } + + @Test + @SneakyThrows + public void getWalletsSuccess() { + initializeClient(ApiRolesV2.ADMIN); + var userWallet = administratorManagedIdentityWalletApiV2.adminGetWallets(0, 1); + + Assertions.assertEquals(1, userWallet.getSize()); + } + + @Test + @SneakyThrows + public void getWalletsUnauthorized() { + initializeClient(ApiRolesV2.WALLET_OWNER); + + Assertions.assertThrows(ApiException.class, () -> + administratorManagedIdentityWalletApiV2.adminGetWallets(0, 1)); + } + + private void initializeClient(String role) { + + final Wallet wallet = testPersistenceUtil.newWalletPersisted(); + final List roles = List.of(role); + final Header header = testAuthV2Util.getAuthHeader(roles, wallet); + + final ApiClient apiClient = new ApiClient(); + apiClient.addDefaultHeader(header.getName(), header.getValue()); + + userManagedIdentityWalletApiV2 = new UserManagedIdentityWalletApiV2(apiClient); + userManagedIdentityWalletApiV2.setCustomBaseUrl("http://localhost:" + port + "/api/v2"); + + administratorManagedIdentityWalletApiV2 = new AdministratorManagedIdentityWalletApiV2(apiClient); + administratorManagedIdentityWalletApiV2.setCustomBaseUrl("http://localhost:" + port + "/api/v2"); + } } diff --git a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/resttemplate/RestTemplateClientV2Test.java b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/resttemplate/RestTemplateClientV2Test.java index 53ec6e4aa..ac30c269b 100644 --- a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/resttemplate/RestTemplateClientV2Test.java +++ b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/client/resttemplate/RestTemplateClientV2Test.java @@ -1,10 +1,90 @@ package org.eclipse.tractusx.managedidentitywallets.client.resttemplate; +import io.restassured.http.Header; +import lombok.SneakyThrows; +import org.eclipse.tractusx.managedidentitywallets.api.v2.ApiRolesV2; +import org.eclipse.tractusx.managedidentitywallets.client.v2.resttemplate.ApiClient; +import org.eclipse.tractusx.managedidentitywallets.client.v2.resttemplate.controllers.AdministratorManagedIdentityWalletApiV2; +import org.eclipse.tractusx.managedidentitywallets.client.v2.resttemplate.controllers.UserManagedIdentityWalletApiV2; +import org.eclipse.tractusx.managedidentitywallets.models.Wallet; import org.eclipse.tractusx.managedidentitywallets.test.MiwTestCase; +import org.eclipse.tractusx.managedidentitywallets.test.util.TestAuthV2Util; +import org.eclipse.tractusx.managedidentitywallets.test.util.TestPersistenceUtil; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.List; /** * Test class for the API v2 client generated by OpenAPI Generator project 'managed-identity-wallets-client-resttemplate-v2'. + *

+ * This class does not test the whole API, it functions mainly as simple functional/smoke test for the generated client. The actual tests for the API are more contract like written in rest assured. */ public class RestTemplateClientV2Test extends MiwTestCase { + + private UserManagedIdentityWalletApiV2 userManagedIdentityWalletApiV2 = null; + private AdministratorManagedIdentityWalletApiV2 administratorManagedIdentityWalletApiV2 = null; + + @Autowired + private TestAuthV2Util testAuthV2Util; + + @Autowired + private TestPersistenceUtil testPersistenceUtil; + + @LocalServerPort + private int port; + + @Test + @SneakyThrows + public void getWalletTestSuccess() { + initializeClient(ApiRolesV2.WALLET_OWNER); + var userWallet = userManagedIdentityWalletApiV2.userGetWallet(); + + Assertions.assertNotNull(userWallet.getId()); + } + + @Test + @SneakyThrows + public void getWalletTestUnauthorized() { + initializeClient(ApiRolesV2.ADMIN); + + Assertions.assertThrows(HttpClientErrorException.class, () -> + userManagedIdentityWalletApiV2.userGetWallet()); + } + + @Test + @SneakyThrows + public void getWalletsSuccess() { + initializeClient(ApiRolesV2.ADMIN); + var userWallet = administratorManagedIdentityWalletApiV2.adminGetWallets(0, 1); + + Assertions.assertEquals(1, userWallet.getSize()); + } + + @Test + @SneakyThrows + public void getWalletsUnauthorized() { + initializeClient(ApiRolesV2.WALLET_OWNER); + + Assertions.assertThrows(HttpClientErrorException.class, () -> + administratorManagedIdentityWalletApiV2.adminGetWallets(0, 1)); + } + + private void initializeClient(String role) { + + final Wallet wallet = testPersistenceUtil.newWalletPersisted(); + final List roles = List.of(role); + final Header header = testAuthV2Util.getAuthHeader(roles, wallet); + + final ApiClient apiClient = new ApiClient(); + apiClient.addDefaultHeader(header.getName(), header.getValue()); + apiClient.setBasePath("http://localhost:" + port + "/api/v2"); + + userManagedIdentityWalletApiV2 = new UserManagedIdentityWalletApiV2(apiClient); + administratorManagedIdentityWalletApiV2 = new AdministratorManagedIdentityWalletApiV2(apiClient); + } } diff --git a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/test/util/TestAuthV2Util.java b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/test/util/TestAuthV2Util.java index 048c27f58..4553e73c7 100644 --- a/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/test/util/TestAuthV2Util.java +++ b/managed-identity-wallets-app/src/test/java/org/eclipse/tractusx/managedidentitywallets/test/util/TestAuthV2Util.java @@ -57,8 +57,6 @@ public class TestAuthV2Util { private static final String KEYCLOAK_ADMIN_USER_PASSWORD = "admin"; private static final String ATTRIBUTE_BPN = "bpn"; - private final TestPersistenceUtil testPersistenceUtil; - public Header getAuthHeader(@NonNull List roles) { return getAuthHeader(roles, null); } @@ -94,7 +92,7 @@ public Header getAuthHeader(@NonNull List roles, Wallet wallet) { return new Header(HttpHeaders.AUTHORIZATION, "Bearer " + token); } - public void createRealm(String newRealmName) { + private void createRealm(@NonNull String newRealmName) { final Keycloak keycloak = getAdminKeycloak(); RealmsResource realmsResource = keycloak.realms(); @@ -111,7 +109,7 @@ public void createRealm(String newRealmName) { realmsResource.create(newRealm); } - public Client createClient(@NonNull String clientId, @NonNull String clientSecret) { + private Client createClient(@NonNull String clientId, @NonNull String clientSecret) { final Keycloak keycloak = getAdminKeycloak(); final RealmResource realmResource = keycloak.realm(KEYCLOAK_DEFAULT_REALM); @@ -119,7 +117,7 @@ public Client createClient(@NonNull String clientId, @NonNull String clientSecre final Optional existingClient = clientsResource.findAll().stream().filter(client -> client.getClientId().equals(clientId)).findFirst(); if (existingClient.isPresent()) { - return new Client(existingClient.get().getId(), clientId); + return new Client(existingClient.get().getId(), clientId, existingClient.get().getSecret()); } /* map bpn attribute in access token */ @@ -153,7 +151,7 @@ public Client createClient(@NonNull String clientId, @NonNull String clientSecre final String responseClientId = CreatedResponseUtil.getCreatedId(response); - return new Client(responseClientId, clientId); + return new Client(responseClientId, clientId, clientSecret); } private User createUser() { @@ -190,7 +188,7 @@ private User createUser() { return new User(userId, name, password); } - public Role createClientRole(@NonNull Client client, @NonNull String roleName) { + private Role createClientRole(@NonNull Client client, @NonNull String roleName) { final Keycloak keycloak = getAdminKeycloak(); final RealmResource realmResource = keycloak.realm(KEYCLOAK_DEFAULT_REALM); @@ -218,7 +216,7 @@ public Role createClientRole(@NonNull Client client, @NonNull String roleName) { return new Role(role.getId(), roleName); } - public void assignClientRoleToUser(@NonNull User user, @NonNull Role role, @NonNull Client client) { + private void assignClientRoleToUser(@NonNull User user, @NonNull Role role, @NonNull Client client) { final Keycloak keycloak = getAdminKeycloak(); final RealmResource realmResource = keycloak.realm(KEYCLOAK_DEFAULT_REALM); @@ -229,7 +227,7 @@ public void assignClientRoleToUser(@NonNull User user, @NonNull Role role, @NonN userResource.roles().clientLevel(client.getId()).add(Collections.singletonList(roleRepresentation)); } - public String getBearerToken(User user) { + private String getBearerToken(@NonNull User user) { Keycloak keycloak = KeycloakBuilder.builder() .serverUrl(KEYCLOAK_URL) .realm(KEYCLOAK_DEFAULT_REALM) @@ -272,5 +270,6 @@ public static class Client { String id; /* also the name */ String clientId; + String clientSecret; } }