blob: de39dc1b8f04ef7406d38f9f7f9577c9335f7f2d [file] [log] [blame]
Giorgi Lekveishvili285ab622023-11-22 13:50:45 +04001# 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
17import os
18
19import pytest
20
21from passlib.apache import HtpasswdFile
22
23import utils
24
25
26@pytest.fixture(scope="session")
27def credentials_dir(tmp_path_factory):
28 return tmp_path_factory.mktemp("creds")
29
30
31@pytest.fixture(scope="session")
32def 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