| Giorgi Lekveishvili | 285ab62 | 2023-11-22 13:50:45 +0400 | [diff] [blame^] | 1 | # pylint: disable=W0613 |
| 2 | |
| 3 | # Copyright (C) 2022 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import os |
| 18 | |
| 19 | import pytest |
| 20 | |
| 21 | from passlib.apache import HtpasswdFile |
| 22 | |
| 23 | import utils |
| 24 | |
| 25 | |
| 26 | @pytest.fixture(scope="session") |
| 27 | def credentials_dir(tmp_path_factory): |
| 28 | return tmp_path_factory.mktemp("creds") |
| 29 | |
| 30 | |
| 31 | @pytest.fixture(scope="session") |
| 32 | def htpasswd(credentials_dir): |
| 33 | basic_auth_creds = {"user": "admin", "password": utils.create_random_string(16)} |
| 34 | htpasswd_file = HtpasswdFile(os.path.join(credentials_dir, ".htpasswd"), new=True) |
| 35 | htpasswd_file.set_password(basic_auth_creds["user"], basic_auth_creds["password"]) |
| 36 | htpasswd_file.save() |
| 37 | basic_auth_creds["htpasswd_string"] = htpasswd_file.to_string() |
| 38 | basic_auth_creds["htpasswd_file"] = credentials_dir |
| 39 | yield basic_auth_creds |