File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -545,4 +545,45 @@ describe('ServerSelector', () => {
545
545
screen . getByRole ( 'button' , { name : / S e r v e r s & T o o l s \( 2 \/ 2 \) / i } ) ,
546
546
) . toBeInTheDocument ( )
547
547
} )
548
+
549
+ it ( 'redirects to base URL with connect path when clicking disconnected server' , async ( ) => {
550
+ // Mock window.location.href assignment
551
+ const originalLocation = window . location
552
+ delete ( window as any ) . location
553
+ window . location = {
554
+ href : 'https://current-app.example.com/some/path' ,
555
+ } as any
556
+
557
+ const servers : Servers = {
558
+ 'test-server' : {
559
+ ...baseServer ,
560
+ status : 'disconnected' ,
561
+ connected : false ,
562
+ url : 'https://db-server.example.com/some/path' ,
563
+ needs_oauth : true ,
564
+ } ,
565
+ }
566
+
567
+ await act ( ( ) => {
568
+ renderWithQueryClient (
569
+ < ServerSelector
570
+ servers = { servers }
571
+ onServersChange = { mockOnServersChange }
572
+ selectedServers = { [ ] }
573
+ onServerToggle = { mockOnServerToggle }
574
+ toolToggles = { [ ] }
575
+ /> ,
576
+ )
577
+ } )
578
+
579
+ await userEvent . click ( screen . getByText ( 'Test Server' ) )
580
+
581
+ // Should redirect to base URL + connect path, not full URL + connect path
582
+ expect ( window . location . href ) . toBe (
583
+ 'https://db-server.example.com/.pomerium/mcp/connect?redirect_url=https%3A%2F%2Fcurrent-app.example.com%2Fsome%2Fpath' ,
584
+ )
585
+
586
+ // Restore original location
587
+ ; ( window as any ) . location = originalLocation
588
+ } )
548
589
} )
Original file line number Diff line number Diff line change @@ -135,8 +135,9 @@ const ServerSelectionContent = ({
135
135
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
136
136
if ( ! server ) return
137
137
const currentUrl = window . location . href
138
- const connectUrl = `${ server . url } ${ POMERIUM_CONNECT_PATH } ?redirect_url=${ encodeURIComponent ( currentUrl ) } `
139
- window . location . href = connectUrl
138
+ const connectUrl = new URL ( POMERIUM_CONNECT_PATH , server . url )
139
+ connectUrl . searchParams . set ( 'redirect_url' , currentUrl )
140
+ window . location . href = connectUrl . toString ( )
140
141
}
141
142
142
143
const disconnectMutation = useDisconnectServer ( servers , onServersChange )
You can’t perform that action at this time.
0 commit comments