summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMałgorzata Ksionek <mksionek@gitlab.com>2019-09-30 10:36:35 +0200
committerMałgorzata Ksionek <mksionek@gitlab.com>2019-09-30 10:36:35 +0200
commit650ecad9bad69dbc12745c71d959a89b87ffdac7 (patch)
tree1d1a7c136be4867e536db2a476a47ad713b30f73
parent9304b1d6110494147ff7113592d8473ecb3e9114 (diff)
downloadgitlab-shell-650ecad9bad69dbc12745c71d959a89b87ffdac7.tar.gz
Clean up files
-rw-r--r--go/internal/config/config.go4
-rw-r--r--go/internal/gitlabnet/client_test.go28
-rw-r--r--go/internal/sshenv/sshenv_test.go5
-rwxr-xr-xsupport/go-test2
4 files changed, 34 insertions, 5 deletions
diff --git a/go/internal/config/config.go b/go/internal/config/config.go
index d958a82..2231851 100644
--- a/go/internal/config/config.go
+++ b/go/internal/config/config.go
@@ -51,9 +51,7 @@ func NewFromDir(dir string) (*Config, error) {
}
func newFromFile(filename string) (*Config, error) {
- cfg := &Config{
- RootDir: path.Dir(filename),
- }
+ cfg := &Config{RootDir: path.Dir(filename)}
configBytes, err := ioutil.ReadFile(filename)
if err != nil {
diff --git a/go/internal/gitlabnet/client_test.go b/go/internal/gitlabnet/client_test.go
index e813e23..f4ab62f 100644
--- a/go/internal/gitlabnet/client_test.go
+++ b/go/internal/gitlabnet/client_test.go
@@ -58,6 +58,13 @@ func TestClients(t *testing.T) {
},
},
{
+ Path: "/api/v4/internal/with_empty_ip",
+ Handler: func(w http.ResponseWriter, r *http.Request) {
+ header := r.Header.Get("X-Forwarded-For")
+ require.Equal(t, "", header)
+ },
+ },
+ {
Path: "/api/v4/internal/error",
Handler: func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
@@ -107,6 +114,7 @@ func TestClients(t *testing.T) {
tc.config.GitlabUrl = url
tc.config.Secret = "sssh, it's a secret"
+
client, err := GetClient(tc.config)
require.NoError(t, err)
@@ -117,6 +125,7 @@ func TestClients(t *testing.T) {
testErrorMessage(t, client)
testAuthenticationHeader(t, client)
testXForwardedForHeader(t, client)
+ testEmptyForwardedForHeader(t, client)
})
}
}
@@ -251,3 +260,22 @@ func testXForwardedForHeader(t *testing.T, client *GitlabClient) {
response.Body.Close()
})
}
+
+func testEmptyForwardedForHeader(t *testing.T, client *GitlabClient) {
+ t.Run("X-Forwarded-For empty for GET", func(t *testing.T) {
+ response, err := client.Get("/with_empty_ip")
+
+ require.NoError(t, err)
+ require.NotNil(t, response)
+ response.Body.Close()
+ })
+
+ t.Run("X-Forwarded-For empty for POST", func(t *testing.T) {
+ data := map[string]string{"key": "value"}
+ response, err := client.Post("/with_empty_ip", data)
+
+ require.NoError(t, err)
+ require.NotNil(t, response)
+ response.Body.Close()
+ })
+}
diff --git a/go/internal/sshenv/sshenv_test.go b/go/internal/sshenv/sshenv_test.go
index 2691df8..d2207f5 100644
--- a/go/internal/sshenv/sshenv_test.go
+++ b/go/internal/sshenv/sshenv_test.go
@@ -12,6 +12,9 @@ func TestLocalAddr(t *testing.T) {
require.NoError(t, err)
defer cleanup()
- require.Nil(t, err)
require.Equal(t, LocalAddr(), "127.0.0.1")
}
+
+func TestEmptyLocalAddr(t *testing.T) {
+ require.Equal(t, LocalAddr(), "")
+}
diff --git a/support/go-test b/support/go-test
index 47fd012..0c043f6 100755
--- a/support/go-test
+++ b/support/go-test
@@ -5,7 +5,7 @@ include GoBuild
def main
ensure_build_dir_exists
- run!(GO_ENV, %w[go test -v ./...], chdir: GO_DIR)
+ run!(GO_ENV, %w[go test ./...], chdir: GO_DIR)
puts 'OK'
end