This guide explains how TrustWeave handles tests that require external credentials, tokens, or API keys for plugins.
Overview
TrustWeave uses a self-describing plugin architecture where each plugin advertises what environment variables it needs. Tests can be annotated to require specific plugins, and the test framework automatically skips tests when required credentials are not available.
How It Works
Each plugin provider declares required environment variables via the requiredEnvironmentVariables property
Tests are annotated with @RequiresPlugin("plugin-name") to indicate they need a plugin
The test framework automatically discovers plugins via ServiceLoader
Tests are skipped if the plugin’s required environment variables are not set
Plugin Provider Interface
All plugin providers (KMS, DID methods, blockchain chains) implement methods to advertise their requirements:
Required: Listed without prefix (e.g., "AWS_REGION")
Optional: Prefixed with "?" (e.g., "?AWS_SESSION_TOKEN")
Using @RequiresPlugin Annotation
Basic Usage
1
2
3
4
5
6
7
8
importcom.trustweave.testkit.annotations.RequiresPlugin@RequiresPlugin("aws")@Testfun`testAWSKMS`()=runBlocking{// Test will be skipped if AWS_REGION is not setvalkms=// ... create AWS KMS}
Multiple Plugins
1
2
3
4
5
@RequiresPlugin("google-cloud-kms","ethereum")@Testfun`testwithmultipleplugins`()=runBlocking{// Test will be skipped if either plugin's env vars are missing}
Plugin Names
Plugin names match the provider name:
KMS providers: "aws", "azure", "google-cloud-kms", "hashicorp", etc.
DID method providers: "ethr", "ion", "polygon", "key", "web", etc.
Blockchain anchor providers: "ethereum", "algorand", "polygon", etc.
classAwsKeyManagementServiceProvider:KeyManagementServiceProvider{overridevalname:String="aws"overridevalrequiredEnvironmentVariables:List<String>=listOf("AWS_REGION",// Required"?AWS_ACCESS_KEY_ID",// Optional (can use IAM roles)"?AWS_SECRET_ACCESS_KEY"// Optional (can use IAM roles))overridefunhasRequiredEnvironmentVariables():Boolean{// Custom logic: Check for region OR IAM role availabilityreturn(System.getenv("AWS_REGION")!=null||System.getenv("AWS_DEFAULT_REGION")!=null)||// Check if running on AWS (IAM role available)try{Class.forName("software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider")true}catch(e:ClassNotFoundException){false}}}
Example: DID Method Provider
1
2
3
4
5
6
7
8
classEthrDidMethodProvider:DidMethodProvider{overridevalname:String="ethr"overridevalrequiredEnvironmentVariables:List<String>=listOf("ETHEREUM_RPC_URL","?ETHEREUM_PRIVATE_KEY"// Optional if only resolving)}
# Skip tests when credentials are missing (default: true)export VERICORE_TEST_SKIP_IF_NO_CREDENTIALS=true# Fail tests when credentials are missingexport VERICORE_TEST_SKIP_IF_NO_CREDENTIALS=false
Programmatic Check
You can also check credentials programmatically:
1
2
3
4
5
6
7
8
9
10
importcom.trustweave.testkit.config.TestConfig@Testfun`testwithmanualcheck`()=runBlocking{org.junit.jupiter.api.Assumptions.assumeTrue(TestConfig.skipIfNoCredentials(),"Credentials not available")// Test code}
Benefits
Scalable: Each plugin declares its own requirements - no centralized list
Self-documenting: Plugin requirements are visible in the code
Automatic: Tests are skipped automatically when credentials are missing
Flexible: Supports optional environment variables
Discoverable: Uses ServiceLoader to find plugins automatically
Best Practices
Always declare required env vars in your plugin provider
Use optional prefix "?" for env vars that have fallbacks (IAM roles, default credentials, etc.)
Override hasRequiredEnvironmentVariables() for custom logic (e.g., checking for IAM roles)
Document env vars in your plugin’s README or documentation
Use @RequiresPlugin on tests that actually need the plugin to function
// kms/plugins/myplugin/src/test/kotlin/MyKmsProviderTest.ktclassMyKmsProviderTest{@Test@RequiresPlugin("my-kms")fun`testwithcredentials`()=runBlocking{// This test will be skipped if MY_KMS_API_KEY is not setvalprovider=MyKmsProvider()valkms=provider.create(mapOf("apiKey"toSystem.getenv("MY_KMS_API_KEY")!!,"endpoint"toSystem.getenv("MY_KMS_ENDPOINT")!!))// Test code}}