37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package app
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"git.stormux.org/storm/fenrir/internal/config"
|
|
"git.stormux.org/storm/fenrir/internal/control"
|
|
)
|
|
|
|
func TestRemoteRequestRejectsOtherUsersBeforeApplyingCommands(t *testing.T) {
|
|
for _, terminalMode := range []bool{false, true} {
|
|
voice := &fakeVoice{}
|
|
a, err := new_application(context.Background(), &fakeSource{}, &fakeKeys{}, voice, RunOptions{Settings: config.Defaults(), TerminalMode: terminalMode})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(a.ui.close)
|
|
for _, uid := range []int{os.Geteuid() + 1, os.Geteuid(), 0} {
|
|
replies := make(chan string, 1)
|
|
a.remote_request(control.Request{UID: uid, Text: "COMMAND SAY authorized", Reply: replies})
|
|
reply := <-replies
|
|
if uid == os.Geteuid()+1 {
|
|
if reply != "Remote control is not permitted for this session" || len(voice.messages) != 0 {
|
|
t.Fatal("unauthorized request reached speech", reply, voice.messages)
|
|
}
|
|
} else if reply != "" || len(voice.messages) == 0 || voice.messages[len(voice.messages)-1] != "authorized" {
|
|
t.Fatal("owner/root request failed", reply, voice.messages)
|
|
}
|
|
}
|
|
}
|
|
}
|