Files
floci/compatibility-tests/sdk-test-java
Abhigya fcc89c0e8d feat(ecs): implement ExecuteCommand (#4121)
* feat(ecs): implement ExecuteCommand

ECS Exec was accepted at the API but opened nothing: a client got a
response it could not connect to. This implements the whole path, so
`aws ecs execute-command` gives a real shell in a task's container.

The gate matches AWS. The session must be interactive, which is the only
mode ECS supports; the task must belong to the cluster the request
names, must be RUNNING and must have been run with enableExecuteCommand;
and the container must have a runtime behind it, so a mock-mode task
answers TargetNotConnectedException.

The response carries a session with a single-use tokenValue and a
streamUrl pointing at Floci's own data channel, which is where
session-manager-plugin then connects. Floci plays the SSM agent's half
of the Session Manager protocol on that channel, the binary AgentMessage
framing, the handshake, sequenced acknowledgements and terminal resizes,
and bridges it to a docker exec with a TTY.

Two threads meet on that channel. Every call into the Docker daemon
blocks, so it runs on a worker rather than on the event loop, and the
daemon streams the container's output back on its own thread; frames are
written from the channel's Vert.x context only, which also keeps the
outbound sequence numbers in the order they reach the wire. The command
is attached to only once the client has accepted the handshake, so no
output can be written to a channel that is still being opened.

Deliberate limits, documented in docs/services/ecs.md:

- The command runs through /bin/sh -c, so an image without a shell
  cannot be exec'd into.
- Sessions are in memory, single use, and expire after five minutes if
  nobody connects.
- ExecuteCommand logging, the executeCommandConfiguration that sends
  session transcripts to S3 or CloudWatch, is not implemented. The
  cluster field still round-trips.

EcsExecSessionRegistry holds a SecureRandom, so it is registered under
--initialize-at-run-time for the native image.

AgentMessageTest covers the wire framing against a JDK-side encode and
decode, EcsExecuteCommandIntegrationTest covers the API gate, and
EcsExecChannelDockerIntegrationTest runs a real session end to end under
Docker.

* fix(ecs): compare the ECS Exec session token in constant time

The token is the single gate in front of an interactive shell in a
container, so compare it with MessageDigest.isEqual on the UTF-8 bytes
rather than String.equals, which returns on the first differing
character. Matches the constant-time comparison the repo already does in
ScimController, IamAuthValidator and LambdaLayerService.

A failed claim still leaves the session in place: dropping it would let
anyone holding a session id cancel somebody else's session.

* fix(ecs): expire an unclaimed ECS Exec session on read

Only create() swept the session map, and neither claim() nor find()
looked at createdAt, so a session nobody connected to stayed claimable,
token included, until the next ExecuteCommand call happened to come in.
On an idle emulator that is forever, which also made the five minute
expiry documented in docs/services/ecs.md untrue.

claim() and find() now go through liveSession(), which drops a session
past SESSION_TTL and reports it as gone: claim() rejects it before the
token comparison, and the WebSocket upgrade refuses to open a channel
for it. The registry takes the CDI Clock so the tests exercise expiry
without waiting out the TTL.
2026-09-22 23:47:40 -04:00
..

sdk-test-java

Compatibility tests for Floci using the AWS SDK for Java v2 (2.31.8).

Runs 352 tests across 17 test classes against a live Floci instance — no mocks.

Services Covered

Test class Description
SsmTest Parameter Store — put, get, path, tags
SqsTest Queues, send/receive/delete, DLQ, visibility
SnsTest Topics, subscriptions, publish, SQS delivery
S3Test Buckets, objects, tagging, copy, multipart, batch delete
DynamoDbTest Tables, CRUD, batch, TTL, tags, streams
DynamoDbScanConditionTests Scan filter and condition expressions
LambdaTest Create/invoke/update/delete functions
IamTest Users, roles, policies, access keys
StsTest GetCallerIdentity, AssumeRole, GetSessionToken
SecretsManagerTest Create/get/put/list/delete secrets, versioning, tags
KmsTest Keys, aliases, encrypt/decrypt, data keys, sign/verify
CloudWatchTest PutMetricData, ListMetrics, GetMetricStatistics, alarms
CloudFormationVirtualHostTests Virtual host style S3 access via CloudFormation
ApigwSfnJsonataCrudlTests API Gateway + Step Functions JSONata CRUDL integration
ApiGatewayV2WebSocketAndExtendedOpsTest API GW v2 WebSocket APIs, Update ops, Route/Integration Responses, Models, Tagging
Ec2Tests EC2 instances, VPCs, security groups, subnets
AppSyncTest GraphQL API CRUDL, data sources, resolvers, functions, types, API keys, tags, schema validation
EcsTests ECS clusters, task definitions, services

Adding a New Test

Create a standard JUnit 5 test class in src/test/java/com/floci/test/. Tests run against a live Floci instance using real AWS SDK clients.

Requirements

  • Java 17+
  • Maven

Running

# All tests
mvn test -q

# Specific test class
mvn test -Dtest=S3Test

# Via just (from compatibility-tests/)
just test-java

Configuration

Variable Default Description
FLOCI_ENDPOINT http://localhost:4566 Floci emulator endpoint

AWS credentials are always test / test / us-east-1.

Metric filter publishing checks

CloudWatchLogsMetricFilterTest and CloudFormationLogsMetricFilterTest run with the rest of the suite. Against a server on another port:

# From compatibility-tests/sdk-test-java
FLOCI_ENDPOINT=http://127.0.0.1:18084 ../../mvnw test \
  -Dtest=CloudWatchLogsMetricFilterTest,CloudFormationLogsMetricFilterTest

The publishing tests read their expected values from src/test/resources/cloudwatchlogs/metric-filter-publishing-aws.json, a byte-identical copy of the root fixture recorded from AWS. MetricFilterFixturePackagingTest checks the copy loads from the classpath, and the root CloudWatchLogsMetricFilterFixturePackagingTest fails when either SDK module copy drifts from the root file. The SDK selects the CloudWatch JSON protocol; MetricFilterQueryAssertions signs the same reads as legacy form-encoded Query requests, so GetMetricStatistics and GetMetricData on both wire formats are asserted against every statistic the fixture records (Sum, SampleCount, Minimum, Maximum). Reads poll for the sample, since the server publishes it shortly after PutLogEvents returns. Passing these tests shows Floci matches the recorded values; it is not live AWS verification. For the opt-in replay against AWS see ../sdk-test-python/README.md.

Docker

docker build -t floci-sdk-java .
docker run --rm --network host floci-sdk-java

# Custom endpoint (macOS/Windows)
docker run --rm -e FLOCI_ENDPOINT=http://host.docker.internal:4566 floci-sdk-java