diff options
author | Małgorzata Ksionek <mksionek@gitlab.com> | 2019-09-17 16:36:37 +0200 |
---|---|---|
committer | Małgorzata Ksionek <mksionek@gitlab.com> | 2019-09-26 12:26:53 +0200 |
commit | 7f0f6e7621cbc60504f0c1f1bf1541d5b95a4ff8 (patch) | |
tree | ba6a69dcc3574023c4b370b774b728458b64ca9f /go/internal/gitlabnet/client_test.go | |
parent | 659ad7f7cedab56ff48abe4d6fb8eb25a644a2a8 (diff) | |
download | gitlab-shell-7f0f6e7621cbc60504f0c1f1bf1541d5b95a4ff8.tar.gz |
Add ip address to headers
Diffstat (limited to 'go/internal/gitlabnet/client_test.go')
-rw-r--r-- | go/internal/gitlabnet/client_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/go/internal/gitlabnet/client_test.go b/go/internal/gitlabnet/client_test.go index e8499dc..debe618 100644 --- a/go/internal/gitlabnet/client_test.go +++ b/go/internal/gitlabnet/client_test.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "net/http" + "os" "path" "testing" @@ -51,6 +52,13 @@ func TestClients(t *testing.T) { }, }, { + Path: "/api/v4/internal/with_ip", + Handler: func(w http.ResponseWriter, r *http.Request) { + header := r.Header.Get("X_FORWARDED_FOR") + require.Equal(t, header, "127.0.0.1") + }, + }, + { Path: "/api/v4/internal/error", Handler: func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") @@ -110,6 +118,7 @@ func TestClients(t *testing.T) { testMissing(t, client) testErrorMessage(t, client) testAuthenticationHeader(t, client) + testXForwardedForHeader(t, client) }) } } @@ -217,3 +226,24 @@ func testAuthenticationHeader(t *testing.T, client *GitlabClient) { assert.Equal(t, "sssh, it's a secret", string(header)) }) } + +func testXForwardedForHeader(t *testing.T, client *GitlabClient) { + t.Run("X-Forwarded-For for GET", func(t *testing.T) { + os.Setenv("SSH_CONNECTION", "127.0.0.1 0") + response, err := client.Get("/with_ip") + defer response.Body.Close() + + require.NoError(t, err) + require.NotNil(t, response) + }) + + t.Run("X-Forwarded-For for POST", func(t *testing.T) { + data := map[string]string{"key": "value"} + os.Setenv("SSH_CONNECTION", "127.0.0.1 0") + response, err := client.Post("/with_ip", data) + defer response.Body.Close() + + require.NoError(t, err) + require.NotNil(t, response) + }) +} |