@@ -148,3 +148,88 @@ describe.each([
148148 await waitFor ( ( ) => expect ( writeText ) . toHaveBeenCalledWith ( command ) ) ;
149149 } ) ;
150150} ) ;
151+
152+ describe ( "legacy hostname prefix" , ( ) => {
153+ it . each ( [
154+ {
155+ name : "default prefix collision with a custom suffix" ,
156+ workspaceName : "coder" ,
157+ hostnamePrefix : "coder." ,
158+ command : "ssh a-workspace-agent.coder.TestUser.dev" ,
159+ } ,
160+ {
161+ name : "custom prefix collision" ,
162+ workspaceName : "work-lab" ,
163+ hostnamePrefix : "work-" ,
164+ command : "ssh a-workspace-agent.work-lab.TestUser.dev" ,
165+ } ,
166+ {
167+ name : "case-insensitive prefix collision" ,
168+ workspaceName : "coder" ,
169+ hostnamePrefix : "CoDeR." ,
170+ command : "ssh a-workspace-agent.coder.TestUser.dev" ,
171+ } ,
172+ {
173+ name : "case-insensitive hostname collision" ,
174+ workspaceName : "CoDeR" ,
175+ hostnamePrefix : "coder." ,
176+ command : "ssh a-workspace-agent.CoDeR.TestUser.dev" ,
177+ } ,
178+ {
179+ name : "prefix spanning the workspace and suffix" ,
180+ workspaceName : "coder" ,
181+ hostnamePrefix : "coder.d" ,
182+ command : "ssh a-workspace-agent.coder.TestUser.dev" ,
183+ } ,
184+ {
185+ name : "noncolliding prefix" ,
186+ workspaceName : "mycoder" ,
187+ hostnamePrefix : "coder." ,
188+ command : "ssh mycoder.dev" ,
189+ } ,
190+ {
191+ name : "disabled prefix" ,
192+ workspaceName : "coder" ,
193+ hostnamePrefix : "" ,
194+ command : "ssh coder.dev" ,
195+ } ,
196+ ] ) (
197+ "copies the safe command for $name" ,
198+ async ( { workspaceName, hostnamePrefix, command } ) => {
199+ const user = userEvent . setup ( ) ;
200+ const writeText = vi
201+ . spyOn ( navigator . clipboard , "writeText" )
202+ . mockResolvedValue ( ) ;
203+ const mockDeploymentSSH = {
204+ ...MockDeploymentSSH ,
205+ hostname_prefix : hostnamePrefix ,
206+ hostname_suffix : "dev" ,
207+ } ;
208+ vi . spyOn ( API , "getDeploymentSSHConfig" ) . mockResolvedValue (
209+ mockDeploymentSSH ,
210+ ) ;
211+ const mockWorkspace : Workspace = {
212+ ...MockWorkspace ,
213+ name : workspaceName ,
214+ latest_build : {
215+ ...MockWorkspace . latest_build ,
216+ workspace_name : workspaceName ,
217+ } ,
218+ } ;
219+ renderWithAuth (
220+ < AgentSSHButton
221+ workspace = { mockWorkspace }
222+ agentName = { MockWorkspaceAgent . name }
223+ /> ,
224+ ) ;
225+ await user . click (
226+ await screen . findByRole ( "button" , { name : "Connect via SSH" } ) ,
227+ ) ;
228+ const copyButtons = await screen . findAllByRole ( "button" , {
229+ name : "Copy code" ,
230+ } ) ;
231+ await user . click ( copyButtons [ copyButtons . length - 1 ] ) ;
232+ await waitFor ( ( ) => expect ( writeText ) . toHaveBeenCalledWith ( command ) ) ;
233+ } ,
234+ ) ;
235+ } ) ;
0 commit comments