remote_attach_validation_test.go RawHistoryFolder
1package client
2
3import (
4 "context"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8
9 "github.com/bnema/vev/internal/domain"
10 "github.com/bnema/vev/internal/ports"
11 portsmocks "github.com/bnema/vev/internal/ports/mocks"
12)
13
14func TestMalformedAttachRequestsNeverDial(t *testing.T) {
15 tests := []struct {
16 name string
17 request AttachRequest
18 }{
19 {name: "missing session name", request: AttachRequest{Intent: ports.IntentAttach}},
20 {name: "unsafe session name", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "bad name"}},
21 {name: "daemon-owned without remote", request: AttachRequest{Intent: ports.IntentAttach, SessionName: "main", EnvironmentPolicy: ports.EnvironmentPolicyDaemonOwned}},
22 {name: "ephemeral with navigation capability", request: AttachRequest{Intent: ports.IntentEphemeral, NavigationCapabilities: ports.NavigationCapabilityHomePicker}},
23 }
24 for _, tt := range tests {
25 t.Run(tt.name, func(t *testing.T) {
26 // No EXPECT: any Dial call fails the test.
27 dialer := portsmocks.NewMockDialer(t)
28 err := NewRunner(Dependencies{Dialer: dialer}).Run(context.Background(), tt.request)
29 require.Error(t, err)
30 })
31 }
32}
33
34func TestValidateAttachRequestRequiresDaemonOwnedEnvironmentForRemoteTarget(t *testing.T) {
35 var lifecycle domain.SessionLifecycleID
36 lifecycle[0] = 1
37 target := &domain.RemoteSessionTarget{
38 Endpoint: "arch", DisplayOrigin: "arch", LifecycleID: lifecycle,
39 SessionName: "work", LiveTabID: "tab-1",
40 }
41
42 tests := []struct {
43 name string
44 policy ports.EnvironmentPolicy
45 wantOK bool
46 }{
47 {name: "daemon owned", policy: ports.EnvironmentPolicyDaemonOwned, wantOK: true},
48 {name: "client owned", policy: ports.EnvironmentPolicyClientOwned},
49 {name: "unknown", policy: ports.EnvironmentPolicy(99)},
50 }
51 for _, test := range tests {
52 t.Run(test.name, func(t *testing.T) {
53 err := validateAttachRequest(AttachRequest{
54 Intent: ports.IntentAttach, SessionName: target.SessionName,
55 RemoteTarget: target, EnvironmentPolicy: test.policy,
56 })
57 if test.wantOK {
58 require.NoError(t, err)
59 return
60 }
61 require.EqualError(t, err, "vev: remote attach target requires daemon-owned environment")
62 })
63 }
64}