Files
floci/compatibility-tests/sdk-test-python/README.md
T
Priamo Germosen 233253334d fix(elbv2): reject a listener certificate the account does not have (#5474)
A listener stored whatever certificate ARN it was given. CreateListener,
ModifyListener and AddListenerCertificates each model CertificateNotFound,
and all three took an ARN naming nothing and answered 200, so a listener
could be left serving a certificate that was never uploaded. Only the other
direction worked: ELBv2 reports its references to IAM, so
DeleteServerCertificate already refused with DeleteConflict while a listener
held one.

The error is the one AWS publishes on those three operations and no others:
botocore gives CertificateNotFoundException the code CertificateNotFound,
400, senderFault, and the API reference lists it under
AddListenerCertificates, CreateListener and ModifyListener with one
sentence, "The specified certificate does not exist." That sentence is the
message rather than one naming the ARN, because it is the one the reference
publishes.

The check covers the listener types the member belongs to and no more. The
reference marks Certificates "[HTTPS and TLS listeners]" on CreateListener
and ModifyListener, and describes AddListenerCertificates as adding to the
list "for the specified HTTPS or TLS listener", so a certificate on a
listener of any other protocol is a configuration it does not describe. What
AWS answers there is not CertificateNotFound on any evidence to hand, so
such a request keeps the behaviour it had rather than being refused with a
code read off the wrong case. A test pins each side of that line. The line
follows the protocol the listener ends the call with, not the one it started
with: ModifyListener takes a protocol without taking certificates, so when
none arrive the certificates checked are the ones already on file. An HTTP
listener holding an ARN that resolves to nothing is left alone, and the
request that turns it into an HTTPS one, which is where those certificates
start being served, is refused.

A blank entry is refused the same way, rather than skipped. Certificates is
the list of certificates the listener serves, an empty value in it names one
no better than a value that is no ARN at all, and the Query parser turns an
empty CertificateArn parameter into exactly that entry, so skipping it
stored a certificate the listener cannot serve.

ELB Classic already answered this question in full, resolving an ARN to an
IAM server certificate or an ACM one and holding IAM's certificate lock
across the write. This is the second caller, so the three private methods it
kept, certificateExists, iamServerCertificate and acmCertificateExists, move
to CertificateReferenceResolver in core.common and Classic reads them from
there. Neither referrer owns the lookup: IAM holds server certificates, ACM
holds the rest, and a listener carries only the ARN. Classic's public
constructors are untouched, so its unit tests still build it the same way.

The check alone is not enough, which is why the lock moves with it. A
certificate can be deleted between the check and the write, and the delete
walks the reference providers under IAM's own lock, so every write that
records an IAM certificate runs inside that lock and re-checks there, while
the fail-fast check outside it keeps the error precedence. That covers
CreateListener as much as the two writes to a listener already published:
until the new listener is in the map, nothing the delete walks can see that
it holds the certificate. A race test drives each of them against
DeleteServerCertificate over the wire, and with the lock removed they leave
a listener holding a deleted certificate in 1 of 30 trials for
AddListenerCertificates and 4 of 30 for CreateListener, so the guarantee is
measured rather than asserted.

Where the check sits in ModifyListener is part of the fix. The listener it
modifies is the stored object, and the port, protocol and SSL policy were
set before anything could refuse the request, so a refusal answered 400 over
a listener already moved to the new port: no later read put it back, and the
data plane was never restarted to match. Every refusal now lands before the
first setter.

An absent resolver leaves the old behaviour in place. ElbV2Service is wired
by hand in its unit tests, with no IAM and no ACM, and a listener write
there is the write it was before any certificate existed to check. The
dependency is a field rather than a constructor parameter because that is
how this class takes all six of its others, and converting it would be a
refactor this change does not need.

docs/services/elb.md said listener certificate ARNs are not validated when
they are added, which was true and is the behaviour this removes, so it now
documents the three operations, the protocols they cover, the empty value,
the protocol change, the error and the lock, as the Classic page already
does.

Sixteen integration tests cover a missing IAM certificate, a missing ACM
one, a blank entry, a value that is no ARN at all and an ARN of a service
that serves no certificates, an uploaded certificate and an ACM certificate
being accepted, a listener carrying no certificate, a TLS listener held to
the same check as an HTTPS one and a listener of a protocol with no
certificates left alone, a protocol change refused over the certificate it
already held and allowed over one that exists, a second certificate being
added, a refused change leaving the port and protocol as they were, and the
two writes that must refuse without changing what the listener already
serves. Every certificate and load balancer they make is registered for
cleanup: the account's certificate quota is 20 and the Quarkus instance is
shared, so one left behind fails an unrelated class's upload instead of
anything here.

Three things the reference states about these operations stay open, each
wanting an error code no source here gives: CreateListener and
ModifyListener take "exactly one certificate" and AddListenerCertificates
"one certificate per call", where Floci accepts a list; TooManyCertificates
is modeled on all three and no quota is enforced; and
DescribeListenerCertificates is documented to report the default certificate
alongside the list, with IsDefault telling them apart, which Floci does not
model.

Driven through the standard hashicorp/aws provider against a local instance
as well, which is how the change was checked against a real client rather
than only against the suite: an aws_iam_server_certificate and an
aws_lb_listener serving it apply clean, and a listener naming a certificate
nobody uploaded fails with CertificateNotFound and the reference's sentence.
That failure arrives at the end of the provider's create timeout rather than
at once, because the provider retries this error on all three calls, the
AddListenerCertificates one against a constant named iamPropagationTimeout:
real AWS is eventually consistent about a certificate just imported, so a
client waits it out. Floci's storage is immediately consistent and nothing
here models a propagation delay, so the retry simply ends in the refusal.

The same contract is pinned at the SDK boundary too, as eight boto3 tests in
compatibility-tests: the refusal on each of the three operations, the
accepted cases, and both protocol edges. They run in under a second, where
driving the same thing through Terraform in CI costs about a minute for the
accepted case and nearly two for the refusal, almost all of it the
provider's waiter and the retry above rather than anything Floci does. The
suite had no ELB coverage at all before this. Each test takes its load
balancer back out before its certificates, which is the order that frees
them, and test_acm.py's private certificate builder moves to a conftest
fixture taking the common name rather than being copied, since the new file
needs the same pair.
2026-10-11 21:47:38 -05:00

107 lines
4.8 KiB
Markdown

# sdk-test-python
Compatibility tests for [Floci](https://github.com/hectorvent/floci) using **boto3 (1.37.1)**.
## Services Covered
| Group | Description |
| ----------------------- | ------------------------------------------------------------------------ |
| `ssm` | Parameter Store — put, get, label, history, path, tags |
| `sqs` | Queues, send/receive/delete, DLQ, visibility |
| `sns` | Topics, subscriptions, publish, SQS delivery |
| `s3` | Buckets, objects, tagging, copy, batch delete |
| `s3-cors` | CORS configuration |
| `s3-notifications` | S3 → SQS event notifications |
| `dynamodb` | Tables, CRUD, batch, TTL, tags |
| `lambda` | Create/invoke/update/delete functions |
| `iam` | Users, roles, policies, access keys |
| `sts` | GetCallerIdentity, AssumeRole, GetSessionToken |
| `secretsmanager` | Create/get/put/list/delete secrets, versioning, tags |
| `kms` | Keys, aliases, encrypt/decrypt, data keys, sign/verify |
| `kinesis` | Streams, shards, PutRecord/GetRecords |
| `cloudwatch-metrics` | PutMetricData, ListMetrics, GetMetricStatistics, alarms |
| `cloudformation-naming` | Auto physical name generation, explicit name precedence, cross-reference |
| `cognito` | User pools, clients, AdminCreateUser, InitiateAuth, GetUser |
| `elbv2` | Listener certificates resolved against IAM and ACM |
## Requirements
- Python 3.9+
- pip
## Running
```bash
pip install -r requirements.txt
# All groups
pytest tests/ --junit-xml=test-results/junit.xml
# Specific tests
pytest tests/test_s3.py
# Via just (from compatibility-tests/)
just test-python
```
## Configuration
| Variable | Default | Description |
| ---------------- | ----------------------- | ----------------------- |
| `FLOCI_ENDPOINT` | `http://localhost:4566` | Floci emulator endpoint |
AWS credentials are always `test` / `test` / `us-east-1`.
## Opt-in metric filter replay against AWS
`tests/metric_filter_replay.py` is a standalone script, not a test: pytest does
not collect it, and `tests/test_metric_filter_replay.py` checks its logic offline
with the network blocked. It does not change `conftest.py`, and `FLOCI_TARGET=aws`
does not select real AWS.
From the repository root, with the declared requirements installed:
```bash
python -m pytest compatibility-tests/sdk-test-python/tests/test_metric_filter_replay.py
# Against a local Floci
python compatibility-tests/sdk-test-python/tests/metric_filter_replay.py \
--endpoint http://127.0.0.1:4566 --region eu-west-1 \
--timeout 30 --stable-seconds 2 --poll-interval 1
```
Real AWS mode requires all three safety arguments. **It creates billable
CloudWatch metrics and a tagged log group, and metric series cannot be deleted**;
they remain until AWS ages them out.
```bash
python compatibility-tests/sdk-test-python/tests/metric_filter_replay.py \
--aws --profile YOUR_DISPOSABLE_TEST_PROFILE --region eu-west-1 \
--ack-live-writes I_ACCEPT_AWS_WRITES
```
Only commercial AWS regions are accepted, the clients pin the official regional
endpoints, and the group is deleted in `finally` only after its ownership tag is
verified. A cleanup failure exits nonzero and prints the group name. Credentials,
account ids, profile names and raw service errors are never printed.
The expected values come from `tests/fixtures/metric-filter-publishing-aws.json`,
a byte-identical copy of the root fixture
`src/test/resources/cloudwatchlogs/metric-filter-publishing-aws.json`; the root
`CloudWatchLogsMetricFilterFixturePackagingTest` fails when either SDK module copy
drifts. The replay ingests each scenario into its own backdated minute, runs the
quiet-default scenario last with no later ingestion, and accepts a result only
after every expected series, absent series and the idle minute after the quiet one
have stayed stable for a full window (AWS defaults: 240 second deadline, 30 second
window). Output is JSON lines of observations, not a regenerated fixture.
## Docker
```bash
docker build -t floci-sdk-python .
docker run --rm --network host floci-sdk-python
# Custom endpoint (macOS/Windows)
docker run --rm -e FLOCI_ENDPOINT=http://host.docker.internal:4566 floci-sdk-python
```