Exemplo n.º 1
0
def test_create_spaces():
    cookie = get_auth('thingone', 'how')
    response, content = http.request('http://0.0.0.0:8080/spaces/thing',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie})
    assert response['status'] == '201'

    response, content = http.request(
            'http://thing.0.0.0.0:8080/bags/thing_private/tiddlers/thingone',
            method='PUT',
            headers={'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie},
            body='{"text": "thingone"}')
    assert response['status'] == '204'

    cookie = get_auth('thingtwo', 'how')
    response, content = http.request('http://0.0.0.0:8080/spaces/foo',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie})
    assert response['status'] == '201'

    response, content = http.request(
            'http://foo.0.0.0.0:8080/bags/foo_private/tiddlers/thingtwo',
            method='PUT',
            headers={'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie},
            body='{"text": "thingtwo"}')
    assert response['status'] == '204'
Exemplo n.º 2
0
def test_create_spaces():
    cookie = get_auth('thingone', 'how')
    response, content = http.request('http://0.0.0.0:8080/spaces/thing',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie})
    assert response['status'] == '201'

    response, content = http.request(
            'http://thing.0.0.0.0:8080/bags/thing_private/tiddlers/thingone',
            method='PUT',
            headers={'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie},
            body='{"text": "thingone"}')
    assert response['status'] == '204'

    cookie = get_auth('thingtwo', 'how')
    response, content = http.request('http://0.0.0.0:8080/spaces/foo',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie})
    assert response['status'] == '201'

    response, content = http.request(
            'http://foo.0.0.0.0:8080/bags/foo_private/tiddlers/thingtwo',
            method='PUT',
            headers={'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie},
            body='{"text": "thingtwo"}')
    assert response['status'] == '204'
Exemplo n.º 3
0
def test_create_spaces():
    cookie = get_auth("thingone", "how")
    response, content = http.request(
        "http://0.0.0.0:8080/spaces/thing", method="PUT", headers={"Cookie": 'tiddlyweb_user="******"' % cookie}
    )
    assert response["status"] == "201"

    response, content = http.request(
        "http://thing.0.0.0.0:8080/bags/thing_private/tiddlers/thingone",
        method="PUT",
        headers={"Content-Type": "application/json", "Cookie": 'tiddlyweb_user="******"' % cookie},
        body='{"text": "thingone"}',
    )
    assert response["status"] == "204"

    cookie = get_auth("thingtwo", "how")
    response, content = http.request(
        "http://0.0.0.0:8080/spaces/foo", method="PUT", headers={"Cookie": 'tiddlyweb_user="******"' % cookie}
    )
    assert response["status"] == "201"

    response, content = http.request(
        "http://foo.0.0.0.0:8080/bags/foo_private/tiddlers/thingtwo",
        method="PUT",
        headers={"Content-Type": "application/json", "Cookie": 'tiddlyweb_user="******"' % cookie},
        body='{"text": "thingtwo"}',
    )
    assert response["status"] == "204"
Exemplo n.º 4
0
def test_subscription():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    subscriptions = simplejson.dumps({'subscriptions': ['extra']})

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
                                     method='POST',
                                     headers={
                                         'Content-Type': 'application/json',
                                     },
                                     body=subscriptions)
    assert response['status'] == '403'

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
                                     method='POST',
                                     headers={
                                         'Content-Type': 'application/json',
                                         'Cookie':
                                         'tiddlyweb_user="******"' % cookie,
                                     },
                                     body='')
    assert response['status'] == '409'

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
                                     method='POST',
                                     headers={
                                         'Content-Type': 'application/json',
                                         'Cookie':
                                         'tiddlyweb_user="******"' % cookie,
                                     },
                                     body=subscriptions)
    assert response['status'] == '204'
Exemplo n.º 5
0
def test_register_user():
    data = {'username': '******', 'password': '******'}
    body = simplejson.dumps(data)
    response, content = http.request('http://0.0.0.0:8080/users',
            method='POST',
            headers={'Content-Type': 'application/json'},
            body=body)
    assert response['status'] == '201'

    response, content = http.request('http://0.0.0.0:8080/users',
            method='POST',
            headers={'Content-Type': 'application/json'},
            body=body)
    assert response['status'] == '409'
    assert 'exists' in content

    cookie = get_auth('cdent', 'cowpig')
    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT')
    assert response['status'] == '201'

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT')
    assert response['status'] == '409'
Exemplo n.º 6
0
def test_register_user():
    data = {'username': '******', 'password': '******'}
    body = simplejson.dumps(data)
    response, content = http.request(
        'http://0.0.0.0:8080/users',
        method='POST',
        headers={'Content-Type': 'application/json'},
        body=body)
    assert response['status'] == '201'

    response, content = http.request(
        'http://0.0.0.0:8080/users',
        method='POST',
        headers={'Content-Type': 'application/json'},
        body=body)
    assert response['status'] == '409'
    assert 'exists' in content

    cookie = get_auth('cdent', 'cowpig')
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/cdent',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT')
    assert response['status'] == '201'

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/cdent',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT')
    assert response['status'] == '409'
Exemplo n.º 7
0
def test_subscription():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    subscriptions = simplejson.dumps({'subscriptions': ['extra']})

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            method='POST',
            headers={
                'Content-Type': 'application/json',
                },
            body=subscriptions)
    assert response['status'] == '403'

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            method='POST',
            headers={
                'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie,
                },
            body='')
    assert response['status'] == '409'

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            method='POST',
            headers={
                'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie,
                },
            body=subscriptions)
    assert response['status'] == '204'
Exemplo n.º 8
0
def test_case_in_space():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/CeXtRa',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            )
    assert response['status'] == '409'
Exemplo n.º 9
0
def test_case_in_space():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/CeXtRa',
        method='PUT',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
    )
    assert response['status'] == '409'
Exemplo n.º 10
0
def test_reserved_space_name():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/www',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            )
    assert response['status'] == '409'
    assert 'Invalid space name: www' in content
Exemplo n.º 11
0
def test_status_space_auth():
    user_cookie = get_auth('foo', 'foobar')
    response, content = http.request('http://thing.0.0.0.0:8080/status',
            headers={'Cookie': 'tiddlyweb_user="******"' % user_cookie})

    assert response['status'] == '200'
    info = simplejson.loads(content)
    assert info['username'] == 'foo'
    assert info['space']['name'] == 'thing'
    assert info['space']['recipe'] == 'thing_private'
Exemplo n.º 12
0
def test_reserved_space_name():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/www',
        method='PUT',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
    )
    assert response['status'] == '409'
    assert 'Invalid space name: www' in content
Exemplo n.º 13
0
def test_foo_tiddlers_guest():
    cookie = get_auth('thingone', 'how')
    response, content = http.request('http://foo.0.0.0.0:8080/',
                                     method='GET',
                                     headers={'Accept': 'application/json'})
    guest_content = content

    response, content = http.request('http://foo.0.0.0.0:8080/',
                                     headers={
                                         'Accept': 'application/json',
                                         'Cookie':
                                         'tiddlyweb_user="******"' % cookie
                                     })
    user_content = content
    assert guest_content == user_content

    response, content = http.request(
        'http://thing.0.0.0.0:8080/bags/thing_private/tiddlers',
        method='GET',
        headers={
            'Accept': 'application/json',
            'Cookie': 'tiddlyweb_user="******"' % cookie
        })
    thing_content = content

    response, content = http.request(
        'http://foo.0.0.0.0:8080/bags/thing_private/tiddlers',
        method='GET',
        headers={
            'Accept': 'application/json',
            'Cookie': 'tiddlyweb_user="******"' % cookie
        })
    assert response['status'] == '404'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/bags/thing_private/tiddlers',
        method='GET',
        headers={
            'Accept': 'application/json',
            'X-ControlView': 'false',
            'Cookie': 'tiddlyweb_user="******"' % cookie
        })
    assert response['status'] == '401'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/bags/thing_private/tiddlers/more',
        method='PUT',
        headers={
            'Content-Type': 'application/json',
            'X-ControlView': 'false',
            'Cookie': 'tiddlyweb_user="******"' % cookie
        },
        body='{"text": "hi"}')
    assert response['status'] == '403'
Exemplo n.º 14
0
def test_status_space_auth():
    user_cookie = get_auth('foo', 'foobar')
    response, content = http.request(
        'http://thing.0.0.0.0:8080/status',
        headers={'Cookie': 'tiddlyweb_user="******"' % user_cookie})

    assert response['status'] == '200'
    info = simplejson.loads(content)
    assert info['username'] == 'foo'
    assert info['space']['name'] == 'thing'
    assert info['space']['recipe'] == 'thing_private'
Exemplo n.º 15
0
def test_delete_member():
    cookie = get_auth('fnd', 'bird')
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members/psd',
        method='DELETE',
    )
    assert response['status'] == '403'

    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/psd',
        method='DELETE',
    )
    assert response['status'] == '403'

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members/psd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='DELETE',
    )
    assert response['status'] == '403'

    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/psd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='DELETE',
    )
    assert response['status'] == '204'

    # delete self
    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/fnd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='DELETE',
    )
    assert response['status'] == '204'

    bag = store.get(Bag('extra_private'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    bag = store.get(Bag('extra_archive'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']
Exemplo n.º 16
0
def test_mutual_subscription():
    """
    Subscription should not result in the same bag showing up more than once.
    """
    response, content = add_subscription('fnd', 'cdent', cookie=get_auth('cdent', 'bar'))
    assert response['status'] == '204'

    recipe = store.get(Recipe('cdent_public'))
    bags = [bag for bag, filter in recipe.get_recipe()]
    unique_bags = list(set(bags))
    assert len(bags) == len(unique_bags)
def test_handler_responds_with_400_when_content_type_not_present():
    cookie = get_auth('ben', 'mocha')
    data = {'mapped_user': '******'}

    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/map_user/ben',
        method='POST',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        body=dumps(data))

    assert response['status'] == '400'
Exemplo n.º 18
0
def test_mutual_subscription():
    """
    Subscription should not result in the same bag showing up more than once.
    """
    response, content = add_subscription('fnd',
                                         'cdent',
                                         cookie=get_auth('cdent', 'bar'))
    assert response['status'] == '204'

    recipe = store.get(Recipe('cdent_public'))
    bags = [bag for bag, filter in recipe.get_recipe()]
    unique_bags = list(set(bags))
    assert len(bags) == len(unique_bags)
Exemplo n.º 19
0
def add_subscription(subscribed, subscriber, cookie=None, unsubscribe=False):
    if not cookie:
        cookie = get_auth('fnd', 'foo')
    http = httplib2.Http()
    if unsubscribe:
        subscriptions = simplejson.dumps({'unsubscriptions': [subscribed]})
    else:
        subscriptions = simplejson.dumps({'subscriptions': [subscribed]})
    return http.request('http://0.0.0.0:8080/spaces/%s' % subscriber,
        method='POST', headers={
            'Content-Type': 'application/json',
            'Cookie': 'tiddlyweb_user="******"' % cookie,
        }, body=subscriptions)
Exemplo n.º 20
0
def test_status_base_auth():
    user = User('foo')
    user.set_password('foobar')
    store.put(user)
    user_cookie = get_auth('foo', 'foobar')
    change_space_member(store, 'thing', add='foo')

    response, content = http.request('http://0.0.0.0:8080/status',
            headers={'Cookie': 'tiddlyweb_user="******"' % user_cookie})

    assert response['status'] == '200'
    info = simplejson.loads(content)
    assert info['username'] == 'foo'
    assert 'space' not in info
Exemplo n.º 21
0
def test_delete_member():
    cookie = get_auth('fnd', 'bird')
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/psd',
            method='DELETE',
            )
    assert response['status'] == '403'

    response, content = http.request('http://extra.0.0.0.0:8080/spaces/extra/members/psd',
            method='DELETE',
            )
    assert response['status'] == '403'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/psd',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='DELETE',
            )
    assert response['status'] == '403'

    response, content = http.request('http://extra.0.0.0.0:8080/spaces/extra/members/psd',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='DELETE',
            )
    assert response['status'] == '204'

    # delete self
    response, content = http.request('http://extra.0.0.0.0:8080/spaces/extra/members/fnd',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='DELETE',
            )
    assert response['status'] == '204'

    bag = store.get(Bag('extra_private'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    bag = store.get(Bag('extra_archive'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']
Exemplo n.º 22
0
def add_subscription(subscribed, subscriber, cookie=None, unsubscribe=False):
    if not cookie:
        cookie = get_auth('fnd', 'foo')
    http = httplib2.Http()
    if unsubscribe:
        subscriptions = simplejson.dumps({'unsubscriptions': [subscribed]})
    else:
        subscriptions = simplejson.dumps({'subscriptions': [subscribed]})
    return http.request('http://0.0.0.0:8080/spaces/%s' % subscriber,
                        method='POST',
                        headers={
                            'Content-Type': 'application/json',
                            'Cookie': 'tiddlyweb_user="******"' % cookie,
                        },
                        body=subscriptions)
Exemplo n.º 23
0
def test_status_base_auth():
    user = User('foo')
    user.set_password('foobar')
    store.put(user)
    user_cookie = get_auth('foo', 'foobar')
    change_space_member(store, 'thing', add='foo')

    response, content = http.request(
        'http://0.0.0.0:8080/status',
        headers={'Cookie': 'tiddlyweb_user="******"' % user_cookie})

    assert response['status'] == '200'
    info = simplejson.loads(content)
    assert info['username'] == 'foo'
    assert 'space' not in info
def test_handler_responds_with_415_when_content_type_is_invalid():
    cookie = get_auth('chris', 'piccolo')
    data = {'mapped_user': '******'}

    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/map_user/chris',
                                     method='POST',
                                     headers={
                                         'content-type':
                                         'text/html; charset=UTF-8',
                                         'Cookie':
                                         'tiddlyweb_user="******"' % cookie
                                     },
                                     body=dumps(data))

    assert response['status'] == '415'
def test_handler_valid_post_responds_with_201():
    cookie = get_auth('ben', 'mocha')
    data = {'mapped_user': '******'}

    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/map_user/ben',
                                     method='POST',
                                     headers={
                                         'content-type':
                                         'application/json; charset=UTF-8',
                                         'Cookie':
                                         'tiddlyweb_user="******"' % cookie
                                     },
                                     body=dumps(data))

    assert response['status'] == '201'
Exemplo n.º 26
0
def test_foo_tiddlers_guest():
    cookie = get_auth("thingone", "how")
    response, content = http.request("http://foo.0.0.0.0:8080/", method="GET", headers={"Accept": "application/json"})
    guest_content = content

    response, content = http.request(
        "http://foo.0.0.0.0:8080/", headers={"Accept": "application/json", "Cookie": 'tiddlyweb_user="******"' % cookie}
    )
    user_content = content
    assert guest_content == user_content

    response, content = http.request(
        "http://thing.0.0.0.0:8080/bags/thing_private/tiddlers",
        method="GET",
        headers={"Accept": "application/json", "Cookie": 'tiddlyweb_user="******"' % cookie},
    )
    thing_content = content

    response, content = http.request(
        "http://foo.0.0.0.0:8080/bags/thing_private/tiddlers",
        method="GET",
        headers={"Accept": "application/json", "Cookie": 'tiddlyweb_user="******"' % cookie},
    )
    assert response["status"] == "404"

    response, content = http.request(
        "http://foo.0.0.0.0:8080/bags/thing_private/tiddlers",
        method="GET",
        headers={"Accept": "application/json", "X-ControlView": "false", "Cookie": 'tiddlyweb_user="******"' % cookie},
    )
    assert response["status"] == "401"

    response, content = http.request(
        "http://foo.0.0.0.0:8080/bags/thing_private/tiddlers/more",
        method="PUT",
        headers={
            "Content-Type": "application/json",
            "X-ControlView": "false",
            "Cookie": 'tiddlyweb_user="******"' % cookie,
        },
        body='{"text": "hi"}',
    )
    assert response["status"] == "403"
Exemplo n.º 27
0
def test_space_members():
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/cdent/members',
            method='GET')
    assert response['status'] == '401'
    cookie = get_auth('cdent', 'cow')

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent/members',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='GET')
    assert response['status'] == '200'
    assert response['cache-control'] == 'no-cache'
    info = simplejson.loads(content)
    assert info == ['cdent']

    response, content = http.request('http://0.0.0.0:8080/spaces/nancy/members',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='GET')
    response['status'] == '404'
Exemplo n.º 28
0
def test_foo_tiddlers_guest():
    cookie = get_auth('thingone', 'how')
    response, content = http.request('http://foo.0.0.0.0:8080/',
            method='GET',
            headers={'Accept': 'application/json'})
    guest_content = content

    response, content = http.request('http://foo.0.0.0.0:8080/',
            headers={'Accept': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie})
    user_content = content
    assert guest_content == user_content

    response, content = http.request(
            'http://thing.0.0.0.0:8080/bags/thing_private/tiddlers',
            method='GET',
            headers={'Accept': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie})
    thing_content = content

    response, content = http.request(
            'http://foo.0.0.0.0:8080/bags/thing_private/tiddlers',
            method='GET',
            headers={'Accept': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie})
    assert response['status'] == '404'

    response, content = http.request(
            'http://foo.0.0.0.0:8080/bags/thing_private/tiddlers',
            method='GET',
            headers={'Accept': 'application/json',
                'X-ControlView': 'false',
                'Cookie': 'tiddlyweb_user="******"' % cookie})
    assert response['status'] == '401'

    response, content = http.request(
            'http://foo.0.0.0.0:8080/bags/thing_private/tiddlers/more',
            method='PUT',
            headers={'Content-Type': 'application/json',
                'X-ControlView': 'false',
                'Cookie': 'tiddlyweb_user="******"' % cookie},
            body='{"text": "hi"}')
    assert response['status'] == '403'
Exemplo n.º 29
0
def test_blacklisted_subscription():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/scrappy',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            )
    assert response['status'] == '201'

    subscriptions = simplejson.dumps({'subscriptions': ['scrappy']})

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            method='POST',
            headers={
                'Content-Type': 'application/json',
                'Cookie': 'tiddlyweb_user="******"' % cookie,
                },
            body=subscriptions)
    assert response['status'] == '409'
    assert 'Subscription not allowed to space: scrappy' in content
def test_handler_valid_post_creates_mapuser_tiddler():
    cookie = get_auth('chris', 'piccolo')
    data = {'mapped_user': '******'}

    http = httplib2.Http()
    http.request('http://0.0.0.0:8080/map_user/chris',
                 method='POST',
                 headers={
                     'content-type': 'application/json; charset=UTF-8',
                     'Cookie': 'tiddlyweb_user="******"' % cookie
                 },
                 body=dumps(data))

    tiddler = Tiddler('chris', 'MAPUSER')
    tiddler = store.get(tiddler)

    assert tiddler.modifier == 'chris'
    assert tiddler.text == ''
    assert 'mapped_user' in tiddler.fields
    assert tiddler.fields['mapped_user'] == 'cdent'
Exemplo n.º 31
0
def test_space_members():
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/cdent/members', method='GET')
    assert response['status'] == '401'
    cookie = get_auth('cdent', 'cow')

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/cdent/members',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='GET')
    assert response['status'] == '200'
    assert response['cache-control'] == 'no-cache'
    info = simplejson.loads(content)
    assert info == ['cdent']

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/nancy/members',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='GET')
    response['status'] == '404'
Exemplo n.º 32
0
def test_chars_in_space():
    testcases = [
        ('foo', '201'),
        ('bAr', '409'),
        ('f0o', '201'),
        ('fo0', '201'),
        ('0foo', '201'),
        ('foo-bar', '201'),
        ('foo-bar-baz', '201'),
        ('-foo', '409'),
        ('foo-', '409'),
    ]

    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    for name, status in testcases:
        response, content = http.request('http://0.0.0.0:8080/spaces/%s' % name,
                method='PUT',
                headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
                )
        assert response['status'] == status
Exemplo n.º 33
0
def test_blacklisted_subscription():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/scrappy',
        method='PUT',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
    )
    assert response['status'] == '201'

    subscriptions = simplejson.dumps({'subscriptions': ['scrappy']})

    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
                                     method='POST',
                                     headers={
                                         'Content-Type': 'application/json',
                                         'Cookie':
                                         'tiddlyweb_user="******"' % cookie,
                                     },
                                     body=subscriptions)
    assert response['status'] == '409'
    assert 'Subscription not allowed to space: scrappy' in content
Exemplo n.º 34
0
def test_chars_in_space():
    testcases = [
        ('foo', '201'),
        ('bAr', '409'),
        ('f0o', '201'),
        ('fo0', '201'),
        ('0foo', '201'),
        ('foo-bar', '201'),
        ('foo-bar-baz', '201'),
        ('-foo', '409'),
        ('foo-', '409'),
    ]

    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    for name, status in testcases:
        response, content = http.request(
            'http://0.0.0.0:8080/spaces/%s' % name,
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        )
        assert response['status'] == status
Exemplo n.º 35
0
def test_space_not_expose_subscription_recipes():
    make_fake_space(store, 'foo')
    make_fake_space(store, 'bar')
    make_fake_space(store, 'baz')

    # add subscription (manual as this is currently insufficiently encapsulated)
    public_recipe = store.get(Recipe('foo_public'))
    private_recipe = store.get(Recipe('foo_private'))
    public_recipe_list = public_recipe.get_recipe()
    private_recipe_list = private_recipe.get_recipe()
    public_recipe_list.insert(-1, ('bar_public', ''))
    private_recipe_list.insert(-2, ('bar_public', ''))
    public_recipe.set_recipe(public_recipe_list)
    private_recipe.set_recipe(private_recipe_list)
    store.put(public_recipe)
    store.put(private_recipe)

    http = httplib2.Http()

    user = User('foo')
    user.set_password('foobar')
    store.put(user)
    user_cookie = get_auth('foo', 'foobar')

    response, content = http.request('http://foo.0.0.0.0:8080/recipes',
                                     method='GET')

    assert response['status'] == '200'
    assert 'foo_public' in content, content
    assert 'foo_private' not in content, content  # not auth'd
    assert 'bar_public' not in content, content
    assert 'bar_private' not in content, content
    assert 'baz_' not in content, content

    response, content = http.request(
        'http://foo.0.0.0.0:8080/recipes/foo_public', method='GET')
    assert response['status'] == '200'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/recipes/foo_private',
        method='GET',
        headers={'Cookie': 'tiddlyweb_user="******"' % user_cookie})
    assert response['status'] == '200'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/recipes/bar_public', method='GET')
    assert response['status'] == '404'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/recipes/bar_private',
        method='GET',
        headers={'Cookie': 'tiddlyweb_user="******"' % user_cookie})
    assert response['status'] == '404'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/recipes/baz_public', method='GET')
    assert response['status'] == '404'

    response, content = http.request(
        'http://foo.0.0.0.0:8080/recipes/baz_private', method='GET')
    assert response['status'] == '404'
Exemplo n.º 36
0
def test_space_not_expose_subscription_recipes():
    make_fake_space(store, 'foo')
    make_fake_space(store, 'bar')
    make_fake_space(store, 'baz')

    # add subscription (manual as this is currently insufficiently encapsulated)
    public_recipe = store.get(Recipe('foo_public'))
    private_recipe = store.get(Recipe('foo_private'))
    public_recipe_list = public_recipe.get_recipe()
    private_recipe_list = private_recipe.get_recipe()
    public_recipe_list.insert(-1, ('bar_public', ''))
    private_recipe_list.insert(-2, ('bar_public', ''))
    public_recipe.set_recipe(public_recipe_list)
    private_recipe.set_recipe(private_recipe_list)
    store.put(public_recipe)
    store.put(private_recipe)

    http = httplib2.Http()

    user = User('foo')
    user.set_password('foobar')
    store.put(user)
    user_cookie = get_auth('foo', 'foobar')

    response, content = http.request('http://foo.0.0.0.0:8080/recipes',
            method='GET')

    assert response['status'] == '200'
    assert 'foo_public' in content, content
    assert 'foo_private' not in content, content # not auth'd
    assert 'bar_public' not in content, content
    assert 'bar_private' not in content, content
    assert 'baz_' not in content, content

    response, content = http.request('http://foo.0.0.0.0:8080/recipes/foo_public',
            method='GET')
    assert response['status'] == '200'

    response, content = http.request('http://foo.0.0.0.0:8080/recipes/foo_private',
            method='GET',
            headers={
                'Cookie': 'tiddlyweb_user="******"' % user_cookie
            })
    assert response['status'] == '200'

    response, content = http.request('http://foo.0.0.0.0:8080/recipes/bar_public',
            method='GET')
    assert response['status'] == '404'

    response, content = http.request('http://foo.0.0.0.0:8080/recipes/bar_private',
            method='GET',
            headers={
                'Cookie': 'tiddlyweb_user="******"' % user_cookie
            })
    assert response['status'] == '404'

    response, content = http.request('http://foo.0.0.0.0:8080/recipes/baz_public',
            method='GET')
    assert response['status'] == '404'

    response, content = http.request('http://foo.0.0.0.0:8080/recipes/baz_private',
            method='GET')
    assert response['status'] == '404'
Exemplo n.º 37
0
def test_create_space():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/cdent',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT')
    assert response['status'] == '409'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra',
                                     method='GET')
    assert response['status'] == '404'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra',
                                     method='PUT')
    assert response['status'] == '403'

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra',
        method='PUT',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
    )
    assert response['status'] == '201'
    assert response['location'] == 'http://extra.0.0.0.0:8080/'

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='GET')
    response['status'] == '200'
    info = simplejson.loads(content)
    assert info == ['cdent'], content

    bag = store.get(Bag('extra_public'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == []
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    bag = store.get(Bag('extra_private'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    bag = store.get(Bag('extra_archive'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    recipe = store.get(Recipe('extra_public'))
    assert recipe.policy.owner == 'cdent'
    assert recipe.policy.read == []
    assert recipe.policy.accept == ['NONE']
    assert recipe.policy.manage == ['cdent']
    assert recipe.policy.write == ['cdent']
    assert recipe.policy.create == ['cdent']
    assert recipe.policy.delete == ['cdent']
    recipe_list = recipe.get_recipe()
    assert len(recipe_list) == 7
    assert recipe_list[0][0] == 'system'
    assert recipe_list[1][0] == 'tiddlyspace'
    assert recipe_list[2][0] == 'system-plugins_public'
    assert recipe_list[3][0] == 'system-info_public'
    assert recipe_list[4][0] == 'system-images_public'
    assert recipe_list[5][0] == 'system-theme_public'
    assert recipe_list[6][0] == 'extra_public'

    recipe = store.get(Recipe('extra_private'))
    recipe_list = recipe.get_recipe()
    assert recipe.policy.owner == 'cdent'
    assert recipe.policy.read == ['cdent']
    assert recipe.policy.accept == ['NONE']
    assert recipe.policy.manage == ['cdent']
    assert recipe.policy.write == ['cdent']
    assert recipe.policy.create == ['cdent']
    assert recipe.policy.delete == ['cdent']
    assert len(recipe_list) == 8
    assert recipe_list[0][0] == 'system'
    assert recipe_list[1][0] == 'tiddlyspace'
    assert recipe_list[2][0] == 'system-plugins_public'
    assert recipe_list[3][0] == 'system-info_public'
    assert recipe_list[4][0] == 'system-images_public'
    assert recipe_list[5][0] == 'system-theme_public'
    assert recipe_list[6][0] == 'extra_public'
    assert recipe_list[7][0] == 'extra_private'
Exemplo n.º 38
0
def test_add_a_member():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members/fnd',
        method='PUT',
    )
    assert response['status'] == '403', content

    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/fnd',
        method='PUT',
    )
    assert response['status'] == '403', content

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members/fnd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT',
    )
    assert response['status'] == '403'

    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/fnd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT',
    )
    assert response['status'] == '204'

    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='GET')
    assert response['status'] == '200', content
    info = simplejson.loads(content)
    assert info == ['cdent', 'fnd']

    bag = store.get(Bag('extra_private'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent', 'fnd']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent', 'fnd']
    assert bag.policy.write == ['cdent', 'fnd']
    assert bag.policy.create == ['cdent', 'fnd']
    assert bag.policy.delete == ['cdent', 'fnd']

    bag = store.get(Bag('extra_archive'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent', 'fnd']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent', 'fnd']
    assert bag.policy.write == ['cdent', 'fnd']
    assert bag.policy.create == ['cdent', 'fnd']
    assert bag.policy.delete == ['cdent', 'fnd']

    bag = store.get(Bag('extra_public'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == []
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent', 'fnd']
    assert bag.policy.write == ['cdent', 'fnd']
    assert bag.policy.create == ['cdent', 'fnd']
    assert bag.policy.delete == ['cdent', 'fnd']

    # authed user not in space may not add people
    cookie = get_auth('psd', 'cat')
    response, content = http.request(
        'http://0.0.0.0:8080/spaces/extra/members/psd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT',
    )
    assert response['status'] == '403'

    cookie = get_auth('fnd', 'bird')
    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/psd',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT',
    )
    assert response['status'] == '204'

    cookie = get_auth('fnd', 'bird')
    response, content = http.request(
        'http://extra.0.0.0.0:8080/spaces/extra/members/mary',
        headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
        method='PUT',
    )
    assert response['status'] == '409'
Exemplo n.º 39
0
def test_add_a_member():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/fnd',
            method='PUT',
            )
    assert response['status'] == '403'

    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/fnd',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT',
            )
    assert response['status'] == '204'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='GET')
    assert response['status'] == '200', content
    info = simplejson.loads(content)
    assert info == ['cdent', 'fnd']

    bag = store.get(Bag('extra_private'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent', 'fnd']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent', 'fnd']
    assert bag.policy.write == ['cdent', 'fnd']
    assert bag.policy.create == ['cdent', 'fnd']
    assert bag.policy.delete == ['cdent', 'fnd']

    bag = store.get(Bag('extra_archive'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent', 'fnd']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent', 'fnd']
    assert bag.policy.write == ['cdent', 'fnd']
    assert bag.policy.create == ['cdent', 'fnd']
    assert bag.policy.delete == ['cdent', 'fnd']

    bag = store.get(Bag('extra_public'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == []
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent', 'fnd']
    assert bag.policy.write == ['cdent', 'fnd']
    assert bag.policy.create == ['cdent', 'fnd']
    assert bag.policy.delete == ['cdent', 'fnd']

    # authed user not in space may not add people
    cookie = get_auth('psd', 'cat')
    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/psd',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT',
            )
    assert response['status'] == '403'

    cookie = get_auth('fnd', 'bird')
    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/psd',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT',
            )
    assert response['status'] == '204'

    cookie = get_auth('fnd', 'bird')
    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members/mary',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT',
            )
    assert response['status'] == '409'
Exemplo n.º 40
0
def test_create_space():
    cookie = get_auth('cdent', 'cow')
    http = httplib2.Http()
    response, content = http.request('http://0.0.0.0:8080/spaces/cdent',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='PUT')
    assert response['status'] == '409'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra',
            method='GET')
    assert response['status'] == '404'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra',
            method='PUT')
    assert response['status'] == '403'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra',
            method='PUT',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            )
    assert response['status'] == '201'
    assert response['location'] == 'http://extra.0.0.0.0:8080/'

    response, content = http.request('http://0.0.0.0:8080/spaces/extra/members',
            headers={'Cookie': 'tiddlyweb_user="******"' % cookie},
            method='GET')
    response['status'] == '200'
    info = simplejson.loads(content)
    assert info == ['cdent'], content

    bag = store.get(Bag('extra_public'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == []
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    bag = store.get(Bag('extra_private'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    bag = store.get(Bag('extra_archive'))
    assert bag.policy.owner == 'cdent'
    assert bag.policy.read == ['cdent']
    assert bag.policy.accept == ['NONE']
    assert bag.policy.manage == ['cdent']
    assert bag.policy.write == ['cdent']
    assert bag.policy.create == ['cdent']
    assert bag.policy.delete == ['cdent']

    recipe = store.get(Recipe('extra_public'))
    assert recipe.policy.owner == 'cdent'
    assert recipe.policy.read == []
    assert recipe.policy.accept == ['NONE']
    assert recipe.policy.manage == ['cdent']
    assert recipe.policy.write == ['cdent']
    assert recipe.policy.create == ['cdent']
    assert recipe.policy.delete == ['cdent']
    recipe_list = recipe.get_recipe()
    assert len(recipe_list) == 7
    assert recipe_list[0][0] == 'system'
    assert recipe_list[1][0] == 'tiddlyspace'
    assert recipe_list[2][0] == 'system-plugins_public'
    assert recipe_list[3][0] == 'system-info_public'
    assert recipe_list[4][0] == 'system-images_public'
    assert recipe_list[5][0] == 'system-theme_public'
    assert recipe_list[6][0] == 'extra_public'

    recipe = store.get(Recipe('extra_private'))
    recipe_list = recipe.get_recipe()
    assert recipe.policy.owner == 'cdent'
    assert recipe.policy.read == ['cdent']
    assert recipe.policy.accept == ['NONE']
    assert recipe.policy.manage == ['cdent']
    assert recipe.policy.write == ['cdent']
    assert recipe.policy.create == ['cdent']
    assert recipe.policy.delete == ['cdent']
    assert len(recipe_list) == 8
    assert recipe_list[0][0] == 'system'
    assert recipe_list[1][0] == 'tiddlyspace'
    assert recipe_list[2][0] == 'system-plugins_public'
    assert recipe_list[3][0] == 'system-info_public'
    assert recipe_list[4][0] == 'system-images_public'
    assert recipe_list[5][0] == 'system-theme_public'
    assert recipe_list[6][0] == 'extra_public'
    assert recipe_list[7][0] == 'extra_private'