Skip to content

Commit

Permalink
feat: Implement disconnection from backing service(s) (#27)
Browse files Browse the repository at this point in the history
Fixes #10
  • Loading branch information
gnarea authored Apr 4, 2023
1 parent 234058f commit bfb2564
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/KmsRsaPssProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RsaPssProvider } from 'webcrypto-core';

export abstract class KmsRsaPssProvider extends RsaPssProvider {}
export abstract class KmsRsaPssProvider extends RsaPssProvider {
public abstract close(): Promise<void>;
}
12 changes: 12 additions & 0 deletions src/lib/aws/AwsKmsRsaPssProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,16 @@ describe('AwsKmsRsaPssProvider', () => {
);
});
});

describe('close', () => {
test('Client should be destroyed', async () => {
const client = new KMSClient({});
const mockDestroy = jest.spyOn(client, 'destroy').mockReturnValue(undefined);
const provider = new AwsKmsRsaPssProvider(client);

await provider.close();

expect(mockDestroy).toHaveBeenCalledWith();
});
});
});
4 changes: 4 additions & 0 deletions src/lib/aws/AwsKmsRsaPssProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export class AwsKmsRsaPssProvider extends KmsRsaPssProvider {
throw new KmsError('Signature verification is unsupported');
}

async close(): Promise<void> {
this.client.destroy();
}

private async retrievePublicKey(key: AwsKmsRsaPssPrivateKey): Promise<ArrayBuffer> {
const command = new GetPublicKeyCommand({ KeyId: key.arn });
const response = await this.client.send(command, REQUEST_OPTIONS);
Expand Down
12 changes: 12 additions & 0 deletions src/lib/gcp/GcpKmsRsaPssProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,15 @@ describe('onVerify', () => {
);
});
});

describe('close', () => {
test('Client should be closed', async () => {
const client = new KeyManagementServiceClient();
const mockClose = jest.spyOn(client, 'close').mockResolvedValue(undefined);
const provider = new GcpKmsRsaPssProvider(client, KMS_CONFIG);

await provider.close();

expect(mockClose).toHaveBeenCalledWith();
});
});
4 changes: 4 additions & 0 deletions src/lib/gcp/GcpKmsRsaPssProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export class GcpKmsRsaPssProvider extends KmsRsaPssProvider {
throw new KmsError('Signature verification is unsupported');
}

async close(): Promise<void> {
await this.client.close();
}

private async getGCPProjectId(): Promise<string> {
// GCP client library already caches the project id.
return this.client.getProjectId();
Expand Down

0 comments on commit bfb2564

Please sign in to comment.