Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit674f60f

Browse files
authored
fix(cli): replace $SESSION_TOKEN placeholder for external apps (#17048)
Fixes an oversight in#17032The FE has logic to replace the string `$SESSION_TOKEN` with anewly-minted session token.This adds corresponding logic to the `coder open app` command.
1 parent77fe10e commit674f60f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

‎cli/open.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ func (r *RootCmd) openApp() *serpent.Command {
301301
pathAppURL:=strings.TrimPrefix(region.PathAppURL,baseURL.String())
302302
appURL:=buildAppLinkURL(baseURL,ws,agt,foundApp,region.WildcardHostname,pathAppURL)
303303

304+
iffoundApp.External {
305+
appURL=replacePlaceholderExternalSessionTokenString(client,appURL)
306+
}
307+
304308
// Check if we're inside a workspace. Generally, we know
305309
// that if we're inside a workspace, `open` can't be used.
306310
insideAWorkspace:=inv.Environ.Get("CODER")=="true"
@@ -314,7 +318,7 @@ func (r *RootCmd) openApp() *serpent.Command {
314318
if!testOpenError {
315319
err=open.Run(appURL)
316320
}else {
317-
err=xerrors.New("test.open-error")
321+
err=xerrors.New("test.open-error: "+appURL)
318322
}
319323
returnerr
320324
},
@@ -511,3 +515,15 @@ func buildAppLinkURL(baseURL *url.URL, workspace codersdk.Workspace, agent coder
511515
}
512516
returnu.String()
513517
}
518+
519+
// replacePlaceholderExternalSessionTokenString replaces any $SESSION_TOKEN
520+
// strings in the URL with the actual session token.
521+
// This is consistent behavior with the frontend. See: site/src/modules/resources/AppLink/AppLink.tsx
522+
funcreplacePlaceholderExternalSessionTokenString(client*codersdk.Client,appURLstring)string {
523+
if!strings.Contains(appURL,"$SESSION_TOKEN") {
524+
returnappURL
525+
}
526+
527+
// We will just re-use the existing session token we're already using.
528+
returnstrings.ReplaceAll(appURL,"$SESSION_TOKEN",client.SessionToken())
529+
}

‎cli/open_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,29 @@ func TestOpenApp(t *testing.T) {
381381
w.RequireError()
382382
w.RequireContains("region not found")
383383
})
384+
385+
t.Run("ExternalAppSessionToken",func(t*testing.T) {
386+
t.Parallel()
387+
388+
client,ws,_:=setupWorkspaceForAgent(t,func(agents []*proto.Agent) []*proto.Agent {
389+
agents[0].Apps= []*proto.App{
390+
{
391+
Slug:"app1",
392+
Url:"https://example.com/app1?token=$SESSION_TOKEN",
393+
External:true,
394+
},
395+
}
396+
returnagents
397+
})
398+
inv,root:=clitest.New(t,"open","app",ws.Name,"app1","--test.open-error")
399+
clitest.SetupConfig(t,client,root)
400+
pty:=ptytest.New(t)
401+
inv.Stdin=pty.Input()
402+
inv.Stdout=pty.Output()
403+
404+
w:=clitest.StartWithWaiter(t,inv)
405+
w.RequireError()
406+
w.RequireContains("test.open-error")
407+
w.RequireContains(client.SessionToken())
408+
})
384409
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp