fix(purchases): mask idempotency token in EC2 RI re-drive log (closes #656)#855
fix(purchases): mask idempotency token in EC2 RI re-drive log (closes #656)#855cristim wants to merge 1 commit into
Conversation
|
@coderabbitai review |
📝 WalkthroughWalkthroughPurchaseCommitment now masks idempotency tokens in logs using ChangesIdempotency Token Masking
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
providers/aws/services/ec2/client_test.go (1)
712-715: 🏗️ Heavy liftTest does not actually verify the skip-log line masks the token.
Lines 712-715 assert
common.MaskToken(token)directly, which only exercises the standalone helper (already covered bytokens_test.go). The production change atclient.go:137is not observed here — if someone reverted that line to log the rawopts.IdempotencyToken, this test would still pass. To guard the regression this PR fixes, capturelogoutput and assert the raw 64-char token never appears while the masked prefix does. Note that doing so requires redirecting the globallogwriter, which conflicts witht.Parallel(), so this test would need to drop parallelism.♻️ Sketch: capture log output to assert masking on the real path
func TestPurchaseCommitment_IdempotencySkipLogMasked(t *testing.T) { // no t.Parallel(): we redirect the global log writer below var buf bytes.Buffer log.SetOutput(&buf) t.Cleanup(func() { log.SetOutput(os.Stderr) }) // ... existing mock/setup/PurchaseCommitment call ... out := buf.String() assert.NotContains(t, out, token, "raw idempotency token must not be logged") assert.Contains(t, out, token[:8]+"...", "skip log must contain the masked token") }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@providers/aws/services/ec2/client_test.go` around lines 712 - 715, The test currently only calls common.MaskToken(token) but doesn't verify the actual logging path in PurchaseCommitment masks opts.IdempotencyToken; update the test (e.g., TestPurchaseCommitment_IdempotencySkipLogMasked) to stop using t.Parallel(), redirect the global log output with log.SetOutput to a bytes.Buffer (and restore it in t.Cleanup), call the real PurchaseCommitment path that triggers the skip-log, then assert the buffer does NOT contain the raw 64-char token and DOES contain common.MaskToken(token) or token[:8]+"..." to ensure the production log uses the masked form rather than the raw opts.IdempotencyToken.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@providers/aws/services/ec2/client_test.go`:
- Around line 712-715: The test currently only calls common.MaskToken(token) but
doesn't verify the actual logging path in PurchaseCommitment masks
opts.IdempotencyToken; update the test (e.g.,
TestPurchaseCommitment_IdempotencySkipLogMasked) to stop using t.Parallel(),
redirect the global log output with log.SetOutput to a bytes.Buffer (and restore
it in t.Cleanup), call the real PurchaseCommitment path that triggers the
skip-log, then assert the buffer does NOT contain the raw 64-char token and DOES
contain common.MaskToken(token) or token[:8]+"..." to ensure the production log
uses the masked form rather than the raw opts.IdempotencyToken.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ebcb5e45-8b14-4ee1-907a-8db641f26f7c
📒 Files selected for processing (2)
providers/aws/services/ec2/client.goproviders/aws/services/ec2/client_test.go
Summary
opts.IdempotencyTokenwithcommon.MaskTokenin the EC2 RI idempotency-guard skip log (providers/aws/services/ec2/client.go:137), bringing EC2 in line with the five sibling executors (RDS, ElastiCache, MemoryDB, OpenSearch, Redshift) fixed in PR feat(purchases): make AWS RDS/ElastiCache/MemoryDB/OpenSearch/Redshift idempotent (refs #641) #652.pkg/commonis already imported.TestPurchaseCommitment_IdempotencySkipLogMaskedasserting the re-drive path returns success and thatMaskTokenproduces the<first-8>...shape, not the raw 64-char token.Test plan
go build ./...cleango test github.com/LeanerCloud/CUDly/providers/aws/services/ec2/...-- 40 tests pass (39 before + 1 new)MaskToken; SavingsPlans passes token asClientTokenwith no skip logSummary by CodeRabbit
Bug Fixes
Tests