2022-11-20 01:00:54 -08:00
|
|
|
import pytest
|
|
|
|
|
2022-11-19 16:58:58 -08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import atheris
|
2022-11-20 01:00:54 -08:00
|
|
|
import bottle
|
2022-11-19 15:14:12 -08:00
|
|
|
from boddle import boddle
|
2022-11-19 16:58:58 -08:00
|
|
|
|
2022-11-19 15:14:12 -08:00
|
|
|
from groove import ondemand
|
|
|
|
|
|
|
|
|
2022-11-20 01:00:54 -08:00
|
|
|
@pytest.fixture(autouse=True, scope='session')
|
|
|
|
def init_db():
|
|
|
|
ondemand.initialize()
|
|
|
|
|
|
|
|
|
2022-11-19 16:58:58 -08:00
|
|
|
def test_server():
|
2022-11-19 15:14:12 -08:00
|
|
|
with boddle():
|
2022-11-20 01:00:54 -08:00
|
|
|
ondemand.index()
|
|
|
|
assert bottle.response.status_code == 200
|
2022-11-19 16:06:23 -08:00
|
|
|
|
|
|
|
|
2022-11-19 16:58:58 -08:00
|
|
|
def test_auth_with_valid_credentials():
|
2022-11-19 16:06:23 -08:00
|
|
|
with boddle(auth=(os.environ.get('USERNAME'), os.environ.get('PASSWORD'))):
|
2022-11-20 01:00:54 -08:00
|
|
|
ondemand.build()
|
|
|
|
assert bottle.response.status_code == 200
|
2022-11-19 16:58:58 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_auth_random_input():
|
|
|
|
|
|
|
|
def auth(fuzzed_input):
|
|
|
|
with boddle(auth=(fuzzed_input, fuzzed_input)):
|
2022-11-20 01:00:54 -08:00
|
|
|
response = ondemand.build()
|
|
|
|
assert response.status_code == 403
|
2022-11-19 16:58:58 -08:00
|
|
|
|
|
|
|
atheris.Setup([sys.argv[0], "-atheris_runs=100000"], auth)
|
|
|
|
try:
|
|
|
|
atheris.Fuzz()
|
|
|
|
except SystemExit:
|
|
|
|
pass
|
2022-11-20 01:00:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('slug, expected', [
|
|
|
|
('playlist-one', 200),
|
|
|
|
('playlist-two', 200),
|
|
|
|
('playlist-three', 200),
|
|
|
|
('no such playlist', 404),
|
|
|
|
])
|
|
|
|
def test_playlist(db, slug, expected):
|
|
|
|
with boddle():
|
|
|
|
response = ondemand.get_playlist(slug, db)
|
|
|
|
assert response.status_code == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_playlist_on_empty_db(in_memory_db):
|
|
|
|
with boddle():
|
|
|
|
response = ondemand.get_playlist('some-slug', in_memory_db)
|
|
|
|
assert response.status_code == 404
|