dbus: add more test cases

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra 2024-09-28 19:19:31 +09:00
parent 342c66aae8
commit 0e7849fac2
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
5 changed files with 104 additions and 16 deletions

View File

@ -1,6 +1,8 @@
package dbus_test package dbus_test
import ( import (
"errors"
"os"
"path" "path"
"reflect" "reflect"
"slices" "slices"
@ -40,12 +42,17 @@ func TestNewConfigFromFile(t *testing.T) {
t.Run(name.String(), func(t *testing.T) { t.Run(name.String(), func(t *testing.T) {
got, err := dbus.NewConfigFromFile(samplePath) got, err := dbus.NewConfigFromFile(samplePath)
if err != nil { if errors.Is(err, os.ErrNotExist) != tc.wantErrF {
t.Errorf("NewConfigFromFile(%q) error = %v", t.Errorf("NewConfigFromFile(%q) error = %v, wantErrF %v",
samplePath, samplePath,
err) err, tc.wantErrF)
return return
} }
if tc.wantErrF {
return
}
if !tc.wantErr && !reflect.DeepEqual(got, tc.c) { if !tc.wantErr && !reflect.DeepEqual(got, tc.c) {
t.Errorf("NewConfigFromFile(%q) got = %v, want %v", t.Errorf("NewConfigFromFile(%q) got = %v, want %v",
samplePath, samplePath,

View File

@ -9,14 +9,16 @@ import (
var samples = []dbusTestCase{ var samples = []dbusTestCase{
{ {
"org.chromium.Chromium", &dbus.Config{ "org.chromium.Chromium", &dbus.Config{
See: nil, See: nil,
Talk: []string{"org.freedesktop.Notifications", "org.freedesktop.FileManager1", "org.freedesktop.ScreenSaver"}, Talk: []string{"org.freedesktop.Notifications", "org.freedesktop.FileManager1", "org.freedesktop.ScreenSaver",
Own: []string{"org.chromium.Chromium.*", "org.mpris.MediaPlayer2.org.chromium.Chromium.*", "org.mpris.MediaPlayer2.chromium.*"}, "org.freedesktop.secrets", "org.kde.kwalletd5", "org.kde.kwalletd6", "org.gnome.SessionManager"},
Own: []string{"org.chromium.Chromium.*", "org.mpris.MediaPlayer2.org.chromium.Chromium.*",
"org.mpris.MediaPlayer2.chromium.*"},
Call: map[string]string{"org.freedesktop.portal.*": "*"}, Call: map[string]string{"org.freedesktop.portal.*": "*"},
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"}, Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
Log: false, Log: false,
Filter: true, Filter: true,
}, false, }, false, false,
[2]string{"unix:path=/run/user/1971/bus", "/tmp/fortify.1971/12622d846cc3fe7b4c10359d01f0eb47/bus"}, [2]string{"unix:path=/run/user/1971/bus", "/tmp/fortify.1971/12622d846cc3fe7b4c10359d01f0eb47/bus"},
[]string{ []string{
"unix:path=/run/user/1971/bus", "unix:path=/run/user/1971/bus",
@ -25,6 +27,10 @@ var samples = []dbusTestCase{
"--talk=org.freedesktop.Notifications", "--talk=org.freedesktop.Notifications",
"--talk=org.freedesktop.FileManager1", "--talk=org.freedesktop.FileManager1",
"--talk=org.freedesktop.ScreenSaver", "--talk=org.freedesktop.ScreenSaver",
"--talk=org.freedesktop.secrets",
"--talk=org.kde.kwalletd5",
"--talk=org.kde.kwalletd6",
"--talk=org.gnome.SessionManager",
"--own=org.chromium.Chromium.*", "--own=org.chromium.Chromium.*",
"--own=org.mpris.MediaPlayer2.org.chromium.Chromium.*", "--own=org.mpris.MediaPlayer2.org.chromium.Chromium.*",
"--own=org.mpris.MediaPlayer2.chromium.*", "--own=org.mpris.MediaPlayer2.chromium.*",
@ -35,17 +41,18 @@ var samples = []dbusTestCase{
{ {
"org.chromium.Chromium+", &dbus.Config{ "org.chromium.Chromium+", &dbus.Config{
See: nil, See: nil,
Talk: []string{"org.freedesktop.Avahi", "org.freedesktop.UPower"}, Talk: []string{"org.bluez", "org.freedesktop.Avahi", "org.freedesktop.UPower"},
Own: nil, Own: nil,
Call: nil, Call: nil,
Broadcast: nil, Broadcast: nil,
Log: false, Log: false,
Filter: true, Filter: true,
}, false, }, false, false,
[2]string{"unix:path=/run/dbus/system_bus_socket", "/tmp/fortify.1971/12622d846cc3fe7b4c10359d01f0eb47/system_bus_socket"}, [2]string{"unix:path=/run/dbus/system_bus_socket", "/tmp/fortify.1971/12622d846cc3fe7b4c10359d01f0eb47/system_bus_socket"},
[]string{"unix:path=/run/dbus/system_bus_socket", []string{"unix:path=/run/dbus/system_bus_socket",
"/tmp/fortify.1971/12622d846cc3fe7b4c10359d01f0eb47/system_bus_socket", "/tmp/fortify.1971/12622d846cc3fe7b4c10359d01f0eb47/system_bus_socket",
"--filter", "--filter",
"--talk=org.bluez",
"--talk=org.freedesktop.Avahi", "--talk=org.freedesktop.Avahi",
"--talk=org.freedesktop.UPower", "--talk=org.freedesktop.UPower",
}, },
@ -60,7 +67,7 @@ var samples = []dbusTestCase{
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"}, Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
Log: false, Log: false,
Filter: true, Filter: true,
}, false, }, false, false,
[2]string{"unix:path=/run/user/1971/bus", "/tmp/fortify.1971/34c24f16a0d791d28835ededaf446033/bus"}, [2]string{"unix:path=/run/user/1971/bus", "/tmp/fortify.1971/34c24f16a0d791d28835ededaf446033/bus"},
[]string{ []string{
"unix:path=/run/user/1971/bus", "unix:path=/run/user/1971/bus",
@ -73,14 +80,62 @@ var samples = []dbusTestCase{
"--call=org.freedesktop.portal.*=*", "--call=org.freedesktop.portal.*=*",
"--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*"}, "--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*"},
}, },
{
"moe.ophivana.CrashTestDummy", &dbus.Config{
See: []string{"moe.ophivana.CrashTestDummy1"},
Talk: []string{"org.freedesktop.Notifications"},
Own: []string{"moe.ophivana.CrashTestDummy.*", "org.mpris.MediaPlayer2.moe.ophivana.CrashTestDummy.*"},
Call: map[string]string{"org.freedesktop.portal.*": "*"},
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
Log: true,
Filter: true,
}, false, false,
[2]string{"unix:path=/run/user/1971/bus", "/tmp/fortify.1971/5da7845287a936efbc2fa75d7d81e501/bus"},
[]string{
"unix:path=/run/user/1971/bus",
"/tmp/fortify.1971/5da7845287a936efbc2fa75d7d81e501/bus",
"--filter",
"--see=moe.ophivana.CrashTestDummy1",
"--talk=org.freedesktop.Notifications",
"--own=moe.ophivana.CrashTestDummy.*",
"--own=org.mpris.MediaPlayer2.moe.ophivana.CrashTestDummy.*",
"--call=org.freedesktop.portal.*=*",
"--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*",
"--log"},
},
{
"moe.ophivana.CrashTestDummy1", &dbus.Config{
See: []string{"moe.ophivana.CrashTestDummy"},
Talk: []string{"org.freedesktop.Notifications"},
Own: []string{"moe.ophivana.CrashTestDummy1.*", "org.mpris.MediaPlayer2.moe.ophivana.CrashTestDummy1.*"},
Call: map[string]string{"org.freedesktop.portal.*": "*"},
Broadcast: map[string]string{"org.freedesktop.portal.*": "@/org/freedesktop/portal/*"},
Log: true,
Filter: true,
}, false, true,
[2]string{"unix:path=/run/user/1971/bus", "/tmp/fortify.1971/5da7845287a936efbc2fa75d7d81e501/bus"},
[]string{
"unix:path=/run/user/1971/bus",
"/tmp/fortify.1971/5da7845287a936efbc2fa75d7d81e501/bus",
"--filter",
"--see=moe.ophivana.CrashTestDummy",
"--talk=org.freedesktop.Notifications",
"--own=moe.ophivana.CrashTestDummy1.*",
"--own=org.mpris.MediaPlayer2.moe.ophivana.CrashTestDummy1.*",
"--call=org.freedesktop.portal.*=*",
"--broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/*",
"--log"},
},
} }
type dbusTestCase struct { type dbusTestCase struct {
id string id string
c *dbus.Config c *dbus.Config
wantErr bool wantErr bool
bus [2]string wantErrF bool
want []string bus [2]string
want []string
} }
var ( var (

View File

@ -0,0 +1,21 @@
{
"see": [
"moe.ophivana.CrashTestDummy1"
],
"talk":[
"org.freedesktop.Notifications"
],
"own":[
"moe.ophivana.CrashTestDummy.*",
"org.mpris.MediaPlayer2.moe.ophivana.CrashTestDummy.*"
],
"call":{
"org.freedesktop.portal.*":"*"
},
"broadcast":{
"org.freedesktop.portal.*":"@/org/freedesktop/portal/*"
},
"log": true,
"filter":true
}

View File

@ -1,5 +1,6 @@
{ {
"talk":[ "talk":[
"org.bluez",
"org.freedesktop.Avahi", "org.freedesktop.Avahi",
"org.freedesktop.UPower" "org.freedesktop.UPower"
], ],

View File

@ -2,7 +2,11 @@
"talk":[ "talk":[
"org.freedesktop.Notifications", "org.freedesktop.Notifications",
"org.freedesktop.FileManager1", "org.freedesktop.FileManager1",
"org.freedesktop.ScreenSaver" "org.freedesktop.ScreenSaver",
"org.freedesktop.secrets",
"org.kde.kwalletd5",
"org.kde.kwalletd6",
"org.gnome.SessionManager"
], ],
"own":[ "own":[
"org.chromium.Chromium.*", "org.chromium.Chromium.*",