Пример #1
0
 def get_from_dict(dict_data: Dict) -> EnvironmentConfig:
     user_creds = UserCreds.get_from_dict(dict_data)
     aws = dict_data['aws'] if 'aws' in dict_data else None
     return EnvironmentConfig(server_config=dict_data['server_config'],
                              deployment=dict_data['deployment'],
                              user_creds=user_creds,
                              aws=aws)
Пример #2
0
 def post(self):
     credentials = UserCreds.get_from_json(request.data)
     try:
         env_singleton.env.try_add_user(credentials)
         return make_response({"error": ""}, 200)
     except (InvalidRegistrationCredentialsError, RegistrationNotNeededError) as e:
         return make_response({"error": str(e)}, 400)
Пример #3
0
def _get_user_credentials_from_request(request):
    cred_dict = json.loads(request.data)

    username = cred_dict.get("user", "")
    password = cred_dict.get("password", "")
    password_hash = password_utils.hash_password(password)

    return UserCreds(username, password_hash)
Пример #4
0
    def _test_save_to_file(self, config: Dict):
        user_creds = UserCreds.get_from_dict(config)
        env_config = EnvironmentConfig(server_config=config['server_config'],
                                       deployment=config['deployment'],
                                       user_creds=user_creds)

        env_config.save_to_file()
        file_path = get_server_config_file_path_test_version()
        with open(file_path, 'r') as f:
            content_from_file = f.read()
        os.remove(file_path)

        self.assertDictEqual(config, json.loads(content_from_file))
Пример #5
0
def test_add_user(config_file, standard_with_credentials):
    new_user = "******"
    new_password_hash = "fedcba"
    new_user_creds = UserCreds(new_user, new_password_hash)

    shutil.copyfile(standard_with_credentials, config_file)

    environment_config = EnvironmentConfig(config_file)
    environment_config.add_user(new_user_creds)

    with open(config_file, "r") as f:
        from_file = json.load(f)

    assert len(from_file["environment"].keys()) == 4
    assert from_file["environment"]["user"] == new_user
    assert from_file["environment"]["password_hash"] == new_password_hash
Пример #6
0
def _get_user_credentials_from_config(dict_data: Dict):
    username = dict_data.get("user", "")
    password_hash = dict_data.get("password_hash", "")

    return UserCreds(username, password_hash)
Пример #7
0
def test_bool_true():
    assert UserCreds(TEST_USER, TEST_HASH)
Пример #8
0
def test_member_values(monkeypatch):
    creds = UserCreds(TEST_USER, TEST_HASH)
    assert creds.username == TEST_USER
    assert creds.password_hash == TEST_HASH
Пример #9
0
def test_to_auth_user_full_credentials():
    user_creds = UserCreds(TEST_USER, TEST_HASH)
    auth_user = user_creds.to_auth_user()
    assert auth_user.id == 1
    assert auth_user.username == TEST_USER
    assert auth_user.secret == TEST_HASH
Пример #10
0
def test_to_dict_full_creds():
    user_creds = UserCreds(TEST_USER, TEST_HASH)
    assert user_creds.to_dict() == {
        "user": TEST_USER,
        "password_hash": TEST_HASH
    }
Пример #11
0
def test_to_dict_empty_creds():
    user_creds = UserCreds("", "")
    assert user_creds.to_dict() == {}
Пример #12
0
def test_bool_false_empty_user_and_password_hash():
    assert not UserCreds("", "")
Пример #13
0
def test_bool_false_empty_user():
    assert not UserCreds("", TEST_HASH)
Пример #14
0
def test_bool_false_empty_password_hash():
    assert not UserCreds(TEST_USER, "")
Пример #15
0
def get_user_credentials_from_request(_request) -> UserCreds:
    username, password = get_username_password_from_request(_request)
    password_hash = hash_password(password)

    return UserCreds(username, password_hash)