feat: execute durable client commands through supervisor
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package windowstray
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTrayFrameRoundTripAndPayloadBounds_HP_WINTRAY_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
frame := Frame{Action: ActionStatus, Payload: []byte("connected=true dirty=false")}
|
||||
encoded, err := Encode(frame)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
decoded, err := Decode(encoded)
|
||||
if err != nil || decoded.Action != frame.Action || !bytes.Equal(decoded.Payload, frame.Payload) {
|
||||
t.Fatalf("tray frame round trip = %#v, %v", decoded, err)
|
||||
}
|
||||
for _, invalid := range []Frame{{Action: 0}, {Action: ActionOpenLog, Payload: []byte("unexpected")}, {Action: ActionStatus, Payload: bytes.Repeat([]byte("x"), maxPayloadBytes+1)}} {
|
||||
if !errors.Is(mustEncode(invalid), ErrInvalidFrame) && !errors.Is(mustEncode(invalid), ErrFrameTooLarge) {
|
||||
t.Fatalf("invalid tray frame accepted: %#v", invalid)
|
||||
}
|
||||
}
|
||||
corrupt := append([]byte(nil), encoded...)
|
||||
corrupt[0] = 'X'
|
||||
if _, err := Decode(corrupt); !errors.Is(err, ErrInvalidFrame) {
|
||||
t.Fatalf("corrupt tray frame error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustEncode(frame Frame) error {
|
||||
_, err := Encode(frame)
|
||||
return err
|
||||
}
|
||||
|
||||
func TestTrayPeerAuthorizationIsActionScoped_BH_WINTRAY_01(t *testing.T) {
|
||||
t.Parallel()
|
||||
user := Peer{PID: 10, SessionID: 1, SID: "S-1-5-21-user", TokenVerified: true, Interactive: true}
|
||||
if err := Authorize(user, ActionStatus); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Authorize(user, ActionRestartService); !errors.Is(err, ErrUnauthorized) {
|
||||
t.Fatalf("unprivileged service mutation error = %v", err)
|
||||
}
|
||||
admin := user
|
||||
admin.Administrator = true
|
||||
if err := Authorize(admin, ActionRestartService); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, peer := range []Peer{{PID: 10, SessionID: 1, SID: "S-1-5-21-user", Interactive: true}, {PID: 10, SessionID: 1, SID: "S-1-5-21-user", TokenVerified: true}} {
|
||||
if err := Authorize(peer, ActionStatus); !errors.Is(err, ErrInvalidPeer) && !errors.Is(err, ErrUnauthorized) {
|
||||
t.Fatalf("invalid peer accepted: %#v err=%v", peer, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user