mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: app sharing (now open source!) (#4378)
This commit is contained in:
@@ -2,6 +2,7 @@ package coderd_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -16,6 +17,14 @@ import (
|
||||
"github.com/coder/coder/enterprise/coderd/coderdenttest"
|
||||
"github.com/coder/coder/provisioner/echo"
|
||||
"github.com/coder/coder/provisionersdk/proto"
|
||||
"github.com/coder/coder/testutil"
|
||||
)
|
||||
|
||||
// App names for each app sharing level.
|
||||
const (
|
||||
testAppNameOwner = "test-app-owner"
|
||||
testAppNameAuthenticated = "test-app-authenticated"
|
||||
testAppNamePublic = "test-app-public"
|
||||
)
|
||||
|
||||
func TestBlockNonBrowser(t *testing.T) {
|
||||
@@ -32,8 +41,8 @@ func TestBlockNonBrowser(t *testing.T) {
|
||||
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
BrowserOnly: true,
|
||||
})
|
||||
id := setupWorkspaceAgent(t, client, user)
|
||||
_, err := client.DialWorkspaceAgentTailnet(context.Background(), slog.Logger{}, id)
|
||||
_, agent := setupWorkspaceAgent(t, client, user, 0)
|
||||
_, err := client.DialWorkspaceAgentTailnet(context.Background(), slog.Logger{}, agent.ID)
|
||||
var apiErr *codersdk.Error
|
||||
require.ErrorAs(t, err, &apiErr)
|
||||
require.Equal(t, http.StatusConflict, apiErr.StatusCode())
|
||||
@@ -49,14 +58,14 @@ func TestBlockNonBrowser(t *testing.T) {
|
||||
coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{
|
||||
BrowserOnly: false,
|
||||
})
|
||||
id := setupWorkspaceAgent(t, client, user)
|
||||
conn, err := client.DialWorkspaceAgentTailnet(context.Background(), slog.Logger{}, id)
|
||||
_, agent := setupWorkspaceAgent(t, client, user, 0)
|
||||
conn, err := client.DialWorkspaceAgentTailnet(context.Background(), slog.Logger{}, agent.ID)
|
||||
require.NoError(t, err)
|
||||
_ = conn.Close()
|
||||
})
|
||||
}
|
||||
|
||||
func setupWorkspaceAgent(t *testing.T, client *codersdk.Client, user codersdk.CreateFirstUserResponse) uuid.UUID {
|
||||
func setupWorkspaceAgent(t *testing.T, client *codersdk.Client, user codersdk.CreateFirstUserResponse, appPort uint16) (codersdk.Workspace, codersdk.WorkspaceAgent) {
|
||||
authToken := uuid.NewString()
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
||||
Parse: echo.ParseComplete,
|
||||
@@ -72,6 +81,23 @@ func setupWorkspaceAgent(t *testing.T, client *codersdk.Client, user codersdk.Cr
|
||||
Auth: &proto.Agent_Token{
|
||||
Token: authToken,
|
||||
},
|
||||
Apps: []*proto.App{
|
||||
{
|
||||
Name: testAppNameOwner,
|
||||
SharingLevel: proto.AppSharingLevel_OWNER,
|
||||
Url: fmt.Sprintf("http://localhost:%d", appPort),
|
||||
},
|
||||
{
|
||||
Name: testAppNameAuthenticated,
|
||||
SharingLevel: proto.AppSharingLevel_AUTHENTICATED,
|
||||
Url: fmt.Sprintf("http://localhost:%d", appPort),
|
||||
},
|
||||
{
|
||||
Name: testAppNamePublic,
|
||||
SharingLevel: proto.AppSharingLevel_PUBLIC,
|
||||
Url: fmt.Sprintf("http://localhost:%d", appPort),
|
||||
},
|
||||
},
|
||||
}},
|
||||
}},
|
||||
},
|
||||
@@ -89,9 +115,16 @@ func setupWorkspaceAgent(t *testing.T, client *codersdk.Client, user codersdk.Cr
|
||||
CoordinatorDialer: agentClient.ListenWorkspaceAgentTailnet,
|
||||
Logger: slogtest.Make(t, nil).Named("agent"),
|
||||
})
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
_ = agentCloser.Close()
|
||||
}()
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
|
||||
return resources[0].Agents[0].ID
|
||||
agnt, err := client.WorkspaceAgent(ctx, resources[0].Agents[0].ID)
|
||||
require.NoError(t, err)
|
||||
|
||||
return workspace, agnt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user