Ejemplo n.º 1
0
def subscription_valid(auth, username):
    """
    Valid a subscription

    Keyword argument:
        username -- Must be unique

    """
    from yunohost.user import user_create
    from yunohost.domain import domain_list
    from yunohost.app import app_ssowatconf
    
    info=subscription_info(auth, username)
    user_create(auth, info['username'], info['firstname'], info['lastname'], info['mail'], info['password'])
    
    #Update password
    new_attr_dict = {'userPassword':info['password']}  

    if auth.update('uid=%s,ou=users' % username, new_attr_dict):
       app_ssowatconf(auth)
    else:
       raise MoulinetteError(169, m18n.n('user_creation_failed'))
    
    #Remove subscription from database
    cur = _get_db()     
    cur.execute("DELETE FROM prefix_subscriptions WHERE `username`=%s",[username])
Ejemplo n.º 2
0
def subscription_valid(auth, username):
    """
    Valid a subscription

    Keyword argument:
        username -- Must be unique

    """
    from yunohost.user import user_create
    from yunohost.domain import domain_list
    from yunohost.app import app_ssowatconf

    info = subscription_info(auth, username)
    user_create(auth, info['username'], info['firstname'], info['lastname'],
                info['mail'], info['password'])

    #Update password
    new_attr_dict = {'userPassword': info['password']}

    if auth.update('uid=%s,ou=users' % username, new_attr_dict):
        app_ssowatconf(auth)
    else:
        raise MoulinetteError(169, m18n.n('user_creation_failed'))

    #Remove subscription from database
    cur = _get_db()
    cur.execute("DELETE FROM prefix_subscriptions WHERE `username`=%s",
                [username])
Ejemplo n.º 3
0
def setup_function(function):

    global maindomain
    maindomain = _get_maindomain()

    assert backup_test_dependencies_are_met()

    clean_tmp_backup_directory()
    reset_ssowat_conf()
    delete_all_backups()
    uninstall_test_apps_if_needed()

    assert len(backup_list()["archives"]) == 0

    markers = {
        m.name: {
            'args': m.args,
            'kwargs': m.kwargs
        }
        for m in function.__dict__.get("pytestmark", [])
    }

    if "with_wordpress_archive_from_2p4" in markers:
        add_archive_wordpress_from_2p4()
        assert len(backup_list()["archives"]) == 1

    if "with_legacy_app_installed" in markers:
        assert not app_is_installed("legacy_app")
        install_app("legacy_app_ynh", "/yolo")
        assert app_is_installed("legacy_app")

    if "with_backup_recommended_app_installed" in markers:
        assert not app_is_installed("backup_recommended_app")
        install_app("backup_recommended_app_ynh", "/yolo",
                    "&helper_to_test=ynh_restore_file")
        assert app_is_installed("backup_recommended_app")

    if "with_backup_recommended_app_installed_with_ynh_restore" in markers:
        assert not app_is_installed("backup_recommended_app")
        install_app("backup_recommended_app_ynh", "/yolo",
                    "&helper_to_test=ynh_restore")
        assert app_is_installed("backup_recommended_app")

    if "with_system_archive_from_2p4" in markers:
        add_archive_system_from_2p4()
        assert len(backup_list()["archives"]) == 1

    if "with_permission_app_installed" in markers:
        assert not app_is_installed("permissions_app")
        user_create("alice", "Alice", "White", maindomain, "test123Ynh")
        install_app("permissions_app_ynh", "/urlpermissionapp" "&admin=alice")
        assert app_is_installed("permissions_app")

    if "with_custom_domain" in markers:
        domain = markers['with_custom_domain']['args'][0]
        if domain not in domain_list()['domains']:
            domain_add(domain)
Ejemplo n.º 4
0
def test_create_user(mocker):

    with message(mocker, "user_created"):
        user_create("albert", "Albert", "Good", maindomain, "test123Ynh")

    group_res = user_group_list()["groups"]
    assert "albert" in user_list()["users"]
    assert "albert" in group_res
    assert "albert" in group_res["albert"]["members"]
    assert "albert" in group_res["all_users"]["members"]
Ejemplo n.º 5
0
def setup_function(function):
    clean_user_groups()

    global maindomain
    maindomain = _get_maindomain()

    user_create("alice", "Alice", "White", maindomain, "test123Ynh")
    user_create("bob", "Bob", "Snow", maindomain, "test123Ynh")
    user_create("jack", "Jack", "Black", maindomain, "test123Ynh")

    user_group_create("dev")
    user_group_create("apps")
    user_group_update("dev", add=["alice"])
    user_group_update("apps", add=["bob"])
Ejemplo n.º 6
0
def setup_function(function):
    clean_user_groups_permission()

    global maindomain
    global other_domains
    maindomain = _get_maindomain()

    markers = {
        m.name: {
            'args': m.args,
            'kwargs': m.kwargs
        }
        for m in function.__dict__.get("pytestmark", [])
    }

    if "other_domains" in markers:
        other_domains = [
            "domain_%s.dev" % string.ascii_lowercase[number]
            for number in range(markers['other_domains']['kwargs']['number'])
        ]
        for domain in other_domains:
            if domain not in domain_list()['domains']:
                domain_add(domain)

    # Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
    # Mainly used for 'can_access_webpage' function
    dns_cache = {(maindomain, 443, 0, 1): [(2, 1, 6, '', ('127.0.0.1', 443))]}
    for domain in other_domains:
        dns_cache[(domain, 443, 0, 1)] = [(2, 1, 6, '', ('127.0.0.1', 443))]

    def new_getaddrinfo(*args):
        try:
            return dns_cache[args]
        except KeyError:
            res = prv_getaddrinfo(*args)
            dns_cache[args] = res
            return res

    socket.getaddrinfo = new_getaddrinfo

    user_create("alice", "Alice", "White", maindomain, dummy_password)
    user_create("bob", "Bob", "Snow", maindomain, dummy_password)
    _permission_create_with_dummy_app(
        permission="wiki.main",
        url="/",
        additional_urls=['/whatever', '/idontnow'],
        auth_header=False,
        label="Wiki",
        show_tile=True,
        allowed=["all_users"],
        protected=False,
        sync_perm=False,
        domain=maindomain,
        path='/wiki')
    _permission_create_with_dummy_app(permission="blog.main",
                                      url="/",
                                      auth_header=True,
                                      show_tile=False,
                                      protected=False,
                                      sync_perm=False,
                                      allowed=["alice"],
                                      domain=maindomain,
                                      path='/blog')
    _permission_create_with_dummy_app(permission="blog.api",
                                      allowed=["visitors"],
                                      protected=True,
                                      sync_perm=True)
Ejemplo n.º 7
0
def test_create_user_with_domain_that_doesnt_exists(mocker):
    with raiseYunohostError(mocker, "domain_name_unknown"):
        user_create("alice", "Alice", "White", "doesnt.exists", "test123Ynh")
Ejemplo n.º 8
0
def test_create_user_already_exists(mocker):
    with raiseYunohostError(mocker, "user_already_exists"):
        user_create("alice", "Alice", "White", maindomain, "test123Ynh")
Ejemplo n.º 9
0
def test_create_user_with_password_too_simple(mocker):
    with raiseYunohostError(mocker, "password_listed"):
        user_create("other", "Alice", "White", maindomain, "12")