Skip to content

Commit

Permalink
add E2E_AWS_KMS_TEST_ENABLE flag for aws kms signer testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jnaulty committed Oct 30, 2024
1 parent 759eada commit 6eff9ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/workflows/turborepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_KMS_TEST_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ vars.AWS_KMS_AWS_REGION }}
AWS_KMS_KEY_ID: ${{ secrets.AWS_KMS_TEST_KMS_KEY_ID }}
E2E_AWS_KMS_TEST_ENABLE: "true"
run: pnpm turbo test

# Pack wallet extension and upload it as an artifact for easy developer use:
Expand Down
72 changes: 40 additions & 32 deletions sdk/kms/tests/e2e-aws-kms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,49 @@ import { beforeAll, describe, expect, it } from 'vitest';

import { AwsKmsSigner } from '../src/aws/aws-kms-signer';

describe('Aws KMS signer E2E testing', () => {
let signer: AwsKmsSigner;
beforeAll(async () => {
const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;

if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !AWS_REGION || !AWS_KMS_KEY_ID) {
throw new Error('Missing one or more required environment variables.');
}

signer = await AwsKmsSigner.fromCredentials(AWS_KMS_KEY_ID, {
region: AWS_REGION,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
});
});
const { E2E_AWS_KMS_TEST_ENABLE } = process.env;

it('should retrieve the correct sui address', async () => {
// Get the public key
const publicKey = signer.getPublicKey();
expect(publicKey.toSuiAddress()).toEqual(
'0x2bfc782b6bf66f305fdeb19a203386efee3e62bce3ceb9d3d53eafbe0b14a035',
);
if (!E2E_AWS_KMS_TEST_ENABLE) {
describe.skip('Aws KMS Signer E2E testing', () => {
// Skip Tests -- not in E2E_CI_ENABLE Environment.
});
} else {
describe('Aws KMS signer E2E testing', () => {
let signer: AwsKmsSigner;
beforeAll(async () => {
const { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_KMS_KEY_ID } = process.env;

if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !AWS_REGION || !AWS_KMS_KEY_ID) {
throw new Error('Missing one or more required environment variables.');
}

signer = await AwsKmsSigner.fromCredentials(AWS_KMS_KEY_ID, {
region: AWS_REGION,
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
});
});

it('should sign a message and verify against pubkey', async () => {
// Define a test message
const testMessage = 'Hello, AWS KMS Signer!';
const messageBytes = new TextEncoder().encode(testMessage);
it('should retrieve the correct sui address', async () => {
// Get the public key
const publicKey = signer.getPublicKey();
expect(publicKey.toSuiAddress()).toEqual(
'0x2bfc782b6bf66f305fdeb19a203386efee3e62bce3ceb9d3d53eafbe0b14a035',
);
});

it('should sign a message and verify against pubkey', async () => {
// Define a test message
const testMessage = 'Hello, AWS KMS Signer!';
const messageBytes = new TextEncoder().encode(testMessage);

// Sign the test message
const { signature } = await signer.signPersonalMessage(messageBytes);
// Sign the test message
const { signature } = await signer.signPersonalMessage(messageBytes);

// verify signature against pubkey
const publicKey = signer.getPublicKey();
const isValid = await publicKey.verifyPersonalMessage(messageBytes, signature);
expect(isValid).toBe(true);
// verify signature against pubkey
const publicKey = signer.getPublicKey();
const isValid = await publicKey.verifyPersonalMessage(messageBytes, signature);
expect(isValid).toBe(true);
});
});
});
}

0 comments on commit 6eff9ee

Please sign in to comment.