Repository navigation
Expand file tree
/
Copy pathtranslocation_test.go
More file actions
64 lines (55 loc) · 1.98 KB
/
Copy pathtranslocation_test.go
File metadata and controls
64 lines (55 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package selfupdate
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsTranslocatedPath(t *testing.T) {
assert.True(t, isTranslocatedPath("/private/var/folders/pc/1mt578kn6615qkxsygpwrw7m0000gn/T/AppTranslocation/CC9EEF5E-BE8A-47B5-9BA2-2A9793595220/d/Example.app/Contents/MacOS/example"))
assert.False(t, isTranslocatedPath("/Applications/Example.app/Contents/MacOS/example"))
assert.False(t, isTranslocatedPath("/Users/me/Applications/Example.app/Contents/MacOS/example"))
assert.False(t, isTranslocatedPath("/home/me/AppTranslocation"))
assert.False(t, isTranslocatedPath(""))
}
func TestApplyTranslocatedReadOnly(t *testing.T) {
if runtime.GOOS == "windows" || os.Geteuid() == 0 {
t.Skip("relies on POSIX directory permissions being enforced")
}
dir := filepath.Join(t.TempDir(), "AppTranslocation", "CC9EEF5E", "d", "Example.app", "Contents", "MacOS")
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
target := filepath.Join(dir, "example")
if err := os.WriteFile(target, []byte("old"), 0755); err != nil {
t.Fatal(err)
}
if err := os.Chmod(dir, 0555); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Chmod(dir, 0755) })
err := Apply(strings.NewReader("new"), Options{TargetPath: target})
assert.ErrorIs(t, err, ErrTranslocated)
}
func TestApplyReadOnlyNotTranslocated(t *testing.T) {
if runtime.GOOS == "windows" || os.Geteuid() == 0 {
t.Skip("relies on POSIX directory permissions being enforced")
}
dir := filepath.Join(t.TempDir(), "Example.app", "Contents", "MacOS")
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
target := filepath.Join(dir, "example")
if err := os.WriteFile(target, []byte("old"), 0755); err != nil {
t.Fatal(err)
}
if err := os.Chmod(dir, 0555); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Chmod(dir, 0755) })
err := Apply(strings.NewReader("new"), Options{TargetPath: target})
assert.Error(t, err)
assert.NotErrorIs(t, err, ErrTranslocated)
}