|
| 1 | +import os |
| 2 | + |
1 | 3 | import pytest |
2 | 4 | import tt_helper |
3 | 5 |
|
@@ -109,3 +111,76 @@ def test_start_multi_inst(tt, tt_app, target): |
109 | 111 | ) |
110 | 112 | def test_start_cluster(tt, tt_app, target): |
111 | 113 | check_start(tt, tt_app, target) |
| 114 | + |
| 115 | + |
| 116 | +################################################################ |
| 117 | +# Permission denied |
| 118 | + |
| 119 | + |
| 120 | +@pytest.mark.skipif(skip_cluster_cond, reason=skip_cluster_reason) |
| 121 | +@pytest.mark.skipif( |
| 122 | + os.getuid() == 0, |
| 123 | + reason="Skipping the test, it shouldn't run as root", |
| 124 | +) |
| 125 | +@pytest.mark.tt_app(**tt_cluster_app) |
| 126 | +@pytest.mark.parametrize( |
| 127 | + "tt_running_targets", |
| 128 | + [ |
| 129 | + pytest.param([], id="running:none"), |
| 130 | + ], |
| 131 | +) |
| 132 | +def test_start_permission_denied(tt, tt_app): |
| 133 | + var_dir = tt_app.path("var") |
| 134 | + os.makedirs(var_dir, exist_ok=True) |
| 135 | + os.chmod(var_dir, 0o444) |
| 136 | + |
| 137 | + try: |
| 138 | + rc, out = tt.exec("start") |
| 139 | + assert rc != 0 |
| 140 | + assert "permission denied" in out.lower() |
| 141 | + finally: |
| 142 | + os.chmod(var_dir, 0o755) |
| 143 | + |
| 144 | + |
| 145 | +@pytest.mark.skipif(skip_cluster_cond, reason=skip_cluster_reason) |
| 146 | +@pytest.mark.skipif( |
| 147 | + os.getuid() == 0, |
| 148 | + reason="Skipping the test, it shouldn't run as root", |
| 149 | +) |
| 150 | +@pytest.mark.tt_app(**tt_cluster_app) |
| 151 | +@pytest.mark.parametrize( |
| 152 | + "tt_running_targets", |
| 153 | + [ |
| 154 | + pytest.param([], id="running:none"), |
| 155 | + ], |
| 156 | +) |
| 157 | +def test_start_permission_denied_permissions_denied_files(tt, tt_app): |
| 158 | + rc, _ = tt.exec("start") |
| 159 | + assert rc == 0 |
| 160 | + assert utils.wait_files(5, tt_helper.pid_files(tt_app, tt_app.instances)) |
| 161 | + |
| 162 | + rc, _ = tt.exec("stop", "-y") |
| 163 | + assert rc == 0 |
| 164 | + |
| 165 | + log_dir = tt_app.path("var", "log") |
| 166 | + lib_dir = tt_app.path("var", "lib") |
| 167 | + run_dir = tt_app.path("var", "run") |
| 168 | + |
| 169 | + dirs_to_lock = [] |
| 170 | + for data_dir in [log_dir, lib_dir, run_dir]: |
| 171 | + for root, dirs, files in os.walk(data_dir, topdown=False): |
| 172 | + dirs_to_lock.extend(os.path.join(root, f) for f in files) |
| 173 | + dirs_to_lock.extend(os.path.join(root, d) for d in dirs) |
| 174 | + dirs_to_lock.append(data_dir) |
| 175 | + |
| 176 | + for d in dirs_to_lock: |
| 177 | + os.chmod(d, 0o444) |
| 178 | + |
| 179 | + try: |
| 180 | + rc, out = tt.exec("start") |
| 181 | + assert rc != 0 |
| 182 | + assert "permission denied" in out.lower() |
| 183 | + finally: |
| 184 | + for d in dirs_to_lock: |
| 185 | + if os.path.exists(d): |
| 186 | + os.chmod(d, 0o755) |
0 commit comments