@@ -14,11 +14,12 @@ func TestResolveNodeSSHEntry_HappyPath(t *testing.T) {
1414 node := & nodev1.ExternalNode {
1515 Name : "My GPU Box" ,
1616 SshAccess : []* nodev1.SSHAccess {
17- {UserId : "user_1" , LinuxUser : "ec2-user" },
17+ {UserId : "user_1" , LinuxUser : "ec2-user" , PortId : "port_1" },
1818 },
1919 Ports : []* nodev1.Port {
2020 {
21- Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_SSH ,
21+ PortId : "port_1" ,
22+ Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_TCP ,
2223 PortNumber : 41920 ,
2324 ServerPort : 22 ,
2425 Hostname : strPtr ("10.0.0.5" ),
@@ -48,11 +49,12 @@ func TestResolveNodeSSHEntry_UsesServerPortNotPortNumber(t *testing.T) {
4849 node := & nodev1.ExternalNode {
4950 Name : "test-node" ,
5051 SshAccess : []* nodev1.SSHAccess {
51- {UserId : "user_1" , LinuxUser : "ubuntu" },
52+ {UserId : "user_1" , LinuxUser : "ubuntu" , PortId : "port_1" },
5253 },
5354 Ports : []* nodev1.Port {
5455 {
55- Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_SSH ,
56+ PortId : "port_1" ,
57+ Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_TCP ,
5658 PortNumber : 51234 , // netbird-assigned port — correct
5759 ServerPort : 22 , // well-known port — NOT what we should connect to
5860 Hostname : strPtr ("gateway.example.com" ),
@@ -76,7 +78,7 @@ func TestResolveNodeSSHEntry_SkipsNoAccess(t *testing.T) {
7678 {UserId : "other_user" , LinuxUser : "ubuntu" },
7779 },
7880 Ports : []* nodev1.Port {
79- {Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_SSH , ServerPort : 22 , Hostname : strPtr ("h" )},
81+ {PortId : "port_1" , Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_TCP , ServerPort : 22 , Hostname : strPtr ("h" )},
8082 },
8183 }
8284
@@ -86,31 +88,34 @@ func TestResolveNodeSSHEntry_SkipsNoAccess(t *testing.T) {
8688 }
8789}
8890
89- func TestResolveNodeSSHEntry_SkipsNoSSHPort (t * testing.T ) {
91+ func TestResolveNodeSSHEntry_UsesAccessPortNotProtocol (t * testing.T ) {
9092 node := & nodev1.ExternalNode {
9193 Name : "box" ,
9294 SshAccess : []* nodev1.SSHAccess {
93- {UserId : "user_1" , LinuxUser : "ubuntu" },
95+ {UserId : "user_1" , LinuxUser : "ubuntu" , PortId : "port_tcp" },
9496 },
9597 Ports : []* nodev1.Port {
96- {Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_TCP , ServerPort : 8080 , Hostname : strPtr ("h" )},
98+ {PortId : "port_tcp" , Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_TCP , PortNumber : 51234 , ServerPort : 22 , Hostname : strPtr ("h" )},
9799 },
98100 }
99101
100102 entry := util .ResolveNodeSSHEntry ("user_1" , node )
101- if entry != nil {
102- t .Errorf ("expected nil for no SSH port, got %+v" , entry )
103+ if entry == nil {
104+ t .Fatal ("expected entry for TCP port with access" )
105+ }
106+ if entry .Port != 51234 {
107+ t .Errorf ("expected port 51234, got %d" , entry .Port )
103108 }
104109}
105110
106111func TestResolveNodeSSHEntry_SkipsEmptyHostname (t * testing.T ) {
107112 node := & nodev1.ExternalNode {
108113 Name : "box" ,
109114 SshAccess : []* nodev1.SSHAccess {
110- {UserId : "user_1" , LinuxUser : "ubuntu" },
115+ {UserId : "user_1" , LinuxUser : "ubuntu" , PortId : "port_1" },
111116 },
112117 Ports : []* nodev1.Port {
113- {Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_SSH , ServerPort : 22 },
118+ {PortId : "port_1" , Protocol : nodev1 .PortProtocol_PORT_PROTOCOL_TCP , ServerPort : 22 },
114119 },
115120 }
116121
@@ -120,33 +125,50 @@ func TestResolveNodeSSHEntry_SkipsEmptyHostname(t *testing.T) {
120125 }
121126}
122127
128+ func TestResolveNodeSSHEntry_SkipsWhenPortIDMissing (t * testing.T ) {
129+ node := & nodev1.ExternalNode {
130+ Name : "box" ,
131+ SshAccess : []* nodev1.SSHAccess {
132+ {UserId : "user_1" , LinuxUser : "ubuntu" },
133+ },
134+ Ports : []* nodev1.Port {
135+ {PortId : "port_a" , PortNumber : 41000 , ServerPort : 22 , Hostname : strPtr ("10.0.0.1" )},
136+ },
137+ }
138+
139+ entry := util .ResolveNodeSSHEntry ("user_1" , node )
140+ if entry != nil {
141+ t .Errorf ("expected nil without PortId on access, got %+v" , entry )
142+ }
143+ }
144+
123145func TestResolveNodeSSHEntry_MultipleNodes (t * testing.T ) {
124146 nodes := []* nodev1.ExternalNode {
125147 {
126148 Name : "Node A" ,
127149 SshAccess : []* nodev1.SSHAccess {
128- {UserId : "user_1" , LinuxUser : "ubuntu" },
150+ {UserId : "user_1" , LinuxUser : "ubuntu" , PortId : "port_a" },
129151 },
130152 Ports : []* nodev1.Port {
131- {Protocol : nodev1 . PortProtocol_PORT_PROTOCOL_SSH , ServerPort : 41000 , Hostname : strPtr ("10.0.0.1" )},
153+ {PortId : "port_a" , PortNumber : 41000 , ServerPort : 22 , Hostname : strPtr ("10.0.0.1" )},
132154 },
133155 },
134156 {
135157 Name : "Node B" ,
136158 SshAccess : []* nodev1.SSHAccess {
137- {UserId : "other_user" , LinuxUser : "root" },
159+ {UserId : "other_user" , LinuxUser : "root" , PortId : "port_b" },
138160 },
139161 Ports : []* nodev1.Port {
140- {Protocol : nodev1 . PortProtocol_PORT_PROTOCOL_SSH , ServerPort : 42000 , Hostname : strPtr ("10.0.0.2" )},
162+ {PortId : "port_b" , PortNumber : 42000 , ServerPort : 22 , Hostname : strPtr ("10.0.0.2" )},
141163 },
142164 },
143165 {
144166 Name : "Node C" ,
145167 SshAccess : []* nodev1.SSHAccess {
146- {UserId : "user_1" , LinuxUser : "admin" },
168+ {UserId : "user_1" , LinuxUser : "admin" , PortId : "port_c" },
147169 },
148170 Ports : []* nodev1.Port {
149- {Protocol : nodev1 . PortProtocol_PORT_PROTOCOL_SSH , ServerPort : 43000 , Hostname : strPtr ("10.0.0.3" )},
171+ {PortId : "port_c" , PortNumber : 43000 , ServerPort : 22 , Hostname : strPtr ("10.0.0.3" )},
150172 },
151173 },
152174 }
0 commit comments