コード例 #1
0
def test_adduser_with_roles():
    handle(['', u'adduser', u'cdent', u'crunk', u'cow', u'monkey'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('crunk')
    assert 'cow' in the_user.list_roles()
    assert 'monkey' in the_user.list_roles()
コード例 #2
0
ファイル: test_commands.py プロジェクト: sgml/tiddlyweb
def test_adduser_with_roles():
    handle(['', u'adduser', u'cdent', u'crunk', u'cow', u'monkey'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('crunk')
    assert 'cow' in the_user.list_roles()
    assert 'monkey' in the_user.list_roles()
コード例 #3
0
ファイル: __init__.py プロジェクト: cdent/wiki-data
def update_user(environ, start_response):
    query = environ['tiddlyweb.query']
    store = environ['tiddlyweb.store']
    username = query.get('email', [None])[0]
    if not username:
        return update_user_form(environ, start_response,
                message='Must have username/email')
    name = query.get('name', [''])[0]
    country = query.get('country', [''])[0]
    company = query.get('company', [''])[0]
    password = query.get('password', [''])[0]
    tier = query.get('tier', [''])[0]

    expiry = query.get('expiry', ['0'])[0]
    now = time.time()
    expiry = now + (float(expiry) * 24 * 60 * 60)

    user = User(username)
    user_new = False
    try:
        user = store.get(user)
    except NoUserError:
        user_new = True
    roles = [role for role in user.list_roles() if not role.startswith('tier')]
    for role in user.list_roles():
        user.del_role(role)
    roles.append(tier)
    for role in roles:
        user.add_role(role) # it's a set dupes are handled
    if password:
        user.set_password(password)
    store.put(user)

    bag_name = environ['tiddlyweb.config'].get('magicuser.bag', 'MAGICUSER')
    tiddler = Tiddler(username, bag_name)
    tiddler.fields['country'] = country
    tiddler.fields['company'] = company
    tiddler.fields['name'] = name
    # Set the creation and expiration times.
    if user_new:
        tiddler.fields['creation'] = '%s' % now
    tiddler.fields['expiry'] = '%s' % expiry
    store.put(tiddler)

    # XXX need to go somewhere useful?
    #raise HTTP303(server_base_url(environ))
    message = "Update successful"
    success = True
    logging.debug('going to update_user_form with message: '+message)
    return update_user_form(environ, start_response, message, success)
コード例 #4
0
ファイル: __init__.py プロジェクト: jayfresh/wiki-data
def update_user(environ, start_response):
    query = environ["tiddlyweb.query"]
    store = environ["tiddlyweb.store"]
    username = query.get("email", [None])[0]
    if not username:
        return update_user_form(environ, start_response, message="Must have username/email")
    name = query.get("name", [""])[0]
    country = query.get("country", [""])[0]
    company = query.get("company", [""])[0]
    password = query.get("password", [""])[0]
    tier = query.get("tier", [""])[0]

    expiry = query.get("expiry", ["0"])[0]
    now = time.time()
    expiry = now + (float(expiry) * 24 * 60 * 60)

    user = User(username)
    user_new = False
    try:
        user = store.get(user)
    except NoUserError:
        user_new = True
    roles = [role for role in user.list_roles() if not role.startswith("tier")]
    for role in user.list_roles():
        user.del_role(role)
    roles.append(tier)
    for role in roles:
        user.add_role(role)  # it's a set dupes are handled
    if password:
        user.set_password(password)
    store.put(user)

    bag_name = environ["tiddlyweb.config"].get("magicuser.bag", "MAGICUSER")
    tiddler = Tiddler(username, bag_name)
    tiddler.fields["country"] = country
    tiddler.fields["company"] = company
    tiddler.fields["name"] = name
    # Set the creation and expiration times.
    if user_new:
        tiddler.fields["creation"] = "%s" % now
    tiddler.fields["expiry"] = "%s" % expiry
    store.put(tiddler)

    # XXX need to go somewhere useful?
    # raise HTTP303(server_base_url(environ))
    message = "Update successful"
    success = True
    logging.debug("going to update_user_form with message: " + message)
    return update_user_form(environ, start_response, message, success)
コード例 #5
0
ファイル: test_user.py プロジェクト: tiddlyweb/tiddlyweb
def test_user_role():
    user = User('paper')
    assert user.list_roles() == []

    user.add_role('ADMIN')
    assert user.list_roles() == ['ADMIN']

    user.del_role('ADMIN')
    assert user.list_roles() == []

    # add twice to confirm set-ness
    user.add_role('ADMIN')
    user.add_role('ADMIN')

    assert user.list_roles() == ['ADMIN']
コード例 #6
0
ファイル: test_user.py プロジェクト: sgml/tiddlyweb
def test_user_role():
    user = User('paper')
    assert user.list_roles() == []

    user.add_role('ADMIN')
    assert user.list_roles() == ['ADMIN']

    user.del_role('ADMIN')
    assert user.list_roles() == []

    # add twice to confirm set-ness
    user.add_role('ADMIN')
    user.add_role('ADMIN')

    assert user.list_roles() == ['ADMIN']
コード例 #7
0
def handle(environ, start_response):
    """
    Handle a posted request for registration.

    If the provided username is blacklisted, ask them to
    log in as someone else. Otherwise send closing
    material with a link to get started.
    """
    pretty_name = environ['tiddlyweb.query'].get('pretty_name', [None])[0]
    target_role = environ['tiddlyweb.config'].get('register_role', 'MEMBER')
    store = environ['tiddlyweb.store']
    username = environ['tiddlyweb.usersign']['name']
    if _blacklisted(environ, username):
        return _send_start(environ, start_response,
                message='That user has been blocked')
    user = User(username)
    try:
        user = store.get(user)
    except NoUserError:
        pass # is cool if they don't exist yet
    user.add_role('%s' % target_role)
    if pretty_name:
        user.note = pretty_name
    store.put(user)
    environ['tiddlyweb.usersign'] = {'name': user.usersign,
            'roles': user.list_roles()}
    return _send_finish(environ, start_response)
コード例 #8
0
def user_page(environ, start_response):
    userpage = environ['wsgiorg.routing_args'][1]['userpage']
    user = environ['tiddlyweb.usersign']

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ['tiddlyweb.store']

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass  # roles will be empty
    if 'MEMBER' not in userpage_user.list_roles():
        raise HTTP404('%s has no page' % userpage)

    user_friend_names = get_friends(store, user['name'])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage),
                               user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage),
                               user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {
        'bags': kept_bags,
        'user_friends': user_friend_names,
        'friends': friends,
        'recipes': kept_recipes,
        'favorites': kept_favorites,
        'bookmarks': kept_bookmarks,
        'home': userpage,
        'profile': profile_html,
        'notice': {
            'html': notice_html,
            'modified': notice_tiddler.modified
        },
        'title': userpage,
        'email': email,
        'email_md5': email_md5,
        'user': get_user_object(environ)
    }

    return send_template(environ, 'profile.html', data)
コード例 #9
0
ファイル: userbag.py プロジェクト: FND/tiddlyweb-plugins-1
 def tiddler_get(self, tiddler):
     store = self.main_store
     username = tiddler.title
     user = User(username)
     user = store.get(user)
     tiddler.text = '%s' % user.list_roles()
     return tiddler
コード例 #10
0
ファイル: userbag.py プロジェクト: funkyeah/tiddlyweb-plugins
 def tiddler_get(self, tiddler):
     store = self.main_store
     username = tiddler.title
     user = User(username)
     user = store.get(user)
     tiddler.text = '%s' % user.list_roles()
     return tiddler
コード例 #11
0
ファイル: register.py プロジェクト: palladius/appengine
def handle(environ, start_response):
    """
    Handle a posted request for registration.

    If the provided username is blacklisted, ask them to
    log in as someone else. Otherwise send closing
    material with a link to get started.
    """
    pretty_name = environ["tiddlyweb.query"].get("pretty_name", [None])[0]
    target_role = environ["tiddlyweb.config"].get("register_role", "MEMBER")
    store = environ["tiddlyweb.store"]
    username = environ["tiddlyweb.usersign"]["name"]
    if _blacklisted(environ, username):
        return _send_start(environ, start_response, message="That user has been blocked")
    user = User(username)
    try:
        user = store.get(user)
    except NoUserError:
        pass  # is cool if they don't exist yet
    user.add_role("%s" % target_role)
    if pretty_name:
        user.note = pretty_name
    store.put(user)
    environ["tiddlyweb.usersign"] = {"name": user.usersign, "roles": user.list_roles()}
    return _send_finish(environ, start_response)
コード例 #12
0
def handle(environ, start_response):
    """
    Handle a posted request for registration.

    If the provided username is blacklisted, ask them to
    log in as someone else. Otherwise send closing
    material with a link to get started.
    """
    pretty_name = environ['tiddlyweb.query'].get('pretty_name', [None])[0]
    target_role = environ['tiddlyweb.config'].get('register_role', 'MEMBER')
    store = environ['tiddlyweb.store']
    username = environ['tiddlyweb.usersign']['name']
    if _blacklisted(environ, username):
        return _send_start(environ,
                           start_response,
                           message='That user has been blocked')
    user = User(username)
    try:
        user = store.get(user)
    except NoUserError:
        pass  # is cool if they don't exist yet
    user.add_role('%s' % target_role)
    if pretty_name:
        user.note = pretty_name
    store.put(user)
    environ['tiddlyweb.usersign'] = {
        'name': user.usersign,
        'roles': user.list_roles()
    }
    return _send_finish(environ, start_response)
コード例 #13
0
ファイル: test_simple.py プロジェクト: cdent/tiddlywebredis
def test_users():
    userc = User('cdent')
    userc.set_password('foobar')
    userc.add_role('ADMIN')
    userc.note = 'A simple programmer of matter'

    store.put(userc)

    userf = User('FND')
    userf.set_password('I<3whitespace')

    store.put(userf)

    user2 = store.get(User('cdent'))
    assert user2.usersign == userc.usersign
    assert user2.check_password('foobar')
    assert user2.list_roles() == userc.list_roles()
    assert user2.note == userc.note

    users = list(store.list_users())
    assert len(users) == 2
    assert ['FND', 'cdent'] == sorted([user.usersign for user in users])

    store.delete(User('FND'))

    users = list(store.list_users())
    assert len(users) == 1

    py.test.raises(NoUserError, "store.get(User('FND'))")
コード例 #14
0
def test_simple_get():
    user = User("cdent")
    user = store.get(user)

    assert user.note == "foo"
    assert user.check_password("cowpig")
    assert sorted(user.list_roles()) == ["ADMIN", "BOSS"]
    assert not user.check_password("pigcow")
コード例 #15
0
def test_simple_get():
    user = User('cdent')
    user = store.get(user)

    assert user.note == 'foo'
    assert user.check_password('cowpig')
    assert sorted(user.list_roles()) == ['ADMIN', 'BOSS']
    assert not user.check_password('pigcow')
コード例 #16
0
ファイル: test_store_user.py プロジェクト: sgml/tiddlyweb
def test_simple_get():
    user = User('cdent')
    user = store.get(user)

    assert user.note == 'foo'
    assert user.check_password('cowpig')
    assert sorted(user.list_roles()) == ['ADMIN', 'BOSS']
    assert not user.check_password('pigcow')
コード例 #17
0
def test_put_get_user():
    user = User('testone')
    user.add_role('monkey')
    store.put(user)

    read_user = User('testone')
    read_user = store.get(read_user)

    assert read_user.list_roles() == ['monkey']
コード例 #18
0
def test_put_get_user():
    user = User('testone')
    user.add_role('monkey')
    store.put(user)

    read_user = User('testone')
    read_user = store.get(read_user)

    assert read_user.list_roles() == ['monkey']
コード例 #19
0
ファイル: __init__.py プロジェクト: ralphbtp/tiddlyhoster
def user_page(environ, start_response):
    userpage = environ['wsgiorg.routing_args'][1]['userpage']
    user = environ['tiddlyweb.usersign']

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ['tiddlyweb.store']

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass # roles will be empty
    if 'MEMBER' not in userpage_user.list_roles():
        raise HTTP404('%s has no page' % userpage)

    user_friend_names = get_friends(store, user['name'])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage),
            user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage),
            user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {'bags': kept_bags,
            'user_friends': user_friend_names,
            'friends': friends,
            'recipes': kept_recipes,
            'favorites': kept_favorites,
            'bookmarks': kept_bookmarks,
            'home': userpage,
            'profile': profile_html,
            'notice': {'html': notice_html,
                'modified': notice_tiddler.modified},
            'title': userpage,
            'email': email,
            'email_md5': email_md5,
            'user': get_user_object(environ)}

    return send_template(environ, 'profile.html', data)
コード例 #20
0
ファイル: __init__.py プロジェクト: pmario/tiddlyhoster
def user_page(environ, start_response):
    userpage = environ["wsgiorg.routing_args"][1]["userpage"]
    user = environ["tiddlyweb.usersign"]

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ["tiddlyweb.store"]

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass  # roles will be empty
    if "MEMBER" not in userpage_user.list_roles():
        raise HTTP404("%s has no page" % userpage)

    user_friend_names = get_friends(store, user["name"])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage), user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage), user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {
        "bags": kept_bags,
        "user_friends": user_friend_names,
        "friends": friends,
        "recipes": kept_recipes,
        "favorites": kept_favorites,
        "bookmarks": kept_bookmarks,
        "home": userpage,
        "profile": profile_html,
        "notice": {"html": notice_html, "modified": notice_tiddler.modified},
        "title": userpage,
        "email": email,
        "email_md5": email_md5,
        "user": get_user_object(environ),
    }

    return send_template(environ, "profile.html", data)
コード例 #21
0
ファイル: __init__.py プロジェクト: cdent/wiki-data
def update_user_form(environ, start_response, message=None, success=False):
    if message is None:
        message = ''
    logging.debug('in update_user_form, message: '+message)
    query = environ['tiddlyweb.query']
    store = environ['tiddlyweb.store']
    username = query.get('username', [None])[0]

    userinfo = {}
    if not username:
        template = templating.get_template(environ, 'user_start_update.html')
    else: 
        # get the user info out of the store and magicuser
        user = User(username)
        try:
            user = store.get(user)
        except NoUserError:
            pass
        userinfo['email'] = user.usersign
        try:
            userinfo['tier'] = [role for role in user.list_roles() if role.startswith('tier')][0]
        except IndexError:
            userinfo['tier'] = ''

        bag_name = environ['tiddlyweb.config'].get('magicuser.bag', 'MAGICUSER')
        tiddler = Tiddler(user.usersign, bag_name)
        try:
            tiddler = store.get(tiddler)
        except NoTiddlerError:
            pass
        country = tiddler.fields.get('country', '')
        company = tiddler.fields.get('company', '')
        name = tiddler.fields.get('name', '')
        # Get the expiration time.
        now = time.time()
        expiration = float(tiddler.fields.get('expiry', 0))
        if expiration != 0:
            expiration = (expiration - now) / (24 * 60 * 60)
        userinfo['country'] = country
        userinfo['company'] = company
        userinfo['name'] = name
        userinfo['expiry'] = expiration

        template = templating.get_template(environ, 'user_update.html')

    start_response('200 OK', [
        ('Content-Type', 'text/html'),
        ('Pragma', 'no-cache')
        ])

    form_starter = userinfo
    
    logging.debug('rendering with message:'+message)
    return template.render(commonVars=templating.common_vars(environ),
            message=message, success=success, form=form_starter)
コード例 #22
0
ファイル: __init__.py プロジェクト: jayfresh/wiki-data
def update_user_form(environ, start_response, message=None, success=False):
    if message is None:
        message = ""
    logging.debug("in update_user_form, message: " + message)
    query = environ["tiddlyweb.query"]
    store = environ["tiddlyweb.store"]
    username = query.get("username", [None])[0]

    userinfo = {}
    if not username:
        template = templating.get_template(environ, "user_start_update.html")
    else:
        # get the user info out of the store and magicuser
        user = User(username)
        try:
            user = store.get(user)
        except NoUserError:
            pass
        userinfo["email"] = user.usersign
        try:
            userinfo["tier"] = [role for role in user.list_roles() if role.startswith("tier")][0]
        except IndexError:
            userinfo["tier"] = ""

        bag_name = environ["tiddlyweb.config"].get("magicuser.bag", "MAGICUSER")
        tiddler = Tiddler(user.usersign, bag_name)
        try:
            tiddler = store.get(tiddler)
        except NoTiddlerError:
            pass
        country = tiddler.fields.get("country", "")
        company = tiddler.fields.get("company", "")
        name = tiddler.fields.get("name", "")
        # Get the expiration time.
        now = time.time()
        expiration = float(tiddler.fields.get("expiry", 0))
        if expiration != 0:
            expiration = (expiration - now) / (24 * 60 * 60)
        userinfo["country"] = country
        userinfo["company"] = company
        userinfo["name"] = name
        userinfo["expiry"] = expiration

        template = templating.get_template(environ, "user_update.html")

    start_response("200 OK", [("Content-Type", "text/html"), ("Pragma", "no-cache")])

    form_starter = userinfo

    logging.debug("rendering with message:" + message)
    return template.render(
        commonVars=templating.common_vars(environ), message=message, success=success, form=form_starter
    )
コード例 #23
0
def _proxy_user(environ, username):
    """
    Load up the correct user information for the user being proxied
    in a mapping.
    """
    store = environ['tiddlyweb.store']
    try:
        user = User(username)
        user = store.get(user)
        return {'name': user.usersign, 'roles': user.list_roles()}
    except StoreError, exc:
        raise HTTP400('invalid mapping: %s' % exc)
コード例 #24
0
ファイル: test_unicode.py プロジェクト: cdent/tiddlywebredis
def test_users():
    userc = User(name)
    userc.set_password(name)
    userc.add_role('ADMIN')
    userc.note = 'A simple programmer of matter'

    store.put(userc)

    user2 = store.get(User(name))
    assert user2.usersign == userc.usersign
    assert user2.check_password(name)
    assert user2.list_roles() == userc.list_roles()
    assert user2.note == userc.note
コード例 #25
0
ファイル: http_basic.py プロジェクト: angeluseve/tiddlyweb
 def extract(self, environ, start_response):
     """
     Look in the request for an Authorization header.
     """
     user_info = environ.get('HTTP_AUTHORIZATION', None)
     if user_info is None:
         return False
     if user_info.startswith('Basic'):
         user_info = user_info.strip().split(' ')[1]
         candidate_username, password = b64decode(user_info).split(':')
         try:
             store = environ['tiddlyweb.store']
             user = User(candidate_username)
             user = store.get(user)
             if user.check_password(password):
                 return {"name": user.usersign, "roles": user.list_roles()}
         except (NoUserError, StoreMethodNotImplemented):
             pass
     return False
コード例 #26
0
ファイル: simple_cookie.py プロジェクト: angeluseve/tiddlyweb
    def extract(self, environ, start_response):
        """
        Extract the cookie, if there, from the headers
        and attempt to validate its contents.
        """
        try:
            user_cookie = environ['HTTP_COOKIE']
            logging.debug('simple_cookie looking at cookie string: %s' % user_cookie)
            cookie = Cookie.SimpleCookie()
            cookie.load(user_cookie)
            cookie_value = cookie['tiddlyweb_user'].value
            secret = environ['tiddlyweb.config']['secret']
            usersign, cookie_secret = cookie_value.split(':')
            store = environ['tiddlyweb.store']

            if cookie_secret == sha('%s%s' % (usersign, secret)).hexdigest():
                user = User(usersign)
                try:
                    user = store.get(user)
                except (StoreMethodNotImplemented, NoUserError):
                    pass
                return {"name": user.usersign, "roles": user.list_roles()}
        except Cookie.CookieError, exc:
            raise HTTP400('malformed cookie: %s' % exc)
コード例 #27
0
def test_make_a_bunch():
    for x in xrange(RANGE):
        bag_name = u'bag%s' % x
        recipe_name = u'recipe%s' % x
        tiddler_name = u'tiddler%s' % x
        recipe_list = [(bag_name, '')]
        tiddler_text = u'hey ho %s' % x
        field_name = u'field%s' % x
        field_name2 = u'fieldone%s' % x
        tag_name = u'tag%s' % x
        user_name = u'user%s' % x
        user_pass = u'pass%s' % x
        user_note = u'note%s' % x
        user_roles = [u'rolehold', u'role%s' % x]

        bag = Bag(bag_name)
        bag.policy.owner = u'owner%s' % x
        bag.policy.read = [u'hi%s' % x, u'andextra']
        bag.policy.manage = [u'R:hi%s' % x, u'andmanage']
        store.put(bag)
        recipe = Recipe(recipe_name)
        recipe.policy.owner = u'owner%s' % x
        recipe.policy.read = [u'hi%s' % x, u'andextra']
        recipe.policy.manage = [u'R:hi%s' % x, u'andmanage']
        recipe.set_recipe(recipe_list)
        store.put(recipe)
        tiddler = Tiddler(tiddler_name, bag_name)
        tiddler.text = tiddler_text
        tiddler.fields[field_name] = field_name
        tiddler.fields[field_name2] = field_name2
        tiddler.fields['server.host'] = 'gunky'
        tiddler.tags = [tag_name]
        store.put(tiddler)
        store.put(tiddler)
        user = User(user_name)
        user.set_password(user_pass)
        user.note = user_note
        for role in user_roles:
            user.add_role(role)
        store.put(user)

    bags = [bag.name for bag in store.list_bags()]
    recipes = [recipe.name for recipe in store.list_recipes()]
    users = [user.usersign for user in store.list_users()]
    assert len(bags) == RANGE
    assert len(recipes) == RANGE
    assert len(users) == RANGE
    for x in xrange(RANGE):
        bname = 'bag%s' % x
        rname = 'recipe%s' % x
        uname = 'user%s' % x
        assert bname in bags
        assert rname in recipes
        assert uname in users

    tiddler = store.get(Tiddler(u'tiddler0', u'bag0'))
    assert tiddler.fields['field0'] == 'field0'
    assert tiddler.fields['fieldone0'] == 'fieldone0'

    bag = Bag(u'bag0')
    bag = store.get(bag)
    tiddlers = []
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.append(store.get(tiddler))
    assert len(tiddlers) == 1
    assert tiddlers[0].title == 'tiddler0'
    assert tiddlers[0].fields['field0'] == 'field0'
    assert tiddlers[0].fields['fieldone0'] == 'fieldone0'
    assert tiddlers[0].tags == ['tag0']
    assert sorted(bag.policy.read) == ['andextra', 'hi0']
    assert sorted(bag.policy.manage) == ['R:hi0', u'andmanage']
    assert bag.policy.owner == 'owner0'

    user = User(u'user1')
    user = store.get(user)
    assert user.usersign == 'user1'
    assert user.check_password('pass1')
    assert user.note == 'note1'
    assert 'role1' in user.list_roles()
    assert 'rolehold' in user.list_roles()

    recipe = Recipe(u'recipe2')
    recipe = store.get(recipe)
    assert recipe.name == 'recipe2'
    bags = [bag_name for bag_name, filter in recipe.get_recipe()]
    assert len(bags) == 1
    assert 'bag2' in bags
    assert sorted(recipe.policy.read) == ['andextra', 'hi2']
    assert sorted(recipe.policy.manage) == ['R:hi2', u'andmanage']
    assert recipe.policy.owner == 'owner2'

    recipe.policy.manage = [u'andmanage']
    store.put(recipe)

    recipe = Recipe (u'recipe2')
    recipe = store.get(recipe)
    assert recipe.policy.manage == [u'andmanage']

    # delete the above things
    store.delete(bag)
    py.test.raises(NoBagError, 'store.delete(bag)')
    py.test.raises(NoBagError, 'store.get(bag)')
    store.delete(recipe)
    py.test.raises(NoRecipeError, 'store.delete(recipe)')
    py.test.raises(NoRecipeError, 'store.get(recipe)')
    store.delete(user)
    py.test.raises(NoUserError, 'store.delete(user)')
    py.test.raises(NoUserError, 'store.get(user)')

    tiddler = Tiddler(u'tiddler9', u'bag9')
    store.get(tiddler)
    assert tiddler.bag == 'bag9'
    assert tiddler.text == 'hey ho 9'
    assert tiddler.tags == ['tag9']
    assert tiddler.fields['field9'] == 'field9'
    assert 'server.host' not in tiddler.fields
    store.delete(tiddler)
    py.test.raises(NoTiddlerError, 'store.delete(tiddler)')
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')
コード例 #28
0
def test_addrole():
    handle(['', u'addrole', u'cdent', u'pig'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert 'cow' in the_user.list_roles()
コード例 #29
0
ファイル: test_commands.py プロジェクト: sgml/tiddlyweb
def test_addrole():
    handle(['', u'addrole', u'cdent', u'pig'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert 'cow' in the_user.list_roles()
コード例 #30
0
    def extract(self, environ, start_response):
        """
        Extract the cookie, if there, from the headers
        and attempt to validate its contents.
        """
        try:
            user_cookie = environ['HTTP_COOKIE']
            logging.debug('simple_cookie looking at cookie string: %s',
                          user_cookie)
            cookie = Cookie.SimpleCookie()
            cookie.load(user_cookie)
            cookie_value = cookie['tiddlyweb_user'].value
            secret = environ['tiddlyweb.config']['secret']
            usersign, cookie_secret = cookie_value.rsplit(':', 1)
            store = environ['tiddlyweb.store']

            if cookie_secret == sha('%s%s' % (usersign, secret)).hexdigest():
                user = User(usersign)
                try:
                    user = store.get(user)
                except (StoreMethodNotImplemented, NoUserError):
                    pass

                #check that the user has the requisite bags
                #if they don't, create them
                public_bag = '%s_public' % user.usersign
                private_bag = '%s_private' % user.usersign
                space = {
                    'bags': {
                        public_bag: {
                            'policy': {
                                "read": [],
                                "create": [user.usersign],
                                "manage": [user.usersign, "R:ADMIN"],
                                "accept": [],
                                "write": [user.usersign],
                                "owner": user.usersign,
                                "delete": [user.usersign, "R:ADMIN"]
                            }
                        },
                        private_bag: {
                            'policy': {
                                "read": [user.usersign],
                                "create": [user.usersign],
                                "manage": [user.usersign, "R:ADMIN"],
                                "accept": [],
                                "write": [user.usersign],
                                "owner": user.usersign,
                                "delete": [user.usersign]
                            }
                        }
                    },
                    'recipes': {
                        '%s' % user.usersign: {
                            'recipe': [['system', ''], [public_bag, ''],
                                       [private_bag, '']],
                            'policy': {
                                "read": [user.usersign],
                                "create": [user.usersign],
                                "manage": [user.usersign, "R:ADMIN"],
                                "accept": [],
                                "write": [user.usersign],
                                "owner": user.usersign,
                                "delete": [user.usersign]
                            }
                        }
                    }
                }
                user_space = Space(environ)
                user_space.create_space(space)

                return {"name": user.usersign, "roles": user.list_roles()}
        except Cookie.CookieError, exc:
            raise HTTP400('malformed cookie: %s' % exc)
コード例 #31
0
def test_make_a_bunch():
    for x in xrange(RANGE):
        bag_name = u'bag%s' % x
        recipe_name = u'recipe%s' % x
        tiddler_name = u'tiddler%s' % x
        recipe_list = [(bag_name, '')]
        tiddler_text = u'hey ho %s' % x
        field_name = u'field%s' % x
        field_name2 = u'fieldone%s' % x
        tag_name = u'tag%s' % x
        user_name = u'user%s' % x
        user_pass = u'pass%s' % x
        user_note = u'note%s' % x
        user_roles = [u'rolehold', u'role%s' % x]

        bag = Bag(bag_name)
        bag.policy.owner = u'owner%s' % x
        bag.policy.read = [u'hi%s' % x, u'andextra']
        bag.policy.manage = [u'R:hi%s' % x, u'andmanage']
        store.put(bag)
        recipe = Recipe(recipe_name)
        recipe.policy.owner = u'owner%s' % x
        recipe.policy.read = [u'hi%s' % x, u'andextra']
        recipe.policy.manage = [u'R:hi%s' % x, u'andmanage']
        recipe.set_recipe(recipe_list)
        store.put(recipe)
        tiddler = Tiddler(tiddler_name, bag_name)
        tiddler.text = tiddler_text
        tiddler.fields[field_name] = field_name
        tiddler.fields[field_name2] = field_name2
        tiddler.fields['server.host'] = 'gunky'
        tiddler.tags = [tag_name]
        store.put(tiddler)
        store.put(tiddler)
        user = User(user_name)
        user.set_password(user_pass)
        user.note = user_note
        for role in user_roles:
            user.add_role(role)
        store.put(user)

    bags = [bag.name for bag in store.list_bags()]
    recipes = [recipe.name for recipe in store.list_recipes()]
    users = [user.usersign for user in store.list_users()]
    assert len(bags) == RANGE
    assert len(recipes) == RANGE
    assert len(users) == RANGE
    for x in xrange(RANGE):
        bname = 'bag%s' % x
        rname = 'recipe%s' % x
        uname = 'user%s' % x
        assert bname in bags
        assert rname in recipes
        assert uname in users

    tiddler = store.get(Tiddler(u'tiddler0', u'bag0'))
    assert tiddler.fields[u'field0'] == u'field0'
    assert tiddler.fields[u'fieldone0'] == u'fieldone0'

    bag = Bag(u'bag0')
    bag = store.get(bag)
    tiddlers = []
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.append(store.get(tiddler))
    assert len(tiddlers) == 1
    assert tiddlers[0].title == 'tiddler0'
    assert tiddlers[0].fields['field0'] == 'field0'
    assert tiddlers[0].fields['fieldone0'] == 'fieldone0'
    assert tiddlers[0].tags == ['tag0']
    assert sorted(bag.policy.read) == ['andextra', 'hi0']
    assert sorted(bag.policy.manage) == ['R:hi0', u'andmanage']
    assert bag.policy.owner == 'owner0'

    user = User(u'user1')
    user = store.get(user)
    assert user.usersign == 'user1'
    assert user.check_password('pass1')
    assert user.note == 'note1'
    assert 'role1' in user.list_roles()
    assert 'rolehold' in user.list_roles()

    recipe = Recipe(u'recipe2')
    recipe = store.get(recipe)
    assert recipe.name == 'recipe2'
    bags = [bag_name for bag_name, filter in recipe.get_recipe()]
    assert len(bags) == 1
    assert 'bag2' in bags
    assert sorted(recipe.policy.read) == ['andextra', 'hi2']
    assert sorted(recipe.policy.manage) == ['R:hi2', u'andmanage']
    assert recipe.policy.owner == 'owner2'

    recipe.policy.manage = [u'andmanage']
    store.put(recipe)

    recipe = Recipe(u'recipe2')
    recipe = store.get(recipe)
    assert recipe.policy.manage == [u'andmanage']

    # delete the above things
    store.delete(bag)
    py.test.raises(NoBagError, 'store.delete(bag)')
    py.test.raises(NoBagError, 'store.get(bag)')
    store.delete(recipe)
    py.test.raises(NoRecipeError, 'store.delete(recipe)')
    py.test.raises(NoRecipeError, 'store.get(recipe)')
    store.delete(user)
    py.test.raises(NoUserError, 'store.delete(user)')
    py.test.raises(NoUserError, 'store.get(user)')

    tiddler = Tiddler(u'tiddler9', u'bag9')
    store.get(tiddler)
    assert tiddler.bag == 'bag9'
    assert tiddler.text == 'hey ho 9'
    assert tiddler.tags == ['tag9']
    assert tiddler.fields['field9'] == 'field9'
    assert 'server.host' not in tiddler.fields
    store.delete(tiddler)
    py.test.raises(NoTiddlerError, 'store.delete(tiddler)')
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')
コード例 #32
0
def test_make_a_bunch():
    for x in xrange(RANGE):
        bag_name = u"bag%s" % x
        recipe_name = u"recipe%s" % x
        tiddler_name = u"tiddler%s" % x
        recipe_list = [(bag_name, "")]
        tiddler_text = u"hey ho %s" % x
        field_name = u"field%s" % x
        tag_name = u"tag%s" % x
        user_name = u"user%s" % x
        user_pass = u"pass%s" % x
        user_note = u"note%s" % x
        user_roles = [u"rolehold", u"role%s" % x]

        bag = Bag(bag_name)
        bag.policy.owner = u"owner%s" % x
        bag.policy.read = [u"hi%s" % x, u"andextra"]
        bag.policy.manage = [u"R:hi%s" % x, u"andmanage"]
        store.put(bag)
        recipe = Recipe(recipe_name)
        recipe.policy.owner = u"owner%s" % x
        recipe.policy.read = [u"hi%s" % x, u"andextra"]
        recipe.policy.manage = [u"R:hi%s" % x, u"andmanage"]
        recipe.set_recipe(recipe_list)
        store.put(recipe)
        tiddler = Tiddler(tiddler_name, bag_name)
        tiddler.text = tiddler_text
        tiddler.fields[field_name] = field_name
        tiddler.fields["server.host"] = u"gunky"
        tiddler.tags = [tag_name]
        store.put(tiddler)
        user = User(user_name)
        user.set_password(user_pass)
        user.note = user_note
        for role in user_roles:
            user.add_role(role)
        store.put(user)

    bags = [bag.name for bag in store.list_bags()]
    recipes = [recipe.name for recipe in store.list_recipes()]
    users = [user.usersign for user in store.list_users()]
    assert len(bags) == RANGE
    assert len(recipes) == RANGE
    assert len(users) == RANGE
    for x in xrange(RANGE):
        bname = u"bag%s" % x
        rname = u"recipe%s" % x
        uname = u"user%s" % x
        assert bname in bags
        assert rname in recipes
        assert uname in users

    bag = Bag("bag0")
    bag = store.get(bag)
    tiddlers = []
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.append(store.get(tiddler))
    assert len(tiddlers) == 1
    assert tiddlers[0].title == "tiddler0"
    assert tiddlers[0].fields["field0"] == "field0"
    assert tiddlers[0].tags == ["tag0"]
    assert sorted(bag.policy.read) == ["andextra", "hi0"]
    assert sorted(bag.policy.manage) == ["R:hi0", "andmanage"]
    assert bag.policy.owner == "owner0"

    bag = Bag("bag0")
    bag = store.get(bag)
    bag.policy.read.remove("hi0")
    store.put(bag)
    bag = Bag("bag0")
    bag = store.get(bag)
    assert bag.policy.read == [u"andextra"]

    bag = Bag("bag0")
    bag = store.get(bag)
    bag.policy.read.append(u"hi0")
    store.put(bag)
    bag = Bag("bag0")
    bag = store.get(bag)
    assert sorted(bag.policy.read) == ["andextra", "hi0"]

    user = User("user1")
    user = store.get(user)
    assert user.usersign == "user1"
    assert user.check_password("pass1")
    assert user.note == "note1"
    assert "role1" in user.list_roles()
    assert "rolehold" in user.list_roles()

    recipe = Recipe("recipe2")
    recipe = store.get(recipe)
    assert recipe.name == "recipe2"
    bags = [bag_name for bag_name, filter in recipe.get_recipe()]
    assert len(bags) == 1
    assert "bag2" in bags
    assert sorted(recipe.policy.read) == ["andextra", "hi2"]
    assert sorted(recipe.policy.manage) == ["R:hi2", "andmanage"]
    assert recipe.policy.owner == "owner2"

    recipe.policy.manage = [u"andmanage"]
    store.put(recipe)

    recipe = Recipe("recipe2")
    recipe = store.get(recipe)
    assert recipe.policy.manage == ["andmanage"]

    # delete the above things
    store.delete(bag)
    py.test.raises(NoBagError, "store.delete(bag)")
    py.test.raises(NoBagError, "store.get(bag)")
    store.delete(recipe)
    py.test.raises(NoRecipeError, "store.delete(recipe)")
    py.test.raises(NoRecipeError, "store.get(recipe)")
    store.delete(user)
    py.test.raises(NoUserError, "store.delete(user)")
    py.test.raises(NoUserError, "store.get(user)")

    tiddler = Tiddler("tiddler9", "bag9")
    store.get(tiddler)
    assert tiddler.bag == "bag9"
    assert tiddler.text == "hey ho 9"
    assert tiddler.tags == ["tag9"]
    assert tiddler.fields["field9"] == "field9"
    assert "server.host" not in tiddler.fields
    store.delete(tiddler)
    py.test.raises(NoTiddlerError, "store.delete(tiddler)")
    py.test.raises(NoTiddlerError, "store.get(tiddler)")