mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 08:20:05 +08:00
Some checks failed
Test / test (1.20, ubuntu-latest) (push) Failing after 1s
Test / test (1.21, ubuntu-latest) (push) Failing after 1s
Test / test (1.22, ubuntu-latest) (push) Failing after 1s
Test / test (1.23, ubuntu-latest) (push) Failing after 1s
Test / test (1.24, ubuntu-latest) (push) Failing after 1s
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 1s
Test / test (1.20, macos-13) (push) Has been cancelled
Test / test (1.20, macos-latest) (push) Has been cancelled
Test / test (1.20, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.20, windows-latest) (push) Has been cancelled
Test / test (1.21, macos-13) (push) Has been cancelled
Test / test (1.21, macos-latest) (push) Has been cancelled
Test / test (1.21, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.21, windows-latest) (push) Has been cancelled
Test / test (1.22, macos-13) (push) Has been cancelled
Test / test (1.22, macos-latest) (push) Has been cancelled
Test / test (1.22, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.22, windows-latest) (push) Has been cancelled
Test / test (1.23, macos-13) (push) Has been cancelled
Test / test (1.23, macos-latest) (push) Has been cancelled
Test / test (1.23, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.23, windows-latest) (push) Has been cancelled
Test / test (1.24, macos-13) (push) Has been cancelled
Test / test (1.24, macos-latest) (push) Has been cancelled
Test / test (1.24, ubuntu-24.04-arm) (push) Has been cancelled
Test / test (1.24, windows-latest) (push) Has been cancelled
package managers can allow for pre-defined safe paths without disabling the entire security check feature for https://github.com/MetaCubeX/mihomo/issues/2004
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package constant
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestPath(t *testing.T) {
|
|
assert.False(t, (&path{}).IsSafePath("/usr/share/metacubexd/"))
|
|
assert.True(t, (&path{
|
|
safePaths: []string{"/usr/share/metacubexd"},
|
|
}).IsSafePath("/usr/share/metacubexd/"))
|
|
|
|
assert.False(t, (&path{}).IsSafePath("../metacubexd/"))
|
|
assert.True(t, (&path{
|
|
homeDir: "/usr/share/mihomo",
|
|
safePaths: []string{"/usr/share/metacubexd"},
|
|
}).IsSafePath("../metacubexd/"))
|
|
assert.False(t, (&path{
|
|
homeDir: "/usr/share/mihomo",
|
|
safePaths: []string{"/usr/share/ycad"},
|
|
}).IsSafePath("../metacubexd/"))
|
|
|
|
assert.False(t, (&path{}).IsSafePath("/opt/mykeys/key1.key"))
|
|
assert.True(t, (&path{
|
|
safePaths: []string{"/opt/mykeys"},
|
|
}).IsSafePath("/opt/mykeys/key1.key"))
|
|
assert.True(t, (&path{
|
|
safePaths: []string{"/opt/mykeys/"},
|
|
}).IsSafePath("/opt/mykeys/key1.key"))
|
|
assert.True(t, (&path{
|
|
safePaths: []string{"/opt/mykeys/key1.key"},
|
|
}).IsSafePath("/opt/mykeys/key1.key"))
|
|
|
|
assert.True(t, (&path{}).IsSafePath("key1.key"))
|
|
assert.True(t, (&path{}).IsSafePath("./key1.key"))
|
|
assert.True(t, (&path{}).IsSafePath("./mykey/key1.key"))
|
|
assert.True(t, (&path{}).IsSafePath("./mykey/../key1.key"))
|
|
assert.False(t, (&path{}).IsSafePath("./mykey/../../key1.key"))
|
|
|
|
}
|