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

Manual Integration tests and fix for authprovider junits #485

Merged
merged 1 commit into from
Jan 20, 2025
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
6 changes: 0 additions & 6 deletions packages/java/auth.provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import com.google.gson.JsonObject;

/**
* This class provides
* This class provides utility functions in order to generate
* projectScopeToken required to call Affinidi Services.
*
*
* @author Priyanka
Expand All @@ -44,7 +45,7 @@ public class AuthProvider {
private String publicKey;
private String projectScopeToken;

AuthProvider(Configurations configurations) {
private AuthProvider(Configurations configurations) {
this.projectId = configurations.projectId;
this.tokenId = configurations.tokenId;
this.privateKey = configurations.privateKey;
Expand Down
5 changes: 5 additions & 0 deletions packages/java/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<artifactId>jersey-common</artifactId>
<version>3.1.7</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public class EnvironmentUtil {
private static Dotenv properties;
private static Logger logger = Logger.getLogger(EnvironmentUtil.class.getName());

static {
properties = Dotenv.load();
public static Dotenv getProperties(){
if(properties == null){
properties = Dotenv.load();
}
return properties;
}


Expand All @@ -35,12 +38,17 @@ public class EnvironmentUtil {
*/
public String getConfiguredEnvironment() {
String configuredEnvironment = null;
if (properties != null) {
configuredEnvironment = properties.get(Environment.AFFINIDI_TDK_PROPERTY_NAME);
if (configuredEnvironment == null) {
configuredEnvironment = properties.get(Environment.NEXT_AFFINIDI_TDK_PROPERTY_NAME);
try{
if (getProperties() != null) {
configuredEnvironment = getProperties().get(Environment.AFFINIDI_TDK_PROPERTY_NAME);
if (configuredEnvironment == null) {
configuredEnvironment = getProperties().get(Environment.NEXT_AFFINIDI_TDK_PROPERTY_NAME);
}
}
}catch(Exception exception){
logger.severe("Could not read .env file for TDK environment configuration");
}

if (configuredEnvironment == null) {
logger.severe("Could not find environment details for "+configuredEnvironment+". Defaulting to production");
configuredEnvironment = Environment.PRODUCTION.environmentName;
Expand Down Expand Up @@ -97,7 +105,13 @@ public String getApiGatewayUrlForEnvironment() {
* @return String
*/
public String getValueFromEnvConfig(String propertyName) {
return properties.get(propertyName);
String propertyValue = null;
try{
propertyValue = getProperties().get(propertyName);
}catch(Exception exception){
logger.severe("Could not read .env file for "+propertyName);
}
return propertyValue;
}

/**
Expand All @@ -111,8 +125,8 @@ private Environment getEnvironmentDetail() {
Environment envDetail = (envName != null) ? Environment.getEnvSpecificDetails(envName) : null;

if (envDetail == null) {
logger.severe("Could not find environment details for the specified name " + envName+". Hence defaulting to production");
envDetail = Environment.getEnvSpecificDetails(Environment.PRODUCTION.environmentName);
logger.severe("Could not find environment details for the specified name " + envName);
}
return envDetail;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/java/reference/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
AFFINIDI_TDK_ENVIRONMENT=prod

PROJECT_ID=""
KEY_ID=
TOKEN_ID=""
PASSPHRASE=""
PRIVATE_KEY=""
114 changes: 114 additions & 0 deletions tests/integration/java/reference/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>com.affinidi.tdk</groupId>
<artifactId>reference</artifactId>
<version>1.0</version>
<name>reference</name>
<url>https://github.com/affinidi/affinidi-tdk</url>
<licenses>
<license>
<name>Apache-2.0</name>
<url>https://github.com/affinidi/affinidi-tdk/blob/main/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<name>Affinidi</name>
<email>...</email>
<organization>Affinidi</organization>
<organizationUrl>https://affinidi.com</organizationUrl>
</developer>
</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<affinidi-common-version>1.0</affinidi-common-version>
<affinidi-auth-version>1.0</affinidi-auth-version>
</properties>

<dependencies>

<dependency>
<groupId>com.affinidi.tdk</groupId>
<artifactId>common</artifactId>
<version>${affinidi-common-version}</version>
</dependency>
<dependency>
<groupId>com.affinidi.tdk</groupId>
<artifactId>auth.provider</artifactId>
<version>${affinidi-auth-version}</version>
</dependency>
<dependency>
<groupId>com.affinidi.tdk</groupId>
<artifactId>wallets.client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.affinidi.tdk</groupId>
<artifactId>credential.issuance.client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

package com.affinidi.reference;




import com.affinidi.tdk.authProvider.AuthProvider;

import com.affinidi.tdk.credential.issuance.client.apis.IssuanceApi;

import com.affinidi.tdk.wallets.client.ApiClient;
import com.affinidi.tdk.wallets.client.Configuration;
import com.affinidi.tdk.wallets.client.apis.WalletApi;
import com.affinidi.tdk.wallets.client.auth.ApiKeyAuth;
import com.affinidi.tdk.wallets.client.models.WalletsListDto;


/**
* To execute this class,
1. Ensure that base package of the working directory contains a valid .env file with values for each property
as present in .env.example
2. Ensure that auth-provider and common package jar is present in either the central maven respository
3. Or you can go to the resective pakage and run mvn clean install : in order to deply these jars in local
maven respository
*
* @author Priyanka
*
*/

public class TdkTestUtil {

public static void main(String arg[]){
try{
System.out.println("\n\n=============================");
System.out.println("01. Testing Wallet Client using TDK java packages");
System.out.println("=============================\n\n");
testWalletClient();
System.out.println("\n\n=============================");
System.out.println("Wallet Client testing using TDK java packages completed");
System.out.println("=============================\n\n");


System.out.println("\n\n=============================");
System.out.println("02. Testing Issuance Client using TDK java packages");
System.out.println("=============================\n\n");
testIssuanceClient();
System.out.println("\n\n=============================");
System.out.println("Issuance Client testing using TDK java packages completed");
System.out.println("=============================\n\n");
}catch(Exception exception){
exception.printStackTrace();
}
}

public static void testWalletClient() throws Exception{

System.out.println("Getting projectScopenToken before calling wallet API");

AuthProvider authProvider = new AuthProvider.Configurations().buildWithEnv();
String projectToken = authProvider.fetchProjectScopedToken();
System.out.println("ProjectScopeToken > > > > > : "+projectToken);

// Creating an API Client using the above token
ApiClient defaultClient = Configuration.getDefaultApiClient();
ApiKeyAuth ProjectTokenAuth = (ApiKeyAuth) defaultClient.getAuthentication("ProjectTokenAuth");
ProjectTokenAuth.setApiKey(projectToken);

WalletApi apiInstance = new WalletApi(defaultClient);
String didType = null;

System.out.println("Calling listWallets ");
WalletsListDto response = apiInstance.listWallets(didType);
System.out.println("Total wallets : "+response.getWallets().size());


System.out.println("Should AuthProvider refresh the token before any further call ? "+authProvider.shouldRefreshToken());
}

public static void testIssuanceClient() throws Exception{

System.out.println("Getting projectScopenToken before calling issuance API");
AuthProvider authProvider = new AuthProvider.Configurations().buildWithEnv();
String projectToken = authProvider.fetchProjectScopedToken();

// Creating an API Client using the above token
com.affinidi.tdk.credential.issuance.client.ApiClient issuanceClient = com.affinidi.tdk.credential.issuance.client.Configuration.getDefaultApiClient();
com.affinidi.tdk.credential.issuance.client.auth.ApiKeyAuth issueTokenAuth = (com.affinidi.tdk.credential.issuance.client.auth.ApiKeyAuth) issuanceClient.getAuthentication("ProjectTokenAuth");
issueTokenAuth.setApiKey(projectToken);

IssuanceApi issuanceApi = new IssuanceApi(issuanceClient);
String projectIdForTesting = "084036a6-a775-478a-9a97-a1323738897f";
System.out.println(issuanceApi.listIssuance(projectIdForTesting));

/* Uncomment to test startIssuance. Provide the relevant projectId and crdential data
StartIssuanceInput startIssuanceInput = new StartIssuanceInput();
startIssuanceInput.setHolderDid("did:key:zQ3shNb7dEAa7z4LY8eAbPafNM4iSxppwuvndoHkTUUp8Hbt6");
startIssuanceInput.setClaimMode(ClaimModeEnum.NORMAL);
StartIssuanceInputDataInner innerData = new StartIssuanceInputDataInner();
innerData.setCredentialTypeId("AlumniIdentityCard");
List<StartIssuanceInputDataInner> list = new ArrayList<StartIssuanceInputDataInner>();
list.add(innerData);
startIssuanceInput.setData(list);
System.out.println(issuanceApi.startIssuance("<projectid>", startIssuanceInput));
*/




}



}
Loading