Skip to content

Commit 06d21e2

Browse files
committed
filter more web apps
1 parent f11e168 commit 06d21e2

File tree

2 files changed

+49
-39
lines changed

2 files changed

+49
-39
lines changed

Coder-Desktop/Coder-Desktop/Views/VPN/WorkspaceAppIcon.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ struct WorkspaceApp {
7373
_ original: CoderSDK.WorkspaceApp,
7474
iconBaseURL: URL,
7575
sessionToken: String,
76-
newAppHost: String
7776
) throws(WorkspaceAppError) {
7877
slug = original.slug
7978
displayName = original.display_name
@@ -90,29 +89,21 @@ struct WorkspaceApp {
9089
throw .isCommandApp
9190
}
9291

93-
guard var urlComponents = URLComponents(url: originalUrl, resolvingAgainstBaseURL: false) else {
94-
throw .invalidURL
95-
}
96-
97-
var url: URL
98-
if urlComponents.host == "localhost" {
99-
urlComponents.host = newAppHost
100-
guard let newUrl = urlComponents.url else {
101-
throw .invalidURL
102-
}
103-
url = newUrl
104-
} else {
105-
url = originalUrl
92+
// We don't want to show buttons for any websites, like internal wikies
93+
// or portals. Those *should* have 'external' set, but if they don't:
94+
guard originalUrl.scheme != "https", originalUrl.scheme != "http" else {
95+
throw .isWebApp
10696
}
10797

108-
let newUrlString = url.absoluteString.replacingOccurrences(of: Self.magicTokenString, with: sessionToken)
98+
let newUrlString = originalUrl.absoluteString.replacingOccurrences(
99+
of: Self.magicTokenString,
100+
with: sessionToken
101+
)
109102
guard let newUrl = URL(string: newUrlString) else {
110103
throw .invalidURL
111104
}
112105
url = newUrl
113106

114-
self.url = url
115-
116107
var icon = original.icon
117108
if let originalIcon = original.icon,
118109
var components = URLComponents(url: originalIcon, resolvingAgainstBaseURL: false)
@@ -162,7 +153,7 @@ func agentToApps(
162153
) -> [WorkspaceApp] {
163154
let workspaceApps = agent.apps.compactMap { app in
164155
do throws(WorkspaceAppError) {
165-
return try WorkspaceApp(app, iconBaseURL: baseAccessURL, sessionToken: sessionToken, newAppHost: host)
156+
return try WorkspaceApp(app, iconBaseURL: baseAccessURL, sessionToken: sessionToken)
166157
} catch {
167158
logger.warning("Skipping WorkspaceApp '\(app.slug)' for \(host): \(error.localizedDescription)")
168159
return nil

Coder-Desktop/Coder-DesktopTests/WorkspaceAppTests.swift

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct WorkspaceAppTests {
1515
func testCreateWorkspaceApp_Success() throws {
1616
let sdkApp = CoderSDK.WorkspaceApp(
1717
id: UUID(),
18-
url: URL(string: "https://localhost:3000/app")!,
18+
url: URL(string: "vscode://myworkspace.coder/foo")!,
1919
external: true,
2020
slug: "test-app",
2121
display_name: "Test App",
@@ -28,21 +28,20 @@ struct WorkspaceAppTests {
2828
let workspaceApp = try WorkspaceApp(
2929
sdkApp,
3030
iconBaseURL: baseAccessURL,
31-
sessionToken: sessionToken,
32-
newAppHost: host
31+
sessionToken: sessionToken
3332
)
3433

3534
#expect(workspaceApp.slug == "test-app")
3635
#expect(workspaceApp.displayName == "Test App")
37-
#expect(workspaceApp.url.absoluteString == "https://test-workspace.coder.test:3000/app")
36+
#expect(workspaceApp.url.absoluteString == "vscode://myworkspace.coder/foo")
3837
#expect(workspaceApp.icon?.absoluteString == "https://coder.example.com/icon/test-app.svg")
3938
}
4039

4140
@Test
4241
func testCreateWorkspaceApp_SessionTokenReplacement() throws {
4342
let sdkApp = CoderSDK.WorkspaceApp(
4443
id: UUID(),
45-
url: URL(string: "https://localhost:3000/app?token=$SESSION_TOKEN")!,
44+
url: URL(string: "vscode://myworkspace.coder/foo?token=$SESSION_TOKEN")!,
4645
external: true,
4746
slug: "token-app",
4847
display_name: "Token App",
@@ -55,12 +54,11 @@ struct WorkspaceAppTests {
5554
let workspaceApp = try WorkspaceApp(
5655
sdkApp,
5756
iconBaseURL: baseAccessURL,
58-
sessionToken: sessionToken,
59-
newAppHost: host
57+
sessionToken: sessionToken
6058
)
6159

6260
#expect(
63-
workspaceApp.url.absoluteString == "https://test-workspace.coder.test:3000/app?token=test-session-token"
61+
workspaceApp.url.absoluteString == "vscode://myworkspace.coder/foo?token=test-session-token"
6462
)
6563
}
6664

@@ -82,8 +80,7 @@ struct WorkspaceAppTests {
8280
try WorkspaceApp(
8381
sdkApp,
8482
iconBaseURL: baseAccessURL,
85-
sessionToken: sessionToken,
86-
newAppHost: host
83+
sessionToken: sessionToken
8784
)
8885
}
8986
}
@@ -92,7 +89,7 @@ struct WorkspaceAppTests {
9289
func testCreateWorkspaceApp_CommandApp() throws {
9390
let sdkApp = CoderSDK.WorkspaceApp(
9491
id: UUID(),
95-
url: URL(string: "https://localhost:3000/app")!,
92+
url: URL(string: "vscode://myworkspace.coder/foo")!,
9693
external: true,
9794
slug: "command-app",
9895
display_name: "Command App",
@@ -106,8 +103,7 @@ struct WorkspaceAppTests {
106103
try WorkspaceApp(
107104
sdkApp,
108105
iconBaseURL: baseAccessURL,
109-
sessionToken: sessionToken,
110-
newAppHost: host
106+
sessionToken: sessionToken
111107
)
112108
}
113109
}
@@ -149,36 +145,59 @@ struct WorkspaceAppTests {
149145
)
150146
}
151147

148+
@Test
149+
func testCreateWorkspaceApp_WebAppFilter() throws {
150+
let sdkApp = CoderSDK.WorkspaceApp(
151+
id: UUID(),
152+
url: URL(string: "https://myworkspace.coder/foo")!,
153+
external: false,
154+
slug: "web-app",
155+
display_name: "Web App",
156+
command: nil,
157+
icon: URL(string: "/icon/web-app.svg")!,
158+
subdomain: false,
159+
subdomain_name: nil
160+
)
161+
162+
#expect(throws: WorkspaceAppError.isWebApp) {
163+
try WorkspaceApp(
164+
sdkApp,
165+
iconBaseURL: baseAccessURL,
166+
sessionToken: sessionToken
167+
)
168+
}
169+
}
170+
152171
@Test
153172
func testAgentToApps_MultipleApps() throws {
154173
let sdkApp1 = CoderSDK.WorkspaceApp(
155174
id: UUID(),
156-
url: URL(string: "https://localhost:3000/app1")!,
175+
url: URL(string: "vscode://myworkspace.coder/foo1")!,
157176
external: true,
158177
slug: "app1",
159178
display_name: "App 1",
160179
command: nil,
161-
icon: URL(string: "/icon/app1.svg")!,
180+
icon: URL(string: "/icon/foo1.svg")!,
162181
subdomain: false,
163182
subdomain_name: nil
164183
)
165184

166185
let sdkApp2 = CoderSDK.WorkspaceApp(
167186
id: UUID(),
168-
url: URL(string: "https://localhost:3000/app2")!,
187+
url: URL(string: "jetbrains://myworkspace.coder/foo2")!,
169188
external: true,
170189
slug: "app2",
171190
display_name: "App 2",
172191
command: nil,
173-
icon: URL(string: "/icon/app2.svg")!,
192+
icon: URL(string: "/icon/foo2.svg")!,
174193
subdomain: false,
175194
subdomain_name: nil
176195
)
177196

178197
// Command app; skipped
179198
let sdkApp3 = CoderSDK.WorkspaceApp(
180199
id: UUID(),
181-
url: URL(string: "https://localhost:3000/app3")!,
200+
url: URL(string: "vscode://myworkspace.coder/foo3")!,
182201
external: true,
183202
slug: "app3",
184203
display_name: "App 3",
@@ -191,12 +210,12 @@ struct WorkspaceAppTests {
191210
// Web app skipped
192211
let sdkApp4 = CoderSDK.WorkspaceApp(
193212
id: UUID(),
194-
url: URL(string: "https://localhost:3000/app4")!,
195-
external: false,
213+
url: URL(string: "https://myworkspace.coder/foo4")!,
214+
external: true,
196215
slug: "app4",
197216
display_name: "App 4",
198217
command: nil,
199-
icon: URL(string: "/icon/app4.svg")!,
218+
icon: URL(string: "/icon/foo4.svg")!,
200219
subdomain: false, subdomain_name: nil
201220
)
202221

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy