Esempio n. 1
0
def test_invalid_config_file(confpath):
    with open(confpath, "a+") as fi:
        fi.write("\\ Invalid toml //")

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Config file must be a valid TOML file" in str(excinfo)
Esempio n. 2
0
def test_invalid_user_keys(config, confpath):
    updated_config = deepcopy(config)
    del updated_config["anyrepo"]["ldap_provider_url"]
    del updated_config["users"]["admin"]["username"]
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Invalid user part in config file" in str(excinfo)
Esempio n. 3
0
def test_no_users(config, confpath, caplog):
    updated_config = deepcopy(config)
    del updated_config["anyrepo"]["ldap_provider_url"]
    updated_config["users"] = {}
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with caplog.at_level(logging.WARNING):
        create_app()
    assert "No user registered for the app" in caplog.text
Esempio n. 4
0
def test_invalid_secret_key(config, confpath):
    updated_config = deepcopy(config)
    updated_config["anyrepo"]["secret_key"] = "tooshort"
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Fernet key must be 32 url-safe base64-encoded bytes" in str(
        excinfo
    )
Esempio n. 5
0
def test_invalid_hook_in_config_file(config, confpath):
    updated_config = deepcopy(config)
    del updated_config["hook"]["gitlab"]["endpoint"]
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Invalid hook part in config file" in str(excinfo)

    updated_config = deepcopy(config)
    updated_config["hook"]["gitlab"]["type"] = "notsupported"
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Invalid hook type" in str(excinfo)
Esempio n. 6
0
def test_config_without_mandatory_values(config, confpath):
    updated_config = deepcopy(config)
    del updated_config["anyrepo"]["secret_key"]
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Missing secret key in config file" in str(excinfo)

    updated_config = deepcopy(config)
    del updated_config["anyrepo"]["sqlalchemy_database_uri"]
    with open(confpath, "w") as fi:
        toml.dump(updated_config, fi)

    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Missing database uri in config file" in str(excinfo)
Esempio n. 7
0
def app_without_ldap(config: dict, confpath: str) -> Flask:
    conf_ = deepcopy(config)
    del conf_["anyrepo"]["ldap_provider_url"]
    with open(confpath, "w") as fi:
        toml.dump(conf_, fi)

    app_ = create_app()
    app_.config["TESTING"] = True

    @app_.login_manager.request_loader
    def load_user_from_request(request):
        return User.query.get(1)

    return app_
Esempio n. 8
0
def app(config: dict) -> Flask:
    """Create the app"""
    app_ = create_app()
    app_.config["TESTING"] = True
    return app_
Esempio n. 9
0
def test_no_config_file(confpath):
    if os.path.exists(confpath):
        os.remove(confpath)
    with pytest.raises(ConfigError) as excinfo:
        create_app()
    assert "Config file not found" in str(excinfo)
Esempio n. 10
0
# AnyRepo
# Copyright (C) 2020  Anybox
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from anyrepo import create_app

app = create_app()