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
8071ea11
Commit
8071ea11
authored
Sep 23, 2019
by
Małgorzata Ksionek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cr remarks
parent
216bfafb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
9 deletions
+16
-9
go/internal/config/config.go
go/internal/config/config.go
+6
-2
go/internal/config/config_test.go
go/internal/config/config_test.go
+8
-0
go/internal/gitlabnet/client.go
go/internal/gitlabnet/client.go
+1
-1
go/internal/gitlabnet/client_test.go
go/internal/gitlabnet/client_test.go
+1
-6
No files found.
go/internal/config/config.go
View file @
8071ea11
...
...
@@ -36,6 +36,7 @@ type Config struct {
Secret
string
`yaml:"secret"`
HttpSettings
HttpSettingsConfig
`yaml:"http_settings"`
HttpClient
*
HttpClient
IPAddr
string
}
func
New
()
(
*
Config
,
error
)
{
...
...
@@ -52,7 +53,10 @@ func NewFromDir(dir string) (*Config, error) {
}
func
newFromFile
(
filename
string
)
(
*
Config
,
error
)
{
cfg
:=
&
Config
{
RootDir
:
path
.
Dir
(
filename
)}
cfg
:=
&
Config
{
RootDir
:
path
.
Dir
(
filename
),
IPAddr
:
getIPAddr
(),
}
configBytes
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
...
...
@@ -123,7 +127,7 @@ func parseSecret(cfg *Config) error {
return
nil
}
func
(
c
*
Config
)
Ip
Addr
()
string
{
func
getIP
Addr
()
string
{
address
:=
os
.
Getenv
(
"SSH_CONNECTION"
)
if
address
!=
""
{
return
strings
.
Fields
(
address
)[
0
]
...
...
go/internal/config/config_test.go
View file @
8071ea11
...
...
@@ -2,6 +2,7 @@ package config
import
(
"fmt"
"os"
"path"
"testing"
...
...
@@ -110,3 +111,10 @@ func TestParseConfig(t *testing.T) {
})
}
}
func
TestGetIPAddr
(
t
*
testing
.
T
)
{
err
:=
os
.
Setenv
(
"SSH_CONNECTION"
,
"127.0.0.1 0"
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
getIPAddr
(),
"127.0.0.1"
)
}
go/internal/gitlabnet/client.go
View file @
8071ea11
...
...
@@ -109,7 +109,7 @@ func (c *GitlabClient) DoRequest(method, path string, data interface{}) (*http.R
request
.
Header
.
Set
(
secretHeaderName
,
encodedSecret
)
request
.
Header
.
Add
(
"Content-Type"
,
"application/json"
)
request
.
Header
.
Add
(
"X_FORWARDED_FOR"
,
c
.
config
.
I
pAddr
()
)
request
.
Header
.
Add
(
"X_FORWARDED_FOR"
,
c
.
config
.
I
PAddr
)
request
.
Close
=
true
...
...
go/internal/gitlabnet/client_test.go
View file @
8071ea11
...
...
@@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"testing"
...
...
@@ -108,7 +107,7 @@ func TestClients(t *testing.T) {
tc
.
config
.
GitlabUrl
=
url
tc
.
config
.
Secret
=
"sssh, it's a secret"
tc
.
config
.
IPAddr
=
"127.0.0.1"
client
,
err
:=
GetClient
(
tc
.
config
)
require
.
NoError
(
t
,
err
)
...
...
@@ -229,9 +228,6 @@ func testAuthenticationHeader(t *testing.T, client *GitlabClient) {
func
testXForwardedForHeader
(
t
*
testing
.
T
,
client
*
GitlabClient
)
{
t
.
Run
(
"X-Forwarded-For for GET"
,
func
(
t
*
testing
.
T
)
{
err
:=
os
.
Setenv
(
"SSH_CONNECTION"
,
"127.0.0.1 0"
)
require
.
Nil
(
t
,
err
)
response
,
err
:=
client
.
Get
(
"/with_ip"
)
require
.
NoError
(
t
,
err
)
...
...
@@ -241,7 +237,6 @@ func testXForwardedForHeader(t *testing.T, client *GitlabClient) {
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
)
require
.
NoError
(
t
,
err
)
...
...
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