Reset master to testing content
This commit is contained in:
1 parent
0f2587b719
commit
42afa2a56c
1483 files changed
+145308
-938069
No files matched your search
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// Authors: Storm Dragon, Angus Kola
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package atspi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFlatpakProcessInstanceBoundaries(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
write := func(pid int, data string) {
|
||||
t.Helper()
|
||||
dir := filepath.Join(root, fmt.Sprint(pid), "root")
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, ".flatpak-info"), []byte(data), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
metadata := "[Application]\nname=org.example.App\n[Instance]\ninstance-id=123\n"
|
||||
write(100, metadata)
|
||||
for _, test := range []struct {
|
||||
name, data string
|
||||
want bool
|
||||
}{
|
||||
{"same instance", metadata, true},
|
||||
{"other instance of same app", strings.ReplaceAll(metadata, "123", "456"), false},
|
||||
{"other app", strings.ReplaceAll(metadata, "org.example.App", "org.example.Other"), false},
|
||||
{"app ID alone", "[Application]\nname=org.example.App\n", false},
|
||||
{"instance ID alone", "[Instance]\ninstance-id=123\n", false},
|
||||
{"wrong section", "[Application]\nname=org.example.App\ninstance-id=123\n", false},
|
||||
{"empty metadata", "", false},
|
||||
{"malformed metadata", metadata + "broken", false},
|
||||
{"duplicate identity", metadata + "instance-id=456\n", false},
|
||||
{"oversized metadata", metadata + strings.Repeat("#", 65536), false},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
write(200, test.data)
|
||||
if got := sameFlatpakInstance(root, 100, 200); got != test.want {
|
||||
t.Fatalf("same instance = %v; want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
if sameFlatpakInstance(root, 100, 300) || sameFlatpakInstance(root, 300, 400) || sameFlatpakInstance(root, 0, 0) {
|
||||
t.Fatal("missing process or unknown identity matched")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user