Skip to content

Commit

Permalink
Hide client name from output
Browse files Browse the repository at this point in the history
  • Loading branch information
morestatic committed Jul 19, 2022
1 parent 8ba9d05 commit 99c7209
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
18 changes: 9 additions & 9 deletions internal/pkg/controllers/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestTunnelCreateWithClientID(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"123","client_id":"334","client_name":"","lhost":"lohost1","lport":"3300","rhost":"rhost2","rport":"3344","lport_random":true,"scheme":"ssh","acl":"3.4.5.6","usage":"ssh -p 3300 localhost.com -l ${USER}","idle_timeout_minutes":7,"rport_server":"%s"}`,
`{"id":"123","client_id":"334","lhost":"lohost1","lport":"3300","rhost":"rhost2","rport":"3344","lport_random":true,"scheme":"ssh","acl":"3.4.5.6","usage":"ssh -p 3300 localhost.com -l ${USER}","idle_timeout_minutes":7,"rport_server":"%s"}`,
srv.URL,
)
assert.Equal(t, expectedOutput, buf.String())
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestTunnelCreateWithSchemeDiscovery(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"444","client_id":"32312","client_name":"","lhost":"lohost33","lport":"","rhost":"","rport":"","lport_random":false,"scheme":"","acl":"","usage":"ssh ya.ru -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}`,
`{"id":"444","client_id":"32312","lhost":"lohost33","lport":"","rhost":"","rport":"","lport_random":false,"scheme":"","acl":"","usage":"ssh ya.ru -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}`,
srv.URL,
)

Expand Down Expand Up @@ -380,7 +380,7 @@ func TestTunnelCreateWithPortDiscovery(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"777","client_id":"1313","client_name":"","lhost":"lohost44","lport":"","rhost":"","rport":"","lport_random":false,"scheme":"","acl":"","usage":"ssh some.com -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}`,
`{"id":"777","client_id":"1313","lhost":"lohost44","lport":"","rhost":"","rport":"","lport_random":false,"scheme":"","acl":"","usage":"ssh some.com -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}`,
srv.URL,
)

Expand All @@ -397,7 +397,7 @@ func TestTunnelCreateWithPortDiscovery(t *testing.T) {
assert.NoError(t, err)

expectedOutput2 := fmt.Sprintf(
`{"id":"777","client_id":"1313","client_name":"","lhost":"lohost44","lport":"","rhost":"","rport":"","lport_random":false,"scheme":"","acl":"","usage":"ssh some.com -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}{"status":"Tunnel successfully deleted"}`,
`{"id":"777","client_id":"1313","lhost":"lohost44","lport":"","rhost":"","rport":"","lport_random":false,"scheme":"","acl":"","usage":"ssh some.com -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}{"status":"Tunnel successfully deleted"}`,
srv.URL,
)
assert.Equal(
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestTunnelCreateWithSSH(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"777","client_id":"1314","client_name":"","lhost":"lohost77","lport":"22","rhost":"","rport":"","lport_random":false,"scheme":"ssh","acl":"","usage":"ssh -p 22 rport-url.com -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}{"status":"Tunnel successfully deleted"}`,
`{"id":"777","client_id":"1314","lhost":"lohost77","lport":"22","rhost":"","rport":"","lport_random":false,"scheme":"ssh","acl":"","usage":"ssh -p 22 rport-url.com -l ${USER}","idle_timeout_minutes":5,"rport_server":"%s"}{"status":"Tunnel successfully deleted"}`,
srv.URL,
)

Expand Down Expand Up @@ -531,7 +531,7 @@ func TestTunnelCreateWithHTTP(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"10","client_id":"1314","client_name":"","lhost":"0.0.0.0","lport":"20793","rhost":"","rport":"","lport_random":false,"scheme":"http","acl":"","usage":"http://rport-url.com:20793","idle_timeout_minutes":5,"rport_server":"%s"}`,
`{"id":"10","client_id":"1314","lhost":"0.0.0.0","lport":"20793","rhost":"","rport":"","lport_random":false,"scheme":"http","acl":"","usage":"http://rport-url.com:20793","idle_timeout_minutes":5,"rport_server":"%s"}`,
srv.URL,
)

Expand Down Expand Up @@ -590,7 +590,7 @@ func TestTunnelCreateWithHTTPS(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"10","client_id":"1314","client_name":"","lhost":"0.0.0.0","lport":"20793","rhost":"","rport":"","lport_random":false,"scheme":"https","acl":"","usage":"https://rport-url.com:20793","idle_timeout_minutes":5,"rport_server":"%s"}`,
`{"id":"10","client_id":"1314","lhost":"0.0.0.0","lport":"20793","rhost":"","rport":"","lport_random":false,"scheme":"https","acl":"","usage":"https://rport-url.com:20793","idle_timeout_minutes":5,"rport_server":"%s"}`,
srv.URL,
)

Expand Down Expand Up @@ -650,7 +650,7 @@ func TestTunnelCreateWithHTTPProxy(t *testing.T) {
assert.NoError(t, err)

expectedOutput := fmt.Sprintf(
`{"id":"10","client_id":"1314","client_name":"","lhost":"0.0.0.0","lport":"20793","rhost":"","rport":"","lport_random":false,"scheme":"http","acl":"","usage":"https://rport-url.com:20793","idle_timeout_minutes":5,"rport_server":"%s"}`,
`{"id":"10","client_id":"1314","lhost":"0.0.0.0","lport":"20793","rhost":"","rport":"","lport_random":false,"scheme":"http","acl":"","usage":"https://rport-url.com:20793","idle_timeout_minutes":5,"rport_server":"%s"}`,
srv.URL,
)

Expand Down Expand Up @@ -786,7 +786,7 @@ func TestTunnelCreateWithRDP(t *testing.T) {
assert.Equal(t, expectedFileInput.UserName, fileWriter.FileInput.UserName)

expectedOutput := fmt.Sprintf(
`{"id":"777","client_id":"1314","client_name":"","lhost":"lohost77","lport":"3344","rhost":"","rport":"","lport_random":false,"scheme":"rdp","acl":"","usage":"rdp://rport-url123.com:3344","idle_timeout_minutes":5,"rport_server":"%s"}`,
`{"id":"777","client_id":"1314","lhost":"lohost77","lport":"3344","rhost":"","rport":"","lport_random":false,"scheme":"rdp","acl":"","usage":"rdp://rport-url123.com:3344","idle_timeout_minutes":5,"rport_server":"%s"}`,
srv.URL,
)
assert.Equal(t, expectedOutput, renderBuf.String())
Expand Down
15 changes: 10 additions & 5 deletions internal/pkg/models/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (t *Tunnel) KeyValues() []testing.KeyValueStr {
type TunnelCreated struct {
ID string `json:"id"`
ClientID string `json:"client_id" yaml:"client_id"`
ClientName string `json:"client_name" yaml:"client_name"`
ClientName string `json:"client_name,omitempty" yaml:"client_name,omitempty"`
Lhost string `json:"lhost" yaml:"local_host"`
Lport string `json:"lport" yaml:"local_port"`
Rhost string `json:"rhost" yaml:"remote_host"`
Expand All @@ -141,10 +141,6 @@ func (tc *TunnelCreated) KeyValues() []testing.KeyValueStr {
Key: "CLIENT_ID",
Value: tc.ClientID,
},
{
Key: "CLIENT_NAME",
Value: tc.ClientName,
},
{
Key: "LOCAL_HOST",
Value: tc.Lhost,
Expand Down Expand Up @@ -183,5 +179,14 @@ func (tc *TunnelCreated) KeyValues() []testing.KeyValueStr {
},
}

// Being defensive here. Clientname isn't returned but there is existing
// code that references it. Just in case there a dependant edge case and
// the client name is set, include it in the human-readable output.
if tc.ClientName != "" {
kvs = append(kvs, testing.KeyValueStr{
Key: "CLIENT_NAME",
Value: tc.ClientName,
})
}
return kvs
}
5 changes: 1 addition & 4 deletions internal/pkg/output/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func TestRenderTunnel(t *testing.T) {
KEY VALUE
ID: id22
CLIENT_ID:
CLIENT_NAME:
LOCAL_HOST: lhost
LOCAL_PORT: 123
REMOTE_HOST: rhost
Expand All @@ -135,7 +134,7 @@ USAGE: ssh -p 123 123.22.22.33 -l root
},
{
Format: FormatJSON,
ExpectedOutput: `{"id":"id22","client_id":"","client_name":"","lhost":"lhost","lport":"123","rhost":"rhost","rport":"124","lport_random":false,"scheme":"ssh","acl":"0.0.0.0","usage":"ssh -p 123 123.22.22.33 -l root","idle_timeout_minutes":7}
ExpectedOutput: `{"id":"id22","client_id":"","lhost":"lhost","lport":"123","rhost":"rhost","rport":"124","lport_random":false,"scheme":"ssh","acl":"0.0.0.0","usage":"ssh -p 123 123.22.22.33 -l root","idle_timeout_minutes":7}
`,
ColCountToGive: 10,
},
Expand All @@ -144,7 +143,6 @@ USAGE: ssh -p 123 123.22.22.33 -l root
ExpectedOutput: `{
"id": "id22",
"client_id": "",
"client_name": "",
"lhost": "lhost",
"lport": "123",
"rhost": "rhost",
Expand All @@ -162,7 +160,6 @@ USAGE: ssh -p 123 123.22.22.33 -l root
Format: FormatYAML,
ExpectedOutput: `id: id22
client_id: ""
client_name: ""
local_host: lhost
local_port: "123"
remote_host: rhost
Expand Down

0 comments on commit 99c7209

Please sign in to comment.