mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-15 09:51:21 +00:00
- Since we are going to be an OpenID Provider, we need to fix the URLs that
other apps will be configured with for authentication. So change now from
/plinth to /freedombox. If done later, it will be harder since all the
configuration files for all dependent apps will need to be updated.
Tests:
- App availability checking works. Request goes to /freedombox URL
- Favicon is served properly and through /favicon.ico URL
- Redirection happens from / to /freedombox directly
- UI is available on /freedombox and on /plinth
- Manual page show /freedombox as the URL in two places
- Static files are successfully served from /freedombox URLs. URLs inside page
start with /freedombox
- backup, bepasty, calibre, config, dynamicdns, ejabberd, featherwiki, gitweb,
ikiwiki, kiwix, miniflux, names, openvpn, shadowsocks, shadowsocksserver,
sharing, shapshot, tiddlywiki, users, wireguard, jsxc, matrixsynapse, first
wizard, storage, samba, tags functional tests work. Backup/restore test for
matrixsynapse fails due to an unrelated bug (server not restarted after
restore).
- Setting the home page works:
- Having /plinth in the home page configuration works. Shows selection
correctly.
- Setting to app works. Shows selection correctly.
- Setting to user home page (sets /freedombox). Shows selection correctly.
- Setting to apache default works. Shows selection correctly.
- Changing back to FreedomBox service works. Shows selection correctly.
- Unit tests work
- Configuration page shows /freedombox in description but not /plinth
- Diagnostics show /freedombox in tests
- Roundcube URL link in email app has /freedombox
- email loads the page /.well-known/autoconfig/mail/config-v1.1.xml correctly
- email app shows /freedombox/apps/roundcube for /roundcube if roundcube is not
installed.
- networks: router configuration page shows URL starting with /freedombox.
- snapshot: Shows URL starting with /freedombox on the app page
- js licenses page uses /freedombox prefix for JSXC.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
137 lines
4.5 KiB
Python
137 lines
4.5 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Tests for config module.
|
|
"""
|
|
|
|
import os
|
|
import pathlib
|
|
from unittest.mock import Mock, patch
|
|
|
|
import pytest
|
|
|
|
from plinth import __main__ as plinth_main
|
|
from plinth import utils
|
|
from plinth.modules.apache import uws_directory_of_user, uws_url_of_user
|
|
from plinth.modules.config import (_home_page_scid2url, change_home_page,
|
|
get_home_page, home_page_url2scid)
|
|
|
|
|
|
def test_homepage_mapping():
|
|
"""Basic tests for homepage functions."""
|
|
func = home_page_url2scid
|
|
assert func(None) == 'apache-default'
|
|
assert func('/unknown/url') is None
|
|
assert func('/plinth/') == 'freedombox'
|
|
assert func('/plinth') == 'freedombox'
|
|
assert func('plinth') == 'freedombox'
|
|
assert func('/freedombox/') == 'freedombox'
|
|
assert func('/freedombox') == 'freedombox'
|
|
assert func('freedombox') == 'freedombox'
|
|
assert func('/index.html') == 'apache-default'
|
|
assert func('/~user') == 'uws-user'
|
|
assert func('/~user/whatever/else') == 'uws-user'
|
|
|
|
func = _home_page_scid2url
|
|
assert func('freedombox') == '/freedombox/'
|
|
assert func('apache-default') is None
|
|
|
|
|
|
def test_homepage_mapping_skip_ci():
|
|
"""Special tests for homepage functions."""
|
|
try:
|
|
user = os.getlogin()
|
|
except OSError:
|
|
# See msg383161 in https://bugs.python.org/issue40821
|
|
reason = "Needs access to ~/ directory. " \
|
|
+ "CI sandboxed workspace doesn't provide it."
|
|
pytest.skip(reason)
|
|
uws_directory = uws_directory_of_user(user)
|
|
uws_url = uws_url_of_user(user)
|
|
uws_scid = home_page_url2scid(uws_url)
|
|
|
|
# Check test's precondition:
|
|
if os.path.exists(uws_directory):
|
|
# Don't blindly remove a pre-existing directory. Just skip the test.
|
|
reason = "UWS directory {} exists already.".format(uws_directory)
|
|
pytest.skip(reason)
|
|
|
|
# AC: Return scid if UWS directory exists:
|
|
try:
|
|
os.mkdir(uws_directory)
|
|
except Exception:
|
|
reason = "Needs access to ~/ directory. " \
|
|
+ "CI sandboxed workspace doesn't provide it."
|
|
pytest.skip(reason)
|
|
assert _home_page_scid2url(uws_scid) == uws_url
|
|
|
|
# AC: Return None if it doesn't:
|
|
os.rmdir(uws_directory)
|
|
assert _home_page_scid2url(uws_scid) == '/freedombox/'
|
|
|
|
|
|
@patch(
|
|
'plinth.frontpage.Shortcut.list',
|
|
Mock(return_value=[
|
|
Mock(url='url/for/' + id, component_id=id) for id in ('a', 'b')
|
|
]))
|
|
@pytest.mark.usefixtures('needs_root')
|
|
def test_homepage_field():
|
|
"""Test homepage changes.
|
|
|
|
Test Cases:
|
|
1) FreedomBox Homepage (default),
|
|
2) Apache default,
|
|
3) A user's website of an...
|
|
3.1) unexisting user
|
|
3.2) existing user without a page
|
|
3.3) existing user page.
|
|
4) A FreedomBox App.
|
|
4.1) unknown app
|
|
4.2) uninstalled app
|
|
4.3) disabled app
|
|
4.4) enabled app
|
|
|
|
Note: If run on a pristine unconfigured FreedomBox, this test will leave
|
|
the homepage default-configured. (Imperfect cleanup in such case).
|
|
|
|
Note: We take fbx as website user because of our testing container.
|
|
|
|
Pending: - Specific test cases to distinguish 4.1,2,3.
|
|
Currently they share the same test case.
|
|
- Search for another valid user apart from fbx.
|
|
"""
|
|
user = 'test_' + utils.random_string(size=12)
|
|
uws_directory = uws_directory_of_user(user)
|
|
uws_url = uws_url_of_user(user)
|
|
uws_scid = home_page_url2scid(uws_url)
|
|
|
|
default_home_page = 'freedombox'
|
|
original_home_page = get_home_page() or default_home_page
|
|
change_home_page(default_home_page) # Set to known value explicitly
|
|
|
|
# AC: invalid changes fall back to default:
|
|
for scid in ('uws-unexisting', uws_scid, 'missing_app'):
|
|
change_home_page(scid)
|
|
assert get_home_page() == default_home_page
|
|
|
|
# AC: valid changes actually happen:
|
|
pathlib.Path(uws_directory).mkdir(parents=True)
|
|
for scid in ('b', 'a', uws_scid, 'apache-default', 'freedombox'):
|
|
change_home_page(scid)
|
|
assert get_home_page() == scid
|
|
|
|
# cleanup:
|
|
change_home_page(original_home_page)
|
|
os.rmdir(uws_directory)
|
|
assert get_home_page() == original_home_page
|
|
|
|
|
|
def test_locale_path():
|
|
"""
|
|
Test that the 'locale' directory is in the same folder as __main__.py.
|
|
This is required for detecting translated languages.
|
|
"""
|
|
plinth_dir = os.path.dirname(plinth_main.__file__)
|
|
locale_dir = os.path.join(plinth_dir, 'locale')
|
|
assert os.path.isdir(locale_dir)
|