Esempio n. 1
0
def test_put():
    app = create_app()

    t1 = time()
    rv = app.test_client().post('/', data=dict(c=str(t1)))
    data = load(rv.get_data())

    assert data.get('uuid')
    assert data.get('url')
    assert 'redacted' not in data.get('uuid')

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    f = lambda c: app.test_client().put(url, data=dict(c=str(c) if c else c))

    rv = f(None)
    assert rv.status_code == 400

    rv = f(t1)
    assert load(rv.get_data())['status'] == 'already exists'

    t2 = time()
    rv = f(t2)
    assert rv.status_code == 200

    rv = app.test_client().get(load(rv.get_data())['url'])
    assert rv.get_data().decode('utf-8') == str(t2)
Esempio n. 2
0
def test_paste_vanity():
    app = create_app()

    c = str(time())
    rv = app.test_client().post('/foo123', data=dict(
        c = c
    ))
    location = rv.headers.get('Location')
    assert 'foo123' in location
    data = load(rv.get_data())

    rv = app.test_client().get(location)
    assert rv.status_code == 200
    assert rv.get_data() == c.encode('utf-8')

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))
    
    rv = app.test_client().put(url, data=dict(
        c = str(time())
    ))
    assert rv.status_code == 200

    rv = app.test_client().delete(url)
    assert rv.status_code == 200
Esempio n. 3
0
def test_insert_private():
    app = create_app()

    c = str(time())
    rv = app.test_client().post('/', data=dict(c=c, p=1))

    data = load(rv.get_data())
    assert sha1(c.encode('utf-8')).hexdigest() in data['sha1']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    f = lambda c: app.test_client().put(url, data=dict(c=c))

    rv = f(c)
    assert load(rv.get_data())['status'] == 'already exists'

    rv = f(str(time()))
    assert load(rv.get_data())['status'] == 'updated'

    rv = app.test_client().delete(url)
    assert load(rv.get_data())['status'] == 'deleted'
Esempio n. 4
0
def test_post_content():
    app = create_app()

    rv = app.test_client().post('/')
    assert rv.status_code == 400

    rv = app.test_client().post('/', data=dict(
        c = str(time())
    ))
    assert rv.status_code == 302

    location = rv.headers.get('Location')
    assert location

    rv = app.test_client().get(location)
    assert rv.status_code == 200

    url_path = parse.urlsplit(location).path
    id = b66_int(path.split(url_path)[-1])
    assert id != 0

    with app.test_request_context():
        url = url_for('paste.get', b66=id+10)

    rv = app.test_client().get(url)
    assert rv.status_code == 404
Esempio n. 5
0
def test_paste_mangle():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.post')

    rv = app.test_client().post(url, data=dict(
        c = str(time())
    ))

    location = rv.headers.get('Location') 
    url_path = parse.urlsplit(location).path
    id = b66_int(path.split(url_path)[-1])

    assert id != 0

    tests = [
        ({'lexer': 'py'}, 200),
        ({'lexer': ''}, 200),
        ({'lexer': 'buhLang'}, 400),
        ({'handler': 'r'}, 200),
        ({'handler': 'Z'}, 400)
    ]

    for kwargs, code in tests:
        with app.test_request_context():
            url = url_for('paste.get', b66=id, **kwargs)

        rv = app.test_client().get(url)
        assert rv.status_code == code
Esempio n. 6
0
def test_paste_vanity():
    app = create_app()

    c = str(time())
    rv = app.test_client().post('/~foo1234', data=dict(
        c=c
    ))

    data = load(rv.get_data())
    assert 'foo1234' in data['url']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200
    assert rv.get_data() == c.encode('utf-8')

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    rv = app.test_client().put(url, data=dict(
        c=str(time())
    ))
    assert rv.status_code == 200

    rv = app.test_client().delete(url)
    assert rv.status_code == 200
Esempio n. 7
0
def test_delete():
    app = create_app()

    rv = app.test_client().post('/', data=dict(
        c='delete me KU7cC3JBrz0jMXYRCWsZ6YGa/YTYIZWw'
    ))
    data = load(rv.get_data())
    assert 'redacted' not in data.get('uuid')

    with app.test_request_context():
        url = url_for('paste.delete', uuid=data.get('uuid'))

    rv = app.test_client().delete(url)
    assert rv.status_code == 200

    rv = app.test_client().delete(url)
    assert rv.status_code == 404

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    rv = app.test_client().put(url, data=dict(
        c=str(time())
    ))
    assert rv.status_code == 404
Esempio n. 8
0
def test_insert_private():
    app = create_app()

    c = str(time())
    rv = app.test_client().post('/', data=dict(
        c = c,
        p = 1
    ))
    location = rv.headers.get('Location')
    data = load(rv.get_data())
    assert sha1(c.encode('utf-8')).hexdigest() in location

    rv = app.test_client().get(location)
    assert rv.status_code == 200

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))
    
    f = lambda c: app.test_client().put(url, data=dict(
        c = c
    ))

    rv = f(c)
    assert rv.status_code == 409

    rv = f(str(time()))
    assert rv.status_code == 200

    rv = app.test_client().delete(url)
    assert rv.status_code == 200
Esempio n. 9
0
def test_put():
    app = create_app()

    t1 = time()
    rv = app.test_client().post("/", data=dict(c=str(t1)))
    data = load(rv.get_data())

    assert data.get("uuid")
    assert data.get("url")
    assert "redacted" not in data.get("uuid")

    with app.test_request_context():
        url = url_for("paste.put", uuid=data.get("uuid"))

    f = lambda c: app.test_client().put(url, data=dict(c=str(c) if c else c))

    rv = f(None)
    assert rv.status_code == 400

    rv = f(t1)
    assert load(rv.get_data())["status"] == "already exists"

    t2 = time()
    rv = f(t2)
    assert rv.status_code == 200

    rv = app.test_client().get(load(rv.get_data())["url"])
    assert rv.get_data().decode("utf-8") == str(t2)
Esempio n. 10
0
def test_put():
    app = create_app()

    t1 = time()
    rv = app.test_client().post('/', data=dict(
        c=str(t1)
    ))
    data = load(rv.get_data())

    assert data.get('uuid')
    assert data.get('url')
    assert 'redacted' not in data.get('uuid')

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    def f(c):
        return app.test_client().put(url, data=dict(
            c=str(c) if c else c
        ))

    rv = f(None)
    assert rv.status_code == 400

    rv = f(t1)
    assert load(rv.get_data())['status'] == 'already exists'

    t2 = time()
    rv = f(t2)
    assert rv.status_code == 200

    rv = app.test_client().get(load(rv.get_data())['url'])
    assert rv.get_data().decode('utf-8') == str(t2)
Esempio n. 11
0
def test_insert_private():
    app = create_app()

    c = str(time())
    rv = app.test_client().post('/', data=dict(
        c=c,
        p=1
    ))

    data = load(rv.get_data())
    assert sha1(c.encode('utf-8')).hexdigest() == data['digest']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    def f(c):
        return app.test_client().put(url, data=dict(
            c=c
        ))

    rv = f(c)
    assert load(rv.get_data())['status'] == 'already exists'

    rv = f(str(time()))
    assert load(rv.get_data())['status'] == 'updated'

    rv = app.test_client().delete(url)
    assert load(rv.get_data())['status'] == 'deleted'
Esempio n. 12
0
def test_get_lexers():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.list_lexers')

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 13
0
def test_get_css():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.highlight_css', style='default')

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 14
0
def test_get_mimetype():
    app = create_app()

    rv = app.test_client().post('/', data=dict(c=str('ello')))

    rv = app.test_client().get('{}.py'.format(load(rv.get_data())['url']))

    assert 'text/x-python' in rv.headers.get('Content-Type')
Esempio n. 15
0
def test_get_lexers():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.list_lexers')

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 16
0
def test_get_css():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.highlight_css', style='default')

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 17
0
def test_get_mimetype():
    app = create_app()

    rv = app.test_client().post("/", data=dict(c=str("ello")))

    rv = app.test_client().get("{}.py".format(load(rv.get_data())["url"]))

    assert "text/x-python" in rv.headers.get("Content-Type")
Esempio n. 18
0
def test_get_mimetype():
    app = create_app()

    rv = app.test_client().post('/', data=dict(
        c = str('ello')
    ))

    rv = app.test_client().get('{}.py'.format(rv.headers.get('Location')))

    assert 'text/x-python' in rv.headers.get('Content-Type')
Esempio n. 19
0
def test_paste_render():
    app = create_app()

    rv = app.test_client().post('/', data=dict(c=str(time())))

    data = load(rv.get_data())
    with app.test_request_context():
        url = url_for('paste.get', handler='r', label=data['short'])

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 20
0
def test_url_get():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.url')

    rv = app.test_client().post(url, data=dict(c=str(time())))
    location = rv.headers.get('Location')
    assert location

    rv = app.test_client().get(location)
    assert rv.status_code == 302
Esempio n. 21
0
def test_get_digest():
    app = create_app()

    c = str(time())
    app.test_client().post('/', data=dict(c=c))

    digest = sha1(c.encode('utf-8')).hexdigest()
    with app.test_request_context():
        url = url_for('paste.get', sha1=digest)

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 22
0
def test_post_file():
    app = create_app()

    c = urandom(24)
    ext = int(time())
    rv = app.test_client().post("/", data=dict(c=(BytesIO(c), "foo.{}".format(ext))))

    data = load(rv.get_data())
    assert ".{}".format(ext) in data["url"]

    rv = app.test_client().get(data["url"])
    assert c == rv.get_data()
Esempio n. 23
0
def test_post_file(field_name):
    app = create_app()

    content = urandom(24)
    ext = int(time())
    rv = app.test_client().post(
        '/', data={field_name: (BytesIO(content), 'foo.{}'.format(ext))})

    data = load(rv.get_data())
    assert '.{}'.format(ext) in data['url']

    rv = app.test_client().get(data['url'])
    assert rv.get_data() == content
Esempio n. 24
0
def test_paste_render():
    app = create_app()

    rv = app.test_client().post('/', data=dict(
        c=str(time())
    ))

    data = load(rv.get_data())
    with app.test_request_context():
        url = url_for('paste.get', handler='r', label=data['short'])

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 25
0
def test_paste_mangle():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.post')

    rv = app.test_client().post(url, data=dict(
        c = str(time())
    ))

    location = rv.headers.get('Location')
    url_path = parse.urlsplit(location).path
    """ FIXME
Esempio n. 26
0
def test_url_get():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.url')

    rv = app.test_client().post(url, data=dict(
        c = str(time())
    ))
    location = rv.headers.get('Location')
    assert location

    rv = app.test_client().get(location)
    assert rv.status_code == 302
Esempio n. 27
0
def test_post_file():
    app = create_app()

    c = urandom(24)
    ext = int(time())
    rv = app.test_client().post('/', data=dict(
        c = (BytesIO(c), 'foo.{}'.format(ext))
    ))

    location = rv.headers.get('Location')
    assert '.{}'.format(ext) in location

    rv = app.test_client().get(location)
    assert c == rv.get_data()
Esempio n. 28
0
def test_post_content():
    app = create_app()

    rv = app.test_client().post('/')
    assert rv.status_code == 400

    rv = app.test_client().post('/', data=dict(c=str(time())))
    assert rv.status_code == 200

    data = load(rv.get_data())
    assert data['url']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200
Esempio n. 29
0
def test_post_file(field_name):
    app = create_app()

    content = urandom(24)
    ext = int(time())
    rv = app.test_client().post('/', data={
        field_name: (BytesIO(content), 'foo.{}'.format(ext))
    })

    data = load(rv.get_data())
    assert '.{}'.format(ext) in data['url']

    rv = app.test_client().get(data['url'])
    assert rv.get_data() == content
Esempio n. 30
0
def test_get_digest():
    app = create_app()

    c = str(time())
    app.test_client().post('/', data=dict(
        c = c
    ))

    digest = sha1(c.encode('utf-8')).digest()
    with app.test_request_context():
        url = url_for('paste.get', sha1=digest)

    rv = app.test_client().get(url)
    assert rv.status_code == 200
Esempio n. 31
0
def test_post_content():
    app = create_app()

    rv = app.test_client().post("/")
    assert rv.status_code == 400

    rv = app.test_client().post("/", data=dict(c=str(time())))
    assert rv.status_code == 200

    data = load(rv.get_data())
    assert data["url"]

    rv = app.test_client().get(data["url"])
    assert rv.status_code == 200
Esempio n. 32
0
def test_post_file():
    app = create_app()

    c = urandom(24)
    ext = int(time())
    rv = app.test_client().post('/',
                                data=dict(c=(BytesIO(c),
                                             'foo.{}'.format(ext))))

    location = rv.headers.get('Location')
    assert '.{}'.format(ext) in location

    rv = app.test_client().get(location)
    assert c == rv.get_data()
Esempio n. 33
0
def test_post_file():
    app = create_app()

    c = urandom(24)
    ext = int(time())
    rv = app.test_client().post('/',
                                data=dict(c=(BytesIO(c),
                                             'foo.{}'.format(ext))))

    data = load(rv.get_data())
    assert '.{}'.format(ext) in data['url']

    rv = app.test_client().get(data['url'])
    assert c == rv.get_data()
Esempio n. 34
0
File: delete.py Progetto: ptpb/pb
def main():
    ns = parser.parse_args()

    res = requests.request('REPORT', f'{ns.endpoint}/{ns.id}', headers={
        'accept': 'application/json'
    })

    assert res.ok

    digest = res.json()['digest']

    app = create_app()
    with app.app_context():
        with app.test_request_context(ns.endpoint):
            delete_paste(digest)
Esempio n. 35
0
def test_post_unqiue():
    app = create_app()

    f = lambda c: app.test_client().post('/', data=dict(c=str(c)))

    rv1 = f(monotonic())
    rv2 = f(monotonic())

    assert rv1.headers.get('Location') != rv2.headers.get('Location')

    c = time()
    rv1 = f(c)
    rv2 = f(c)

    assert rv1.headers.get('Location') == rv2.headers.get('Location')
Esempio n. 36
0
def main():
    ns = parser.parse_args()

    res = requests.request('REPORT',
                           f'{ns.endpoint}/{ns.id}',
                           headers={'accept': 'application/json'})

    assert res.ok

    digest = res.json()['digest']

    app = create_app()
    with app.app_context():
        with app.test_request_context(ns.endpoint):
            delete_paste(digest)
Esempio n. 37
0
def test_post_unique():
    app = create_app()

    f = lambda c: app.test_client().post("/", data=dict(c=str(c)))

    rv1 = f(monotonic())
    rv2 = f(monotonic())

    assert load(rv1.get_data())["url"] != load(rv2.get_data())["url"]

    c = time()
    rv1 = f(c)
    rv2 = f(c)

    assert load(rv1.get_data())["url"] == load(rv2.get_data())["url"]
Esempio n. 38
0
def test_url_post():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.url')

    rv = app.test_client().post(url)
    assert rv.status_code == 400

    f = lambda c: app.test_client().post(url, data=dict(c=str(c)))
    rv = f(shorturl)
    assert rv.status_code == 200

    rv = f(time())
    assert rv.status_code == 200
Esempio n. 39
0
def test_post_content():
    app = create_app()

    rv = app.test_client().post('/')
    assert rv.status_code == 400

    rv = app.test_client().post('/', data=dict(
        c = str(time())
    ))
    assert rv.status_code == 302

    location = rv.headers.get('Location')
    assert location

    rv = app.test_client().get(location)
    assert rv.status_code == 200
Esempio n. 40
0
def test_post_content(field_name):
    app = create_app()

    rv = app.test_client().post('/')
    assert rv.status_code == 400

    content = str(time())
    rv = app.test_client().post('/', data={field_name: content})
    assert rv.status_code == 200

    data = load(rv.get_data())
    assert data['url']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200
    assert rv.get_data() == content.encode('utf-8')
Esempio n. 41
0
def test_post_unique():
    app = create_app()

    def f(c):
        return app.test_client().post('/', data=dict(c=str(c)))

    rv1 = f(monotonic())
    rv2 = f(monotonic())

    assert load(rv1.get_data())['url'] != load(rv2.get_data())['url']

    c = time()
    rv1 = f(c)
    rv2 = f(c)

    assert load(rv1.get_data())['url'] == load(rv2.get_data())['url']
Esempio n. 42
0
def test_post_unqiue():
    app = create_app()

    f = lambda c: app.test_client().post('/', data=dict(
        c = str(c)
    ))

    rv1 = f(monotonic())
    rv2 = f(monotonic())

    assert rv1.headers.get('Location') != rv2.headers.get('Location')

    c = time()
    rv1 = f(c)
    rv2 = f(c)

    assert rv1.headers.get('Location') == rv2.headers.get('Location')
Esempio n. 43
0
def test_url_post():
    app = create_app()

    with app.test_request_context():
        url = url_for('paste.url')

    rv = app.test_client().post(url)
    assert rv.status_code == 400

    f = lambda c: app.test_client().post(url, data=dict(
        c = str(c)
    ))
    rv = f(shorturl)
    assert rv.status_code == 200

    rv = f(time())
    assert rv.status_code == 200
Esempio n. 44
0
def test_post_content(field_name):
    app = create_app()

    rv = app.test_client().post('/')
    assert rv.status_code == 400

    content = str(time())
    rv = app.test_client().post('/', data={
        field_name: content
    })
    assert rv.status_code == 200

    data = load(rv.get_data())
    assert data['url']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200
    assert rv.get_data() == content.encode('utf-8')
Esempio n. 45
0
def test_post_unique():
    app = create_app()

    def f(c):
        return app.test_client().post('/', data=dict(
            c=str(c)
        ))

    rv1 = f(monotonic())
    rv2 = f(monotonic())

    assert load(rv1.get_data())['url'] != load(rv2.get_data())['url']

    c = time()
    rv1 = f(c)
    rv2 = f(c)

    assert load(rv1.get_data())['url'] == load(rv2.get_data())['url']
Esempio n. 46
0
def test_paste_render():
    app = create_app()

    rv = app.test_client().post('/', data=dict(c=str(time())))

    data = load(rv.get_data())
    with app.test_request_context():
        nurl = url_for('paste.get', label=data['short'], lexer='')
        iurl = url_for('paste.get', label=data['short'], lexer='bogus')
        lurl = url_for('paste.get', label=data['short'], lexer='pycon')

    rv1 = app.test_client().get(nurl)
    rv2 = app.test_client().get(iurl)
    rv3 = app.test_client().get(lurl)

    assert rv1.status_code == 200
    assert rv2.status_code == 400
    assert rv3.status_code == 200
Esempio n. 47
0
def test_paste_sunset():
    app = create_app()

    rv = app.test_client().post('/', data=dict(c=str(time()), s=1))

    data = load(rv.get_data())
    with app.test_request_context():
        url = url_for('paste.get', label=data['short'])

    sleep(1)

    rv = app.test_client().get(url)
    data = load(rv.get_data())

    assert data['status'] == 'expired'

    rv = app.test_client().get(url)

    assert rv.status_code == 404
Esempio n. 48
0
def test_paste_sunset_expire_before_get():
    app = create_app()

    c = str(time())

    app.test_client().post('/', data=dict(
        c=c,
        s=1
    ))

    sleep(1)

    rv = app.test_client().post('/', data=dict(
        c=c,
        s=1
    ))

    assert rv.status_code == 200
    data = load(rv.get_data())
    assert data['status'] == 'created'
Esempio n. 49
0
def test_paste_render():
    app = create_app()

    rv = app.test_client().post('/', data=dict(
        c = str(time())
    ))

    data = load(rv.get_data())
    with app.test_request_context():
        nurl = url_for('paste.get', label=data['short'], lexer='')
        iurl = url_for('paste.get', label=data['short'], lexer='bogus')
        lurl = url_for('paste.get', label=data['short'], lexer='pycon')

    rv1 = app.test_client().get(nurl)
    rv2 = app.test_client().get(iurl)
    rv3 = app.test_client().get(lurl)

    assert rv1.status_code == 200
    assert rv2.status_code == 400
    assert rv3.status_code == 200
Esempio n. 50
0
def test_paste_vanity():
    app = create_app()

    c = str(time())
    rv = app.test_client().post('/~foo1234', data=dict(c=c))

    data = load(rv.get_data())
    assert 'foo1234' in data['url']

    rv = app.test_client().get(data['url'])
    assert rv.status_code == 200
    assert rv.get_data() == c.encode('utf-8')

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    rv = app.test_client().put(url, data=dict(c=str(time())))
    assert rv.status_code == 200

    rv = app.test_client().delete(url)
    assert rv.status_code == 200
Esempio n. 51
0
def test_delete():
    app = create_app()

    rv = app.test_client().post(
        '/', data=dict(c='delete me KU7cC3JBrz0jMXYRCWsZ6YGa/YTYIZWw'))
    data = load(rv.get_data())
    assert 'redacted' not in data.get('uuid')

    with app.test_request_context():
        url = url_for('paste.delete', uuid=data.get('uuid'))

    rv = app.test_client().delete(url)
    assert rv.status_code == 200

    rv = app.test_client().delete(url)
    assert rv.status_code == 404

    with app.test_request_context():
        url = url_for('paste.put', uuid=data.get('uuid'))

    rv = app.test_client().put(url, data=dict(c=str(time())))
    assert rv.status_code == 404
Esempio n. 52
0
def test_url_get():
    app = create_app()

    with app.test_request_context():
        url = url_for('url.post')

    rv = app.test_client().post(url, data=dict(c=str(time())))
    location = rv.headers.get('Location')
    assert location

    rv = app.test_client().get(location)
    assert rv.status_code == 302

    url_path = parse.urlsplit(location).path
    id = b66_int(path.split(url_path)[-1])
    assert id != 0

    with app.test_request_context():
        url = url_for('url.get', b66=id + 10)

    rv = app.test_client().get(url)
    assert rv.status_code == 404
Esempio n. 53
0
def test_get_index():
    app = create_app()

    with app.test_request_context():
        rv = app.test_client().get(url_for('paste.index'))
        assert rv.status_code == 200
Esempio n. 54
0
def app():
    app = create_app()
    return app
Esempio n. 55
0
File: run.py Progetto: GermainZ/pb
#!/usr/bin/env python3
"""
    wsgi stub
    ~~~~~~~~~

    intended to be conveniently used by wsgi servers.

    :copyright: Copyright (C) 2014 by the respective authors; see AUTHORS.
    :license: GPLv3, see LICENSE for details.
"""

from pb.pb import create_app

app = create_app()

if __name__ == '__main__':
    app.run(host='::1', port=10002)