2a3d85b7632e93087b649f1a6222cd9772ad4d04
- Author
- Michael Aquilina <michaelaquilina@gmail.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Merge pull request #41 from gugu/master
Support 644 and 640 permissions as well
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index 1927b4180abc2e0a4707c1dc4babc0962a282fa4..a78651cfafccff2be788bf58d31e9be47383ee2a 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -77,7 +77,7 @@ function check_venv()
6 printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
7 printf "Reason: Found a .venv file but it is not owned by the current user\n"
8 printf "Change ownership of $venv_path to '$USER' to fix this\n"
9- elif [[ "$file_permissions" != "600" ]]; then
10+ elif ! [[ "$file_permissions" =~ ^[64][04][04]$ ]]; then
11 printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
12 printf "Reason: Found a .venv file with weak permission settings ($file_permissions).\n"
13 printf "Run the following command to fix this: \"chmod 600 $venv_path\"\n"
14diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
15index c312bd9ad0d4960849cd1e3af4648fb36728d57d..31f7bf8ede74bb4f36927b8c7f7506a69eb4fccb 100644
16--- a/tests/test_check_venv.zunit
17+++ b/tests/test_check_venv.zunit
18@@ -25,7 +25,7 @@
19 }
20
21
22-@test 'check_venv - Security warning for weak permissions' {
23+@test 'check_venv - Security warning for weak writeable by group permissions' {
24 PWD="$TARGET"
25
26 echo "foobar" > "$TARGET/.venv"
27@@ -41,6 +41,66 @@
28 assert "$lines[4]" same_as "Run the following command to fix this: \"chmod 600 $TARGET/.venv\""
29 }
30
31+@test 'check_venv - Security warning for weak writeable by everyone permissions' {
32+ PWD="$TARGET"
33+
34+ echo "foobar" > "$TARGET/.venv"
35+ chmod 600 "$TARGET/.venv"
36+ chmod a+w "$TARGET/.venv"
37+
38+ run check_venv
39+
40+ assert $status equals 0
41+ assert "$lines[1]" same_as "AUTOSWITCH WARNING: Virtualenv will not be activated"
42+ assert "$lines[2]" is_empty
43+ assert "$lines[3]" same_as "Reason: Found a .venv file with weak permission settings (622)."
44+ assert "$lines[4]" same_as "Run the following command to fix this: \"chmod 600 $TARGET/.venv\""
45+}
46+
47+@test 'check_venv - No security warning for readable by everyone permission' {
48+ PWD="$TARGET"
49+
50+ echo "foobar" > "$TARGET/.venv"
51+ chmod 600 "$TARGET/.venv"
52+ chmod a+r "$TARGET/.venv"
53+ MYOLDPWD="$(dirname $TARGET)"
54+ AUTOSWITCH_DEFAULTENV="foodefault"
55+
56+ run check_venv
57+
58+ assert $status equals 0
59+ assert "$output" same_as "Switching virtualenv: foobar [$PYTHON_VERSION]"
60+}
61+
62+@test 'check_venv - No security warning for readable by group permission' {
63+ PWD="$TARGET"
64+
65+ echo "foobar" > "$TARGET/.venv"
66+ chmod 600 "$TARGET/.venv"
67+ chmod g+r "$TARGET/.venv"
68+ MYOLDPWD="$(dirname $TARGET)"
69+ AUTOSWITCH_DEFAULTENV="foodefault"
70+
71+ run check_venv
72+
73+ assert $status equals 0
74+ assert "$output" same_as "Switching virtualenv: foobar [$PYTHON_VERSION]"
75+}
76+
77+@test 'check_venv - No security warning for readable only by owner permission' {
78+ PWD="$TARGET"
79+
80+ echo "foobar" > "$TARGET/.venv"
81+ chmod 600 "$TARGET/.venv"
82+ MYOLDPWD="$(dirname $TARGET)"
83+ AUTOSWITCH_DEFAULTENV="foodefault"
84+
85+ run check_venv
86+
87+ assert $status equals 0
88+ assert "$output" same_as "Switching virtualenv: foobar [$PYTHON_VERSION]"
89+}
90+
91
92 @test 'check_venv - does not change if MYOLDPWD=PWD' {
93 PWD="$TARGET"