Add test for disabling config, update response code
Introduces a test to ensure the correct response code is found when attempting to update the config when disabled, and ensure default config is unchanged when posting a new config dict. Attempting to update the config using the API when disabled now returns a 403 code + redirect.
This commit is contained in:
parent
45f1f1e857
commit
03ee15a938
1
app.json
1
app.json
|
@ -85,7 +85,6 @@
|
|||
"value": "",
|
||||
"required": false
|
||||
},
|
||||
|
||||
"WHOOGLE_CONFIG_DARK": {
|
||||
"description": "[CONFIG] Enable dark mode (set to 1 or leave blank)",
|
||||
"value": "",
|
||||
|
|
|
@ -241,7 +241,7 @@ def config():
|
|||
config_disabled = app.config['CONFIG_DISABLE']
|
||||
if request.method == 'GET':
|
||||
return json.dumps(g.user_config.__dict__)
|
||||
elif request.method == 'PUT' and not config_disabled:
|
||||
elif request.method == 'PUT' and not config_disabled:
|
||||
if 'name' in request.args:
|
||||
config_pkl = os.path.join(
|
||||
app.config['CONFIG_PATH'],
|
||||
|
@ -273,7 +273,7 @@ def config():
|
|||
session['config'] = config_data
|
||||
return redirect(config_data['url'])
|
||||
else:
|
||||
return json.dumps({})
|
||||
return redirect(url_for('.index'), code=403)
|
||||
|
||||
|
||||
@app.route('/url', methods=['GET'])
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from app import app
|
||||
|
||||
import json
|
||||
|
||||
from test.conftest import demo_config
|
||||
|
@ -52,6 +54,17 @@ def test_config(client):
|
|||
assert rv._status_code == 200
|
||||
assert custom_config.replace('&', '&') in str(rv.data)
|
||||
|
||||
# Test disabling changing config from client
|
||||
app.config['CONFIG_DISABLE'] = 1
|
||||
dark_mod = not demo_config['dark']
|
||||
demo_config['dark'] = dark_mod
|
||||
rv = client.post('/config', data=demo_config)
|
||||
assert rv._status_code == 403
|
||||
|
||||
rv = client.get('/config')
|
||||
config = json.loads(rv.data)
|
||||
assert config['dark'] != dark_mod
|
||||
|
||||
|
||||
def test_opensearch(client):
|
||||
rv = client.get('/opensearch.xml')
|
||||
|
|
Loading…
Reference in New Issue
Block a user