diff --git a/.travis.yml b/.travis.yml index af5b21a..9c1a84f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,7 @@ script: - docker-compose -p instance1 -f docker-compose-tests.yml ps - WEB_PORT=5007 CONFIG_DIR=./tests/fixtures/instance2/config docker-compose -p instance2 -f docker-compose-tests.yml up -d - docker-compose -p instance2 -f docker-compose-tests.yml ps - - pytest -v --ignore data + # Integration tests first + - pytest -v --ignore data -k integration + # Federation tests (with two local instances) + - pytest -v -s --ignore data -k federation diff --git a/app.py b/app.py index fe0c444..db0d98c 100644 --- a/app.py +++ b/app.py @@ -760,6 +760,8 @@ def api_upload(): @api_required def api_new_note(): source = request.args.get('content') + if not source: + raise ValueError('missing content') content, tags = parse_markdown(source) to = request.args.get('to') cc = [ID+'/followers'] @@ -792,6 +794,8 @@ def api_stream(): @api_required def api_follow(): actor = request.args.get('actor') + if not actor: + raise ValueError('missing actor') if DB.following.find({'remote_actor': actor}).count() > 0: return Response(status=201) diff --git a/config.py b/config.py index 6002350..6cb17e6 100644 --- a/config.py +++ b/config.py @@ -43,7 +43,7 @@ with open('config/me.yml') as f: SUMMARY = conf['summary'] ICON_URL = conf['icon_url'] PASS = conf['pass'] - PUBLIC_INSTANCES = conf.get('public_instances') + PUBLIC_INSTANCES = conf.get('public_instances', []) # TODO(tsileo): choose dark/light style THEME_COLOR = conf.get('theme_color') diff --git a/docker-compose-tests.yml b/docker-compose-tests.yml index af55d05..d45609b 100644 --- a/docker-compose-tests.yml +++ b/docker-compose-tests.yml @@ -1,4 +1,4 @@ -version: '3' +version: '3.5' services: web: build: . @@ -31,3 +31,6 @@ services: environment: - RABBITMQ_ERLANG_COOKIE=secretrabbit - RABBITMQ_NODENAME=rabbit@my-rabbit +networks: + default: + name: microblogpubfede diff --git a/tests/federation_test.py b/tests/federation_test.py new file mode 100644 index 0000000..f345dd0 --- /dev/null +++ b/tests/federation_test.py @@ -0,0 +1,41 @@ +import os + +import requests +from html2text import html2text + + +def resp2plaintext(resp): + """Convert the body of a requests reponse to plain text in order to make basic assertions.""" + return html2text(resp.text) + + +def test_federation(): + """Ensure the homepage is accessible.""" + resp = requests.get('http://localhost:5006') + resp.raise_for_status() + assert resp.status_code == 200 + + resp = requests.get('http://localhost:5007') + resp.raise_for_status() + assert resp.status_code == 200 + + # Keep one session per instance + + # Login + session1 = requests.Session() + resp = session1.post('http://localhost:5006/login', data={'pass': 'hello'}) + assert resp.status_code == 200 + + # Login + session2 = requests.Session() + resp = session2.post('http://localhost:5007/login', data={'pass': 'hello'}) + assert resp.status_code == 200 + + # Instance1 follows instance2 + resp = session1.get('http://localhost:5006/api/follow', params={'actor': 'http://instance2_web_1:5005'}) + assert resp.status_code == 201 + + resp = requests.get('http://localhost:5007/followers', headers={'Accept': 'application/activity+json'}) + resp.raise_for_status() + + assert resp.json()['first']['orderedItems'] == ['http://instance1_web_1:5005'] diff --git a/tests/fixtures/instance1/config/me.yml b/tests/fixtures/instance1/config/me.yml index 2513938..f7c803c 100644 --- a/tests/fixtures/instance1/config/me.yml +++ b/tests/fixtures/instance1/config/me.yml @@ -1,7 +1,7 @@ -username: 'instance_1' +username: 'instance1' name: 'Instance 1' icon_url: 'https://sos-ch-dk-2.exo.io/microblogpub/microblobpub.png' -domain: 'localhost:5006' -summary: 'instance 1 summary' +domain: 'instance1_web_1:5005' +summary: 'instance1 summary' pass: '$2b$12$nEgJMgaYbXSPOvgnqM4jSeYnleKhXqsFgv/o3hg12x79uEdsR4cUy' # hello https: false diff --git a/tests/fixtures/instance2/config/me.yml b/tests/fixtures/instance2/config/me.yml index 844e5c8..22f4127 100644 --- a/tests/fixtures/instance2/config/me.yml +++ b/tests/fixtures/instance2/config/me.yml @@ -1,7 +1,7 @@ -username: 'instance_2' +username: 'instance2' name: 'Instance 2' icon_url: 'https://sos-ch-dk-2.exo.io/microblogpub/microblobpub.png' -domain: 'localhost:5007' -summary: 'instance 2 summary' +domain: 'instance2_web_1:5005' +summary: 'instance2 summary' pass: '$2b$12$nEgJMgaYbXSPOvgnqM4jSeYnleKhXqsFgv/o3hg12x79uEdsR4cUy' # hello https: false