diff --git a/sdktests/client_side_events_all.go b/sdktests/client_side_events_all.go index 94c6573..477f794 100644 --- a/sdktests/client_side_events_all.go +++ b/sdktests/client_side_events_all.go @@ -2,12 +2,11 @@ package sdktests import ( "github.com/launchdarkly/go-sdk-common/v3/ldcontext" + m "github.com/launchdarkly/go-test-helpers/v2/matchers" h "github.com/launchdarkly/sdk-test-harness/v2/framework/helpers" "github.com/launchdarkly/sdk-test-harness/v2/framework/ldtest" "github.com/launchdarkly/sdk-test-harness/v2/mockld" "github.com/launchdarkly/sdk-test-harness/v2/servicedef" - - m "github.com/launchdarkly/go-test-helpers/v2/matchers" ) func doClientSideEventTests(t *ldtest.T) { @@ -40,6 +39,10 @@ func doClientSideEventRequestTests(t *ldtest.T) { Header("Content-Type").Should(m.StringContains("application/json")), )) + if t.Capabilities().Has(servicedef.CapabilityHTTPProxy) { + eventTests.HttpProxy(t) + } + requestPathMatcher := h.IfElse( sdkKind == mockld.JSClientSDK, m.Equal("/events/bulk/"+envIDOrMobileKey), diff --git a/sdktests/common_tests_events_request.go b/sdktests/common_tests_events_request.go index 25f2dc1..24309e4 100644 --- a/sdktests/common_tests_events_request.go +++ b/sdktests/common_tests_events_request.go @@ -1,6 +1,7 @@ package sdktests import ( + "net/url" "strings" "time" @@ -119,3 +120,42 @@ func (c CommonEventTests) UniquePayloadIDs(t *ldtest.T) { } }) } + +func (c CommonEventTests) HttpProxy(t *ldtest.T) { + t.Run("http proxy", func(t *ldtest.T) { + events := NewSDKEventSink(t) + + // The idea here is that we'll configure the SDK's service endpoints with an arbitrary host, but with the + // correct path that the test harness expects (like /endpoints/1). Then, we'll inject the actual test harness's + // endpoint via the HTTP Proxy configuration. + // + // The SDK should therefore: + // 1. Open a socket to the test harness's host and port + // 2. Send an HTTP request that has the arbitrary host and the correct path + // + // If the SDK didn't support proxying, then it would attempt to connect to the arbitrary host and + // the harness should fail the connection assertion. + eventURI := strings.Replace(events.Endpoint().BaseURL(), "localhost", "not.valid.local", 1) + + u, err := url.Parse(events.Endpoint().BaseURL()) + if err != nil { + t.Errorf("unexpected error parsing URL: %s", err) + t.FailNow() + } + u.Path = "" + + dataSource := NewSDKDataSource(t, nil) + + client := NewSDKClient(t, c.baseSDKConfigurationPlus(dataSource, events, WithEventsConfig( + servicedef.SDKConfigEventParams{ + BaseURI: eventURI, + }), c.withHTTPProxy(u.String()))...) + + c.sendArbitraryEvent(t, client) + client.FlushEvents(t) + + request := events.Endpoint().RequireConnection(t, time.Second) + + m.In(t).For("request method").Assert(request.Method, m.Equal("POST")) + }) +}