35 lines
1.4 KiB
Go
35 lines
1.4 KiB
Go
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package tentaclewire
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestRemoteConsentInteractionValidation(t *testing.T) {
|
|
valid := Interaction{Remote: &RemoteRequest{Role: "controller", Grants: []string{"remote-present"}}, Next: "approved"}
|
|
data, _ := json.Marshal(valid)
|
|
if _, err := DecodeInteraction(data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, raw := range []string{
|
|
`{"remote":null,"next":"approved"}`,
|
|
`{"remote":{"role":"controller","grants":["remote-present"]}}`,
|
|
`{"remote":{"role":"controller","grants":["keyboard-inject"]},"next":"approved"}`,
|
|
`{"remote":{"role":"controlled","grants":[]},"next":"approved"}`,
|
|
`{"remote":{"role":"controlled","grants":["output-observe","output-observe"]},"next":"approved"}`,
|
|
`{"remote":{"role":"controlled","grants":["output-observe"],"session":"other"},"next":"approved"}`,
|
|
} {
|
|
if _, err := DecodeInteraction([]byte(raw)); err == nil {
|
|
t.Fatal("invalid remote interaction accepted", raw)
|
|
}
|
|
}
|
|
for _, field := range []string{`"clipboard":"text"`, `"source":"clipboard"`, `"done":true`, `"poll":"poll"`, `"reader":{"snapshot":true}`} {
|
|
raw := `{"remote":{"role":"controller","grants":["remote-present"]},"next":"approved",` + field + `}`
|
|
if _, err := DecodeInteraction([]byte(raw)); err == nil {
|
|
t.Fatal("remote consent mixed with another effect", field)
|
|
}
|
|
}
|
|
}
|