Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
216bfafb
Commit
216bfafb
authored
Sep 19, 2019
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add code review remarks
parent
7f0f6e76
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
15 deletions
+16
-15
go/internal/config/config.go
go/internal/config/config.go
+9
-0
go/internal/gitlabnet/client.go
go/internal/gitlabnet/client.go
+1
-11
go/internal/gitlabnet/client_test.go
go/internal/gitlabnet/client_test.go
+6
-4
No files found.
go/internal/config/config.go
View file @
216bfafb
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"os"
"os"
"path"
"path"
"path/filepath"
"path/filepath"
"strings"
yaml
"gopkg.in/yaml.v2"
yaml
"gopkg.in/yaml.v2"
)
)
...
@@ -121,3 +122,11 @@ func parseSecret(cfg *Config) error {
...
@@ -121,3 +122,11 @@ func parseSecret(cfg *Config) error {
return
nil
return
nil
}
}
func
(
c
*
Config
)
IpAddr
()
string
{
address
:=
os
.
Getenv
(
"SSH_CONNECTION"
)
if
address
!=
""
{
return
strings
.
Fields
(
address
)[
0
]
}
return
address
}
go/internal/gitlabnet/client.go
View file @
216bfafb
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"os"
"strings"
"strings"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
...
@@ -110,8 +109,7 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R
...
@@ -110,8 +109,7 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R
request
.
Header
.
Set
(
secretHeaderName
,
encodedSecret
)
request
.
Header
.
Set
(
secretHeaderName
,
encodedSecret
)
request
.
Header
.
Add
(
"Content-Type"
,
"application/json"
)
request
.
Header
.
Add
(
"Content-Type"
,
"application/json"
)
ip
:=
ipAddr
()
request
.
Header
.
Add
(
"X_FORWARDED_FOR"
,
c
.
config
.
IpAddr
())
request
.
Header
.
Add
(
"X_FORWARDED_FOR"
,
ip
)
request
.
Close
=
true
request
.
Close
=
true
...
@@ -127,14 +125,6 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R
...
@@ -127,14 +125,6 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R
return
response
,
nil
return
response
,
nil
}
}
func
ipAddr
()
string
{
address
:=
os
.
Getenv
(
"SSH_CONNECTION"
)
if
address
!=
""
{
return
strings
.
Fields
(
address
)[
0
]
}
return
address
}
func
ParseJSON
(
hr
*
http
.
Response
,
response
interface
{})
error
{
func
ParseJSON
(
hr
*
http
.
Response
,
response
interface
{})
error
{
if
err
:=
json
.
NewDecoder
(
hr
.
Body
)
.
Decode
(
response
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
hr
.
Body
)
.
Decode
(
response
);
err
!=
nil
{
return
ParsingError
return
ParsingError
...
...
go/internal/gitlabnet/client_test.go
View file @
216bfafb
...
@@ -55,7 +55,7 @@ func TestClients(t *testing.T) {
...
@@ -55,7 +55,7 @@ func TestClients(t *testing.T) {
Path
:
"/api/v4/internal/with_ip"
,
Path
:
"/api/v4/internal/with_ip"
,
Handler
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
Handler
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
header
:=
r
.
Header
.
Get
(
"X_FORWARDED_FOR"
)
header
:=
r
.
Header
.
Get
(
"X_FORWARDED_FOR"
)
require
.
Equal
(
t
,
header
,
"127.0.0.1"
)
require
.
Equal
(
t
,
"127.0.0.1"
,
header
)
},
},
},
},
{
{
...
@@ -229,21 +229,23 @@ func testAuthenticationHeader(t *testing.T, client *GitlabClient) {
...
@@ -229,21 +229,23 @@ func testAuthenticationHeader(t *testing.T, client *GitlabClient) {
func
testXForwardedForHeader
(
t
*
testing
.
T
,
client
*
GitlabClient
)
{
func
testXForwardedForHeader
(
t
*
testing
.
T
,
client
*
GitlabClient
)
{
t
.
Run
(
"X-Forwarded-For for GET"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"X-Forwarded-For for GET"
,
func
(
t
*
testing
.
T
)
{
os
.
Setenv
(
"SSH_CONNECTION"
,
"127.0.0.1 0"
)
err
:=
os
.
Setenv
(
"SSH_CONNECTION"
,
"127.0.0.1 0"
)
require
.
Nil
(
t
,
err
)
response
,
err
:=
client
.
Get
(
"/with_ip"
)
response
,
err
:=
client
.
Get
(
"/with_ip"
)
defer
response
.
Body
.
Close
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
response
)
require
.
NotNil
(
t
,
response
)
response
.
Body
.
Close
()
})
})
t
.
Run
(
"X-Forwarded-For for POST"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"X-Forwarded-For for POST"
,
func
(
t
*
testing
.
T
)
{
data
:=
map
[
string
]
string
{
"key"
:
"value"
}
data
:=
map
[
string
]
string
{
"key"
:
"value"
}
os
.
Setenv
(
"SSH_CONNECTION"
,
"127.0.0.1 0"
)
os
.
Setenv
(
"SSH_CONNECTION"
,
"127.0.0.1 0"
)
response
,
err
:=
client
.
Post
(
"/with_ip"
,
data
)
response
,
err
:=
client
.
Post
(
"/with_ip"
,
data
)
defer
response
.
Body
.
Close
()
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
response
)
require
.
NotNil
(
t
,
response
)
response
.
Body
.
Close
()
})
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment