grooveondemand/test/test_webserver.py

55 lines
1.2 KiB
Python
Raw Normal View History

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
from boddle import boddle
2022-11-19 16:58:58 -08:00
2022-11-20 09:28:00 -08:00
from groove import webserver
2022-11-20 01:00:54 -08:00
2022-11-19 16:58:58 -08:00
def test_server():
with boddle():
2022-11-20 09:28:00 -08:00
webserver.index()
2022-11-20 01:00:54 -08:00
assert bottle.response.status_code == 200
2022-11-19 16:58:58 -08:00
def test_auth_with_valid_credentials():
with boddle(auth=(os.environ.get('USERNAME'), os.environ.get('PASSWORD'))):
2022-11-20 09:28:00 -08:00
webserver.build()
2022-11-20 01:00:54 -08:00
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 09:28:00 -08:00
response = webserver.build()
2022-11-20 01:07:38 -08:00
assert response.status_code == 401
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():
2022-11-20 09:28:00 -08:00
response = webserver.get_playlist(slug, db)
2022-11-20 01:00:54 -08:00
assert response.status_code == expected
def test_playlist_on_empty_db(in_memory_db):
with boddle():
2022-11-20 09:28:00 -08:00
response = webserver.get_playlist('some-slug', in_memory_db)
2022-11-20 01:00:54 -08:00
assert response.status_code == 404