feat(LocalStack): Require auth token for 4.15 and onwards#1667
feat(LocalStack): Require auth token for 4.15 and onwards#1667HofmeisterAn merged 3 commits intodevelopfrom
Conversation
WalkthroughMultiple builders across the Testcontainers library now use concrete Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can suggest fixes for GitHub Check annotations.Configure the |
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/Testcontainers.LocalStack.Tests/LocalStackBuilderTest.cs (1)
3-31: Consider adding test coverage forlatestandnightlytags.The validation logic in
LocalStackBuilder.Validate()usesMatchLatestOrNightly()to require auth tokens for these tags, which aligns with the PR objective thatlocalstack/localstack:latestwill require authentication after March 23, 2026. However, there's no test coverage for this path.💡 Suggested additional tests
[Fact] public void LocalStackLatestWithoutAuthTokenThrowsArgumentException() { const string message = "The image 'localstack/localstack:latest' requires the LOCALSTACK_AUTH_TOKEN environment variable for LocalStack 4.15 and onwards."; ExpectArgEx(message, () => new LocalStackBuilder("localstack/localstack:latest").Build()); } [Fact] public void LocalStackLatestWithAuthTokenDoesNotThrowArgumentException() { var exception = Xunit.Record.Exception(() => new LocalStackBuilder("localstack/localstack:latest").WithEnvironment("LOCALSTACK_AUTH_TOKEN", "<auth-token>").Build()); Assert.Null(exception); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Testcontainers.LocalStack.Tests/LocalStackBuilderTest.cs` around lines 3 - 31, Add unit tests in LocalStackBuilderTest to cover the "latest" and "nightly" image tags similar to existing tests: add tests that assert LocalStackBuilder("localstack/localstack:latest") and ("localstack/localstack:nightly") throw the same ArgumentException message when built without LOCALSTACK_AUTH_TOKEN (use ExpectArgEx), and add companion tests that call WithEnvironment("LOCALSTACK_AUTH_TOKEN", "<auth-token>") and assert no exception (use Xunit.Record.Exception and Assert.Null). These tests exercise the validation path in LocalStackBuilder.Validate() that uses MatchLatestOrNightly() to require auth tokens.src/Testcontainers.LocalStack/LocalStackBuilder.cs (1)
90-91: Consider adding parentheses for clarity.While operator precedence is correct (
&&binds tighter than||), explicit parentheses would improve readability:- !value.Environments.TryGetValue("LOCALSTACK_AUTH_TOKEN", out _) && (value.Image.MatchLatestOrNightly() || value.Image.MatchVersion(v => v.Major > 4 || v.Major == 4 && v.Minor > 14)); + !value.Environments.TryGetValue("LOCALSTACK_AUTH_TOKEN", out _) && (value.Image.MatchLatestOrNightly() || value.Image.MatchVersion(v => v.Major > 4 || (v.Major == 4 && v.Minor > 14)));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/Testcontainers.LocalStack/LocalStackBuilder.cs` around lines 90 - 91, The predicate requiresAuthToken expression is correct but unclear; update the lambda in Predicate<LocalStackConfiguration> requiresAuthToken to add explicit parentheses around the OR portion so the intent is obvious (e.g. parenthesize the Image.MatchLatestOrNightly() || Image.MatchVersion(... ) part) while keeping the logic the same; this touches the lambda that reads value => !value.Environments.TryGetValue("LOCALSTACK_AUTH_TOKEN", out _) && (value.Image.MatchLatestOrNightly() || value.Image.MatchVersion(v => v.Major > 4 || v.Major == 4 && v.Minor > 14)) referencing LocalStackConfiguration, Environments, LOCALSTACK_AUTH_TOKEN, Image.MatchLatestOrNightly and Image.MatchVersion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/Testcontainers.LocalStack/LocalStackBuilder.cs`:
- Around line 90-91: The predicate requiresAuthToken expression is correct but
unclear; update the lambda in Predicate<LocalStackConfiguration>
requiresAuthToken to add explicit parentheses around the OR portion so the
intent is obvious (e.g. parenthesize the Image.MatchLatestOrNightly() ||
Image.MatchVersion(... ) part) while keeping the logic the same; this touches
the lambda that reads value =>
!value.Environments.TryGetValue("LOCALSTACK_AUTH_TOKEN", out _) &&
(value.Image.MatchLatestOrNightly() || value.Image.MatchVersion(v => v.Major > 4
|| v.Major == 4 && v.Minor > 14)) referencing LocalStackConfiguration,
Environments, LOCALSTACK_AUTH_TOKEN, Image.MatchLatestOrNightly and
Image.MatchVersion.
In `@tests/Testcontainers.LocalStack.Tests/LocalStackBuilderTest.cs`:
- Around line 3-31: Add unit tests in LocalStackBuilderTest to cover the
"latest" and "nightly" image tags similar to existing tests: add tests that
assert LocalStackBuilder("localstack/localstack:latest") and
("localstack/localstack:nightly") throw the same ArgumentException message when
built without LOCALSTACK_AUTH_TOKEN (use ExpectArgEx), and add companion tests
that call WithEnvironment("LOCALSTACK_AUTH_TOKEN", "<auth-token>") and assert no
exception (use Xunit.Record.Exception and Assert.Null). These tests exercise the
validation path in LocalStackBuilder.Validate() that uses MatchLatestOrNightly()
to require auth tokens.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 26b1294e-49a4-4b70-b66a-ecec79309e93
📒 Files selected for processing (12)
src/Testcontainers.Kafka/KafkaBuilder.cssrc/Testcontainers.LocalStack/LocalStackBuilder.cssrc/Testcontainers.LocalStack/Usings.cssrc/Testcontainers.Neo4j/Neo4jBuilder.cssrc/Testcontainers.Oracle/OracleBuilder.cssrc/Testcontainers/Builders/AbstractBuilder4.cs`src/Testcontainers/Builders/ContainerBuilder3.cs`src/Testcontainers/Builders/ImageFromDockerfileBuilder.cssrc/Testcontainers/Builders/NetworkBuilder.cssrc/Testcontainers/Builders/VolumeBuilder.cstests/Testcontainers.LocalStack.Tests/Dockerfiletests/Testcontainers.LocalStack.Tests/LocalStackBuilderTest.cs
What does this PR do?
The LocalStack team reached out and let us know that starting from version 4.15, LocalStack requires the
LOCALSTACK_AUTH_TOKENenvironment variable to be set. This PR updates the LocalStack module to enforce that requirement. If the variable isn't provided, it throws an exception and directs the developer to the LocalStack blog/documentation. /cc @HarshCasperWhy is it important?
Make it more visible to users that the LocalStack module requires the environment variable.
Related issues
localstack/localstack:latestwill require auth token from March 23 — LocalStack module docs & examples need updating #1663Summary by CodeRabbit
Release Notes
New Features
LOCALSTACK_AUTH_TOKENenvironment variable requirement for LocalStack 4.15 and later versions.Tests
Chores