Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apmproxy/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ func (c *Client) handleInfoRequest() (func(w http.ResponseWriter, r *http.Reques
r.Header.Set("X-Forwarded-Host", r.Header.Get("Host"))
r.Host = parsedApmServerURL.Host

// Override authorization header sent by the APM agents
if c.ServerAPIKey != "" {
r.Header.Add("Authorization", "ApiKey "+c.ServerAPIKey)
} else if c.ServerSecretToken != "" {
r.Header.Add("Authorization", "Bearer "+c.ServerSecretToken)
}

// Forward request to the APM server
reverseProxy.ServeHTTP(w, r)
}, nil
Expand Down
34 changes: 33 additions & 1 deletion apmproxy/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestInfoProxy(t *testing.T) {
// Create apm server and handler
apmServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for key := range headers {
assert.Equal(t, 1, len(r.Header[key]))
assert.Equal(t, 2, len(r.Header[key]))
assert.Equal(t, headers[key], r.Header[key][0])
}
w.Header().Add("test", "header")
Expand Down Expand Up @@ -88,6 +88,38 @@ func TestInfoProxy(t *testing.T) {
require.NoError(t, resp.Body.Close())
}

func TestInfoProxyAuth(t *testing.T) {
// Create apm server and handler
apmServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "ApiKey bar", r.Header.Get("Authorization"))
w.WriteHeader(http.StatusTeapot)
}))
defer apmServer.Close()

// Create extension config and start the server
apmClient, err := apmproxy.NewClient(
apmproxy.WithURL(apmServer.URL),
apmproxy.WithAPIKey("bar"),
// Use ipv4 to avoid issues in CI
apmproxy.WithReceiverAddress("127.0.0.1:1234"),
apmproxy.WithReceiverTimeout(15*time.Second),
apmproxy.WithLogger(zaptest.NewLogger(t).Sugar()),
)
require.NoError(t, err)

require.NoError(t, apmClient.StartReceiver())
defer func() {
require.NoError(t, apmClient.Shutdown())
}()

url := "http://127.0.0.1:1234"

// Send the request to the extension
resp, err := http.Get(url)
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
}

func TestInfoProxyErrorStatusCode(t *testing.T) {
// Create apm server and handler
apmServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down