Preserve viewer source port in audit log for MAP-E client identification#39
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 Walkthroughウォークスルー
変更内容
推奨コード レビュー対象領域
推定コード レビュー工数🎯 2 (Simple) | ⏱️ ~10 minutes 関連の可能性があるPR
ウサギからのお祝い詩
🚥 Pre-merge checks | ✅ 3✅ 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)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
runner/handler_test.go (1)
665-700: 🧹 Nitpick | 🔵 TrivialLGTM! テストが新しい動作を正しく検証しています。
ip:port形式のフルアドレスがauditログに記録されることを確認するテストに更新されており、handler.goの変更と整合しています。AI生成サマリーによると
TestExecuteCloudFrontViewerAddressWithoutPortが削除されていますが、CloudFrontは常にポートを含むため、この削除は妥当です。IPv6アドレスのテストケースを追加すると、カバレッジがより包括的になります:
📝 IPv6テストケースの追加案
// TestExecuteCloudFrontViewerAddressIPv6 verifies that IPv6 addresses with port // are preserved in the audit log remote field. func TestExecuteCloudFrontViewerAddressIPv6(t *testing.T) { var buf bytes.Buffer log.SetOutput(&buf) defer log.SetOutput(os.Stderr) sm := NewSessionManager() defer sm.CloseAll() sm.newShell = func() (Shell, error) { return &mockShell{exitCode: 0}, nil } handler := newHandler(sm, nil) id, _, err := sm.Create() if err != nil { t.Fatalf("Create() error: %v", err) } body := strings.NewReader(`{"command":"ls"}`) req := httptest.NewRequest(http.MethodPost, "/api/execute", body) req.AddCookie(&http.Cookie{Name: "session_id", Value: id}) req.Header.Set("CloudFront-Viewer-Address", "[2001:db8::1]:54321") w := httptest.NewRecorder() handler.ServeHTTP(w, req) if w.Code != http.StatusOK { t.Fatalf("status = %d, want %d", w.Code, http.StatusOK) } logOutput := buf.String() if !strings.Contains(logOutput, "remote=[2001:db8::1]:54321") { t.Fatalf("expected audit log to contain remote=[2001:db8::1]:54321, got:\n%s", logOutput) } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@runner/handler_test.go` around lines 665 - 700, Add an IPv6 test analogous to TestExecuteCloudFrontViewerAddress to ensure bracketed IPv6+port values are preserved in the audit remote field: create TestExecuteCloudFrontViewerAddressIPv6 that sets up a SessionManager (sm), uses sm.newShell to return a mockShell, creates a handler via newHandler(sm, nil), issues an httptest POST to /api/execute with the session_id cookie and header CloudFront-Viewer-Address set to "[2001:db8::1]:54321", calls handler.ServeHTTP, asserts status OK, captures log output, and verifies it contains "remote=[2001:db8::1]:54321" (matching the pattern used in the existing TestExecuteCloudFrontViewerAddress).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@runner/handler_test.go`:
- Around line 665-700: Add an IPv6 test analogous to
TestExecuteCloudFrontViewerAddress to ensure bracketed IPv6+port values are
preserved in the audit remote field: create
TestExecuteCloudFrontViewerAddressIPv6 that sets up a SessionManager (sm), uses
sm.newShell to return a mockShell, creates a handler via newHandler(sm, nil),
issues an httptest POST to /api/execute with the session_id cookie and header
CloudFront-Viewer-Address set to "[2001:db8::1]:54321", calls handler.ServeHTTP,
asserts status OK, captures log output, and verifies it contains
"remote=[2001:db8::1]:54321" (matching the pattern used in the existing
TestExecuteCloudFrontViewerAddress).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: aec3bb85-d40e-4abf-821d-66c5cf1e15b5
📒 Files selected for processing (2)
runner/handler.gorunner/handler_test.go
Summary
ip:portfromCloudFront-Viewer-Addressheader in audit logs instead of stripping the portnetimport and simplifyclientIP()functionTest plan
docker build --target test runner/passes with 100% coverageremote=in audit logs showsip:portformat🤖 Generated with Claude Code
Summary by CodeRabbit
リリースノート