Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parts/
sdist/
var/
venv/
.venv/
*.egg-info/
.installed.cfg
*.egg
Expand Down
24 changes: 23 additions & 1 deletion vault_service/tests/test_bumblebee.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ def create_app(self):
'TESTING': True,
'PROPAGATE_EXCEPTIONS': True,
'TRAP_BAD_REQUEST_ERRORS': True,
'VAULT_BUMBLEBEE_OPTIONS': {'foo': 'bar'}
'VAULT_BUMBLEBEE_OPTIONS': {'foo': 'bar'},
'VAULT_NECTAR_OPTIONS': {'foo': 'other-bar'}
})
return a


def test_store_data(self):
'''Tests the ability to query site config'''

headers = {'Referer': 'https://dev.scixplorer.org'}

r = self.client.get(url_for('bumblebee.configuration'),
content_type='application/json')
self.assertStatus(r, 200)
Expand All @@ -45,6 +48,25 @@ def test_store_data(self):
content_type='application/json')
self.assertStatus(r, 404)

r = self.client.get(url_for('bumblebee.configuration'),
content_type='application/json', headers=headers)
self.assertStatus(r, 200)
self.assertTrue(r.json == {'foo': 'other-bar'}, 'missing json response')

r = self.client.get(url_for('bumblebee.configuration') + '/foo',
content_type='application/json', headers=headers)
self.assertStatus(r, 200)
self.assertTrue(r.json == 'other-bar', 'missing json response')

r = self.client.get(url_for('bumblebee.configuration') + '/foo',
content_type='application/json', headers=headers)
self.assertStatus(r, 200)
self.assertFalse(r.json == 'bar', 'missing json response')

r = self.client.get(url_for('bumblebee.configuration') + '/foox',
content_type='application/json', headers=headers)
self.assertStatus(r, 404)

class TestOpenURL(TestCaseDatabase):
'''Tests that each route is an http response'''

Expand Down
10 changes: 7 additions & 3 deletions vault_service/views/bumblebee.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from flask import Blueprint
from flask import current_app
from flask import current_app, request
from ..models import Library
from operator import itemgetter
import json
import urllib

from flask_discoverer import advertise

Expand All @@ -12,9 +13,12 @@
@bp.route('/configuration', methods=['GET'])
@bp.route('/configuration/<key>', methods=['GET'])
def configuration(key=None):
'''Allows you to retrieve JSON data from VAULT_BUMBLEBEE_OPTIONS'''
'''Allows you to retrieve JSON data from VAULT_BUMBLEBEE_OPTIONS or VAULT_NECTAR_OPTIONS'''

opts = current_app.config.get('VAULT_BUMBLEBEE_OPTIONS') or {}
if urllib.parse.urlparse(request.referrer).netloc in current_app.config.get("NECTAR_REFERRERS",["dev.scixplorer.org"]):
opts = current_app.config.get('VAULT_NECTAR_OPTIONS') or current_app.config.get('VAULT_BUMBLEBEE_OPTIONS') or {}
else:
opts = current_app.config.get('VAULT_BUMBLEBEE_OPTIONS') or {}

if not isinstance(opts, dict):
return json.dumps({'msg': 'Server misconfiguration, VAULT_BUMBLEBEE_OPTIONS is of an invalid type'}), 500
Expand Down