-
Notifications
You must be signed in to change notification settings - Fork 0
test: align E2E coverage with current EE models #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,15 +3,52 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package e2e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "net/http" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/stretchr/testify/assert" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // waitForGatewayStatus polls the gateway until the desired status is observed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // or the timeout expires. Each request is bound to the remaining deadline so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // stalled HTTP call cannot outlive the caller-provided timeout. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func waitForGatewayStatus(url string, buildRequest func() (*http.Request, error), want func(int) bool, timeout time.Duration) (int, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deadline := time.Now().Add(timeout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lastStatus := 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+23
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var lastErr error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for time.Now().Before(deadline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req, err := buildRequest() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0, err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx, cancel := context.WithDeadline(context.Background(), deadline) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req = req.WithContext(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resp, err := insecureClient.Do(req) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cancel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lastErr = err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time.Sleep(500 * time.Millisecond) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lastStatus = resp.StatusCode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resp.Body.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if want(resp.StatusCode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return resp.StatusCode, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| time.Sleep(500 * time.Millisecond) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if lastErr != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return lastStatus, lastErr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return lastStatus, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+34
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clear Line 35 makes transient transport failures sticky for the rest of the wait. If the gateway briefly refuses connections and then only returns 🛠 Suggested fix resp, err := insecureClient.Do(req)
cancel()
if err != nil {
lastErr = err
time.Sleep(500 * time.Millisecond)
continue
}
+ lastErr = nil
lastStatus = resp.StatusCode
resp.Body.Close()📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+50
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // deleteConsumerViaCLI deletes a consumer using the a7 CLI. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func deleteConsumerViaCLI(t *testing.T, env []string, username string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Helper() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -111,60 +148,78 @@ func TestConsumer_WithKeyAuth(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requireHTTPBin(t) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env := setupEnv(t) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| username := "e2e-consumer-keyauth" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| svcID := "e2e-service-keyauth" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| routeID := "e2e-route-keyauth" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| credID := "e2e-cred-keyauth" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Cleanup(func() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deleteRouteViaAdmin(t, routeID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deleteServiceViaAdmin(t, svcID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deleteConsumerViaAdmin(t, username) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create consumer (no auth plugins — API7 EE requires credentials). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createTestConsumerViaCLI(t, env, username) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createTestServiceViaCLI(t, env, svcID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create credential with key-auth plugin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| credJSON := fmt.Sprintf(`{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": %q, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "plugins": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "key-auth": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "key": "e2e-key-%s" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`, username) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`, credID, username) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| credFile := filepath.Join(t.TempDir(), "credential.json") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, os.WriteFile(credFile, []byte(credJSON), 0644)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _, stderr, err := runA7WithEnv(env, "credential", "create", credID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout, stderr, err := runA7WithEnv(env, "credential", "create", credID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--consumer", username, "-f", credFile, "-g", gatewayGroup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Skipf("credential create failed: %s", stderr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, err, "stdout=%s stderr=%s", stdout, stderr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
150
to
+177
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create route with key-auth plugin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| routeJSON := fmt.Sprintf(`{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "id": %q, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "route-keyauth", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "service_id": %q, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "paths": ["/test-keyauth"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "upstream": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type": "roundrobin", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nodes": {"%s": 1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "plugins": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "key-auth": {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "proxy-rewrite": {"uri": "/get"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`, routeID, upstreamNode()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }`, routeID, svcID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tmpFile := filepath.Join(t.TempDir(), "route.json") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, os.WriteFile(tmpFile, []byte(routeJSON), 0644)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _, stderr, err = runA7WithEnv(env, "route", "create", "-f", tmpFile, "-g", gatewayGroup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, err, stderr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdout, stderr, err = runA7WithEnv(env, "route", "create", "-f", tmpFile, "-g", gatewayGroup) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, err, "stdout=%s stderr=%s", stdout, stderr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Verify: request without key should fail (401 or 403) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resp, err := insecureClient.Get(gatewayURL + "/test-keyauth") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer resp.Body.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.True(t, resp.StatusCode == 401 || resp.StatusCode == 403, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "expected 401/403 without key, got %d", resp.StatusCode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status, err := waitForGatewayStatus(gatewayURL+"/test-keyauth", func() (*http.Request, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return http.NewRequest("GET", gatewayURL+"/test-keyauth", nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, func(code int) bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return code == 401 || code == 403 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, 15*time.Second) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if status == 404 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Skip("route did not propagate to the local gateway within timeout; skipping live key-auth assertion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.True(t, status == 401 || status == 403, "expected 401/403 without key, got %d", status) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| status, err = waitForGatewayStatus(gatewayURL+"/test-keyauth", func() (*http.Request, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req, err := http.NewRequest("GET", gatewayURL+"/test-keyauth", nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req.Header.Set("apikey", "e2e-key-"+username) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return req, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, func(code int) bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return code == 200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, 15*time.Second) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if status == 404 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| t.Skip("authenticated route did not propagate to the local gateway within timeout; skipping live key-auth assertion") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.Equal(t, 200, status) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func TestConsumer_DeleteNonexistent(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sanitizeDumpForSyncis introduced but not used anywhere in this test file. If it’s no longer needed, consider removing it to avoid dead code; if it is intended for the roundtrip sync flow, consider calling it (or folding it intotrimDumpForRoundtrip).