Files
floci/compatibility-tests/sdk-test-node/tests/tls.test.ts
T
5befe8b619 feat: optional TLS/HTTPS support with self-signed certificate generation (#754)
* feat: optional TLS/HTTPS support with self-signed certificate generation

- Add TlsConfigSource (MicroProfile ConfigSource SPI) that injects Quarkus
  TLS properties before the HTTP server starts
- Auto-generate self-signed certificates with correct SANs including custom
  hostnames from FLOCI_HOSTNAME and FLOCI_BASE_URL
- Persist certificate metadata for change detection across restarts
- Fix CertificateGenerator to encode IP addresses as iPAddress SANs (RFC 5280)
- Serve HTTP + HTTPS simultaneously (LocalStack parity)
- Support user-provided certificates via FLOCI_TLS_CERT_PATH/KEY_PATH
- Add TLS configuration documentation
- Add Node.js SDK compatibility test for HTTPS connectivity
- Add comprehensive unit and integration tests (79 test cases)

Closes #711

* feat(tls): add TLS proxy server and WebSocket-over-TLS tests

- Add TlsProxyServer: TCP proxy on port 4566 that detects TLS ClientHello
  and routes to HTTPS (4511) or HTTP (4510) backend accordingly
- Add apigatewayv2-websocket-tls.test.ts: WSS compatibility tests covering
  connect/disconnect, route selection, broadcast, authorization,
  @connections API, binary frames, and payload size limits
- Update CI workflow to enable FLOCI_TLS_ENABLED=true for compat tests
- Update sdk-test-node Dockerfile with NODE_TLS_REJECT_UNAUTHORIZED=0
- Update tls.test.ts for HTTPS SDK client tests
- Update README with WebSocket-over-TLS test documentation

* fix(tls): address review comments — LocalStack parity and floci.io SANs

- Add USE_SSL and CUSTOM_SSL_CERT_PATH mappings to localstack-parity.sh
- Add localhost.floci.io and *.localhost.floci.io to default certificate SANs
- Update affected tests and documentation

---------

Co-authored-by: Dixit R Jain <dixitrjain@Mac-379.lan>
Co-authored-by: Dixit R Jain <dixitrjain@Mac.lan>
2026-05-10 10:21:03 -05:00

176 lines
4.5 KiB
TypeScript

/**
* TLS/HTTPS connectivity tests for floci.
*
* Verifies that AWS SDK v3 clients can interact with floci over HTTPS
* when TLS is enabled with a self-signed certificate.
*
* These tests run within the existing test suite. Since Floci serves HTTP
* and HTTPS simultaneously, existing HTTP tests are unaffected. The HTTPS
* endpoint is derived from the HTTP endpoint by swapping the scheme.
*
* Prerequisites:
* - Floci must be started with FLOCI_TLS_ENABLED=true
* - NODE_TLS_REJECT_UNAUTHORIZED=0 must be set in the test environment
*/
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { STSClient, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
import {
SQSClient,
CreateQueueCommand,
SendMessageCommand,
DeleteQueueCommand,
} from '@aws-sdk/client-sqs';
import {
SSMClient,
PutParameterCommand,
GetParameterCommand,
DeleteParameterCommand,
} from '@aws-sdk/client-ssm';
import {
S3Client,
CreateBucketCommand,
PutObjectCommand,
GetObjectCommand,
DeleteObjectCommand,
DeleteBucketCommand,
} from '@aws-sdk/client-s3';
import { ENDPOINT, uniqueName, ACCOUNT, REGION, CREDS } from './setup';
// Derive the HTTPS endpoint from the HTTP endpoint by swapping the scheme.
// When TLS is enabled, Floci serves HTTPS on port 4566 (same port as HTTP without TLS).
const HTTPS_ENDPOINT = ENDPOINT.replace(/^http:\/\//, 'https://');
const TLS_CLIENT_CONFIG = {
endpoint: HTTPS_ENDPOINT,
region: REGION,
credentials: CREDS,
forcePathStyle: true,
};
function makeTlsClient<T>(
ClientClass: new (config: typeof TLS_CLIENT_CONFIG) => T,
): T {
return new ClientClass(TLS_CLIENT_CONFIG);
}
describe('TLS — STS over HTTPS', () => {
let sts: STSClient;
beforeAll(() => {
sts = makeTlsClient(STSClient);
});
it('should call GetCallerIdentity over HTTPS', async () => {
const response = await sts.send(new GetCallerIdentityCommand({}));
expect(response.Account).toBe(ACCOUNT);
expect(response.Arn).toBeTruthy();
});
});
describe('TLS — SQS over HTTPS', () => {
let sqs: SQSClient;
let queueUrl: string;
beforeAll(() => {
sqs = makeTlsClient(SQSClient);
});
afterAll(async () => {
if (queueUrl) {
try {
await sqs.send(new DeleteQueueCommand({ QueueUrl: queueUrl }));
} catch {
// ignore
}
}
});
it('should create a queue and get HTTPS queue URL', async () => {
const name = uniqueName('tls-sqs');
const response = await sqs.send(new CreateQueueCommand({ QueueName: name }));
queueUrl = response.QueueUrl!;
expect(queueUrl).toMatch(/^https:\/\//);
expect(queueUrl).toContain(name);
});
it('should send a message over HTTPS', async () => {
const response = await sqs.send(
new SendMessageCommand({
QueueUrl: queueUrl,
MessageBody: 'hello-tls',
})
);
expect(response.MessageId).toBeTruthy();
});
});
describe('TLS — SSM over HTTPS', () => {
let ssm: SSMClient;
const paramName = `/${uniqueName('tls-param')}`;
beforeAll(() => {
ssm = makeTlsClient(SSMClient);
});
afterAll(async () => {
try {
await ssm.send(new DeleteParameterCommand({ Name: paramName }));
} catch {
// ignore
}
});
it('should put and get a parameter over HTTPS', async () => {
await ssm.send(
new PutParameterCommand({
Name: paramName,
Value: 'tls-value',
Type: 'String',
})
);
const response = await ssm.send(
new GetParameterCommand({ Name: paramName })
);
expect(response.Parameter?.Value).toBe('tls-value');
});
});
describe('TLS — S3 over HTTPS', () => {
let s3: S3Client;
const bucketName = uniqueName('tls-s3');
const key = 'test-object.txt';
beforeAll(async () => {
s3 = makeTlsClient(S3Client);
await s3.send(new CreateBucketCommand({ Bucket: bucketName }));
});
afterAll(async () => {
try {
await s3.send(new DeleteObjectCommand({ Bucket: bucketName, Key: key }));
await s3.send(new DeleteBucketCommand({ Bucket: bucketName }));
} catch {
// ignore
}
});
it('should put and get an object over HTTPS', async () => {
const body = 'hello from TLS';
await s3.send(
new PutObjectCommand({
Bucket: bucketName,
Key: key,
Body: body,
})
);
const response = await s3.send(
new GetObjectCommand({ Bucket: bucketName, Key: key })
);
const text = await response.Body!.transformToString();
expect(text).toBe(body);
});
});