Esempio n. 1
0
 def test_valid_multi_user_multi_group_single_ip(self, ip_network_mock):
     self.config.read_dict({
         "groupfirst": {
             "userfirstname": "userfirstip",
             "usersecondname": "usersecondip",
         },
         "groupsecond": {
             "userfirstname": "userfirstip",
             "usersecondname": "usersecondip",
         }
     })
     self.assertEqual(
         get_auth_ips(self.config), {
             "userfirstname_userfirstip": {
                 "username": "******",
                 "network": "userfirstip",
                 "groups": ["groupfirst", "groupsecond"],
             },
             "usersecondname_usersecondip": {
                 "username": "******",
                 "network": "usersecondip",
                 "groups": ["groupfirst", "groupsecond"],
             }
         })
     ip_network_mock.assert_has_calls([
         mock.call("userfirstip"),
         mock.call("usersecondip"),
     ],
                                      any_order=True)
Esempio n. 2
0
from app.utils import get_auth_users, get_auth_ips, generate_auth_id
from environment_settings import APP_AUTH_FILE, APP_AUIP_FILE, APP_AUIP_ENABLED

auth = HTTPBasicAuth()

BASE_PATH = os.path.dirname(os.path.abspath(__file__))

config = ConfigParser()
config.read(APP_AUTH_FILE or "{}/auth.ini".format(BASE_PATH), encoding="utf-8")

ip_config = ConfigParser()
ip_config.read(APP_AUIP_FILE or "{}/auip.ini".format(BASE_PATH),
               encoding="utf-8")

USERS = get_auth_users(config)
IPS = get_auth_ips(ip_config)


def get_network_data():
    for network_id, network_data in IPS.items():
        network = network_data.get("network")
        if ip_address(request.remote_addr) in ip_network(network):
            return network_data


@auth.verify_password
def verify_password(username, password):
    user_id = generate_auth_id(username, auth.hash_password_callback(password))
    return verify_auth_id(user_id)