Forward Remote punctuation keys by default
This commit is contained in:
1 parent
8f51511801
commit
a3c4e888c7
8 files changed
+139
-9
No files matched your search
@@ -312,7 +312,6 @@ func (command *connectionCommand) select_relay(ctx context.Context, raw json.Raw
|
||||
}
|
||||
workflow.key = key
|
||||
workflow.remember = value.Values["remember"].Checked
|
||||
workflow.profile = "portable"
|
||||
if value.Activated == "connect" {
|
||||
return workflow.submit(ctx, sdk.Submission{Activated: "connect"})
|
||||
}
|
||||
|
||||
@@ -59,6 +59,49 @@ func TestRemoteCommandCollectsCredentialsBeforeApproval(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteCommandIncludesPunctuationByDefault(t *testing.T) {
|
||||
for _, role := range []string{"controller", "controlled"} {
|
||||
t.Run(role, func(t *testing.T) {
|
||||
c, _ := fixtureCoordinator(t, nil)
|
||||
store, _, saved := settingsFixture(t)
|
||||
command := &connectionCommand{coordinator: c, store: store, selected: saved}
|
||||
raw, _ := json.Marshal(sdk.Submission{Activated: "options", Values: map[string]sdk.Value{
|
||||
"host": {Text: "relay.invalid"}, "role": {Selected: role},
|
||||
}})
|
||||
result, err := command.select_relay(t.Context(), raw)
|
||||
if err != nil || command.workflow == nil {
|
||||
t.Fatal("options did not open", err)
|
||||
}
|
||||
w := command.workflow
|
||||
t.Cleanup(func() { w.close(); awaitDone(t, w.done) })
|
||||
assertProfile := func(form sdk.Interaction, want string) {
|
||||
t.Helper()
|
||||
for _, element := range form.Form.Elements {
|
||||
if element.ID == "key-profile" && len(element.Items) == 2 && element.Items[0].ID == want {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("keyboard mapping did not select %s", want)
|
||||
}
|
||||
assertProfile(result.(sdk.Interaction), "us")
|
||||
mapping := keyboardFixture(t, w.profile)
|
||||
for _, name := range []string{"semicolon", "equal", "comma", "minus", "period", "slash", "grave", "bracketleft", "backslash", "bracketright", "apostrophe"} {
|
||||
if _, err := mapping.toWire(name, true); err != nil {
|
||||
t.Fatalf("default connection dropped %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
// An empty key keeps setup local while testing explicit profile choice.
|
||||
limited, err := w.submit(t.Context(), sdk.Submission{Activated: "connect", Values: map[string]sdk.Value{
|
||||
"key-profile": {Selected: "portable"},
|
||||
}})
|
||||
if err != nil || w.profile != "portable" {
|
||||
t.Fatal("explicit portable selection was lost", err)
|
||||
}
|
||||
assertProfile(limited, "portable")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteCommandRejectsInvalidSelectionAndDropsEndpointPin(t *testing.T) {
|
||||
c, _ := fixtureCoordinator(t, nil)
|
||||
store, _, saved := settingsFixture(t)
|
||||
|
||||
@@ -75,7 +75,7 @@ func new_connection_workflow(ctx context.Context, owner *coordinator, action sdk
|
||||
}
|
||||
lifetime, cancel := context.WithCancel(owner.ctx)
|
||||
w := &connectionWorkflow{ctx: lifetime, cancel: cancel, done: make(chan struct{}), setupCtx: setupCtx,
|
||||
owner: owner, action: approval, target: target, store: store, mode: "credentials", role: approval.Role}
|
||||
owner: owner, action: approval, target: target, store: store, mode: "credentials", role: approval.Role, profile: defaultKeyboardProfile}
|
||||
stopParent := context.AfterFunc(ctx, cancel)
|
||||
go func() {
|
||||
defer close(w.done)
|
||||
@@ -152,8 +152,8 @@ func (w *connectionWorkflow) form_locked() sdk.Interaction {
|
||||
}
|
||||
elements = append(elements, sdk.Element{ID: "forget-recent", Label: "Forget recent connections and their keys", Kind: sdk.Button})
|
||||
}
|
||||
profiles := []sdk.ListItem{{ID: "portable", Label: "Letters, numbers and navigation"}, {ID: "us", Label: "Include US punctuation"}}
|
||||
if w.profile == "us" {
|
||||
profiles := []sdk.ListItem{{ID: "us", Label: "Include US punctuation"}, {ID: "portable", Label: "Letters, numbers and navigation"}}
|
||||
if w.profile == "portable" {
|
||||
profiles[0], profiles[1] = profiles[1], profiles[0]
|
||||
}
|
||||
elements = append(elements, sdk.Element{ID: "key-profile", Label: "Keyboard mapping", Kind: sdk.List, Items: profiles}, sdk.Element{ID: "cancel", Label: "Cancel", Kind: sdk.Button})
|
||||
@@ -490,7 +490,7 @@ func new_setup_workflow(owner *coordinator, target endpoint, store *settingsStor
|
||||
return nil, errLease
|
||||
}
|
||||
lifetime, cancel := context.WithCancel(owner.ctx)
|
||||
w := &connectionWorkflow{ctx: lifetime, cancel: cancel, done: make(chan struct{}), setupCtx: lifetime, owner: owner, target: target, store: store, role: role, mode: "credentials", needsApproval: true}
|
||||
w := &connectionWorkflow{ctx: lifetime, cancel: cancel, done: make(chan struct{}), setupCtx: lifetime, owner: owner, target: target, store: store, role: role, mode: "credentials", profile: defaultKeyboardProfile, needsApproval: true}
|
||||
if target.pin != nil {
|
||||
// A setup target's pin comes only from remembered trust.
|
||||
w.savedPin = hex.EncodeToString(target.pin.sha256[:])
|
||||
|
||||
@@ -15,6 +15,10 @@ type wireKey struct {
|
||||
|
||||
var errKeyboard = errors.New("unsupported remote keyboard mapping")
|
||||
|
||||
// Include every supported key by default, including the US OEM punctuation
|
||||
// identities. The portable profile remains an explicit limited alternative.
|
||||
const defaultKeyboardProfile = "us"
|
||||
|
||||
// mediaKeys are VK 0xa6 (browser back) through 0xb7 (launch app 2).
|
||||
var mediaKeys = []string{
|
||||
"XF86Back", "XF86Forward", "XF86Reload", "XF86Stop", "XF86Search", "XF86Favorites",
|
||||
|
||||
@@ -256,3 +256,74 @@ func TestCoordinatorFocusRequiresCaptureGrant(t *testing.T) {
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoordinatorDefaultProfileForwardsPunctuationAndShift(t *testing.T) {
|
||||
c, f := fixtureCoordinator(t, nil)
|
||||
c.set_keyboard(defaultKeyboardProfile)
|
||||
action := approveGrants(t, c, f, 1, "controller", "remote-present", "keyboard-capture")
|
||||
received := make(chan string, 32)
|
||||
if err := c.connect(action, controllerRelay(t, received), "synthetic-fixture"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nextCall(t, f, "remote.open")
|
||||
awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "ready" })
|
||||
// Comma, period, then Shift+comma and Shift+period, including a held-key
|
||||
// repeat. Shift is forwarded separately so the peer receives < and >.
|
||||
keys := []sdk.RemoteCapturedKey{
|
||||
{Code: 59, Name: "comma", Pressed: true}, {Code: 59},
|
||||
{Code: 60, Name: "period", Pressed: true}, {Code: 60},
|
||||
{Code: 50, Name: "Shift_L", Pressed: true},
|
||||
{Code: 59, Name: "comma", Pressed: true}, {Code: 59},
|
||||
{Code: 60, Name: "period", Pressed: true},
|
||||
{Code: 60, Pressed: true, Repeat: true}, {Code: 60}, {Code: 50},
|
||||
}
|
||||
for index, key := range keys {
|
||||
f.events <- sdk.SessionEvent{Sequence: uint64(2 + index), Kind: "remote.input", Lease: strings.Repeat("b", 32), Epoch: 1, Input: &key}
|
||||
}
|
||||
wantVK := []int{0xbc, 0xbc, 0xbe, 0xbe, 0xa0, 0xbc, 0xbc, 0xbe, 0xbe, 0xbe, 0xa0}
|
||||
for index, vk := range wantVK {
|
||||
select {
|
||||
case frame := <-received:
|
||||
want, err := encodeMessage("key", keyTransition{VK: vk, Pressed: keys[index].Pressed})
|
||||
if err != nil || frame != strings.TrimSpace(string(want)) {
|
||||
t.Fatalf("frame %d = %s, want %s: %v", index, frame, want, err)
|
||||
}
|
||||
case <-time.After(4 * time.Second):
|
||||
t.Fatalf("missing punctuation frame %d", index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoordinatorDefaultProfileReceivesPunctuationAndShift(t *testing.T) {
|
||||
c, f := fixtureCoordinator(t, nil)
|
||||
c.set_keyboard(defaultKeyboardProfile)
|
||||
action := approveGrants(t, c, f, 1, "controlled", "output-observe", "keyboard-inject")
|
||||
vks := []int{0xbc, 0xbc, 0xbe, 0xbe, 0xa0, 0xbc, 0xbc, 0xbe, 0xbe, 0xa0}
|
||||
names := []string{"comma", "comma", "period", "period", "Shift_L", "comma", "comma", "period", "period", "Shift_L"}
|
||||
pressed := []bool{true, false, true, false, true, true, false, true, false, false}
|
||||
frames := make([]string, len(vks))
|
||||
for index, vk := range vks {
|
||||
frames[index] = keyFrame(vk, pressed[index])
|
||||
}
|
||||
if err := c.connect(action, keyRelay(t, frames), "synthetic-fixture"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nextCall(t, f, "remote.open")
|
||||
for index, name := range names {
|
||||
var call readerCall
|
||||
for {
|
||||
select {
|
||||
case call = <-f.calls:
|
||||
case <-time.After(4 * time.Second):
|
||||
t.Fatalf("missing punctuation call %d", index)
|
||||
}
|
||||
if call.method != "remote.heartbeat" {
|
||||
break
|
||||
}
|
||||
}
|
||||
request, ok := call.params.(sdk.RemoteKeyRequest)
|
||||
if call.method != "remote.key" || !ok || request.Key.Name != name || request.Key.Pressed != pressed[index] {
|
||||
t.Fatalf("call %d = %s %+v, want %s pressed %t", index, call.method, call.params, name, pressed[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user