@@ -15,6 +15,56 @@ function runTestExtensionTests() {
1515 const normalizedAddress = address . replace ( / \/ + $ / , "" )
1616 await expect ( codeServerPage . page . getByText ( `Info: proxyUri: ${ normalizedAddress } /proxy/{{port}}/` ) ) . toBeVisible ( )
1717 } )
18+
19+ runExternalUriTests ( )
20+ }
21+
22+ function runExternalUriTests ( proxyEndpointTemplate ?: string ) {
23+ const cases = [
24+ {
25+ name : "path" ,
26+ input : "http://127.0.0.1:1234/my/path" ,
27+ suffix : "/my/path" ,
28+ } ,
29+ {
30+ name : "query and fragment" ,
31+ input : "http://localhost:1234/my/path?token=abc&mode=preview#section" ,
32+ suffix : "/my/path?token%3Dabc%26mode%3Dpreview#section" ,
33+ } ,
34+ {
35+ name : "encoded components" ,
36+ input : "http://0.0.0.0:1234/my%20path/%23file?token=a%20b#my%20section" ,
37+ suffix : "/my%20path/%23file?token%3Da%20b#my%20section" ,
38+ } ,
39+ {
40+ name : "root path" ,
41+ input : "http://127.0.0.1:1234/" ,
42+ suffix : "/" ,
43+ } ,
44+ ]
45+
46+ for ( const { name, input, suffix } of cases ) {
47+ test ( `asExternalUri should preserve ${ name } ` , async ( { codeServerPage } ) => {
48+ const address = await getMaybeProxiedCodeServer ( codeServerPage )
49+ const normalizedAddress = address . replace ( / \/ + $ / , "" )
50+ const proxyBase = proxyEndpointTemplate
51+ ? new URL ( proxyEndpointTemplate . replace ( "{{port}}" , "1234" ) , `${ normalizedAddress } /` ) . toString ( )
52+ : `${ normalizedAddress } /proxy/1234/`
53+
54+ await codeServerPage . waitForTestExtensionLoaded ( )
55+ await codeServerPage . executeCommandViaMenus ( "code-server: asExternalUri test" )
56+
57+ const inputBox = codeServerPage . page . locator ( ".quick-input-widget input" )
58+ await inputBox . fill ( input )
59+ await inputBox . press ( "Enter" )
60+
61+ // The test extension displays URI.toString(), which also encodes query delimiters.
62+ const output = `${ proxyBase . replace ( / \/ $ / , "" ) } ${ suffix } `
63+ await expect (
64+ codeServerPage . page . getByText ( `Info: input: ${ input } output: ${ output } ` , { exact : true } ) ,
65+ ) . toBeVisible ( )
66+ } )
67+ }
1868}
1969
2070const flags = [ "--disable-workspace-trust" , "--extensions-dir" , path . join ( __dirname , "./extensions" ) ]
@@ -23,6 +73,17 @@ describe("Extensions", flags, {}, () => {
2373 runTestExtensionTests ( )
2474} )
2575
76+ for ( const proxyEndpointTemplate of [ "./proxy/{{port}}" , "https://{{port}}-workspace.example.com" ] ) {
77+ describe (
78+ `Extensions with VSCODE_PROXY_URI=${ proxyEndpointTemplate } ` ,
79+ flags ,
80+ { VSCODE_PROXY_URI : proxyEndpointTemplate } ,
81+ ( ) => {
82+ runExternalUriTests ( proxyEndpointTemplate )
83+ } ,
84+ )
85+ }
86+
2687if ( process . env . USE_PROXY !== "1" ) {
2788 describe ( "Extensions with --cert" , [ ...flags , "--cert" ] , { } , ( ) => {
2889 runTestExtensionTests ( )
0 commit comments