mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
samba: tests: Convert functional tests to non-BDD python format
- Also, fix an issue where share writability tests were performed always as an admin user. Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
5367980163
commit
e31053eb92
@ -1,53 +0,0 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
@apps @samba
|
||||
Feature: Samba File Sharing
|
||||
Configure samba file sharing service.
|
||||
|
||||
Background:
|
||||
Given I'm a logged in user
|
||||
Given the network device is in the internal firewall zone
|
||||
Given the samba application is installed
|
||||
|
||||
Scenario: Enable samba application
|
||||
Given the samba application is disabled
|
||||
When I enable the samba application
|
||||
Then the samba service should be running
|
||||
|
||||
Scenario: Enable open samba share
|
||||
Given the samba application is enabled
|
||||
When I enable the open samba share
|
||||
Then I can write to the open samba share
|
||||
And a guest user can write to the open samba share
|
||||
|
||||
Scenario: Enable group samba share
|
||||
Given the samba application is enabled
|
||||
When I enable the group samba share
|
||||
Then I can write to the group samba share
|
||||
And a guest user can't access the group samba share
|
||||
|
||||
Scenario: Enable home samba share
|
||||
Given the samba application is enabled
|
||||
When I enable the home samba share
|
||||
Then I can write to the home samba share
|
||||
And a guest user can't access the home samba share
|
||||
|
||||
Scenario: Disable open samba share
|
||||
Given the samba application is enabled
|
||||
When I disable the open samba share
|
||||
Then the open samba share should not be available
|
||||
|
||||
@backups
|
||||
Scenario: Backup and restore samba
|
||||
Given the samba application is enabled
|
||||
When I enable the home samba share
|
||||
And I create a backup of the samba app data with name test_samba
|
||||
And I disable the home samba share
|
||||
And I restore the samba app data backup with name test_samba
|
||||
Then the samba service should be running
|
||||
And I can write to the home samba share
|
||||
|
||||
Scenario: Disable samba application
|
||||
Given the samba application is enabled
|
||||
When I disable the samba application
|
||||
Then the samba service should not be running
|
||||
@ -8,40 +8,65 @@ import string
|
||||
import subprocess
|
||||
import urllib
|
||||
|
||||
from pytest_bdd import parsers, scenarios, then, when
|
||||
import pytest
|
||||
|
||||
from plinth.tests import functional
|
||||
|
||||
scenarios('samba.feature')
|
||||
pytestmark = [pytest.mark.apps, pytest.mark.samba]
|
||||
|
||||
|
||||
@when(parsers.parse('I {task:w} the {share_type:w} samba share'))
|
||||
def samba_enable_share(session_browser, task, share_type):
|
||||
if task == 'enable':
|
||||
_set_share(session_browser, share_type, status='enabled')
|
||||
elif task == 'disable':
|
||||
_set_share(session_browser, share_type, status='disabled')
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
def fixture_background(session_browser):
|
||||
"""Login and install the app."""
|
||||
functional.login(session_browser)
|
||||
functional.install(session_browser, 'samba')
|
||||
functional.app_enable(session_browser, 'samba')
|
||||
functional.networks_set_firewall_zone(session_browser, 'internal')
|
||||
yield
|
||||
functional.login(session_browser)
|
||||
functional.app_disable(session_browser, 'samba')
|
||||
|
||||
|
||||
@then(parsers.parse('I can write to the {share_type:w} samba share'))
|
||||
def samba_share_should_be_writable(share_type):
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_login(session_browser):
|
||||
"""Login fixture."""
|
||||
functional.login(session_browser)
|
||||
functional.app_enable(session_browser, 'samba')
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.backups
|
||||
def test_backup(session_browser):
|
||||
"""Test backing up and restoring."""
|
||||
_set_share(session_browser, 'home', status='enabled')
|
||||
functional.backup_create(session_browser, 'samba', 'test_samba')
|
||||
_set_share(session_browser, 'home', status='disabled')
|
||||
functional.backup_restore(session_browser, 'samba', 'test_samba')
|
||||
assert functional.service_is_running(session_browser, 'samba')
|
||||
_assert_share_is_writable('home')
|
||||
|
||||
|
||||
def test_enable_disable(session_browser):
|
||||
"""Test enabling and disabling the app."""
|
||||
functional.app_disable(session_browser, 'samba')
|
||||
assert functional.service_is_not_running(session_browser, 'samba')
|
||||
|
||||
functional.app_enable(session_browser, 'samba')
|
||||
assert functional.service_is_running(session_browser, 'samba')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('share_type', ['open', 'group', 'home'])
|
||||
def test_enable_disable_samba_share(session_browser, share_type):
|
||||
"""Test enabling and disabling Samba share."""
|
||||
_set_share(session_browser, share_type, status='enabled')
|
||||
|
||||
_assert_share_is_writable(share_type)
|
||||
if share_type == 'open':
|
||||
_assert_share_is_writable(share_type, as_guest=True)
|
||||
else:
|
||||
_assert_share_is_not_accessible(share_type, as_guest=True)
|
||||
|
||||
|
||||
@then(parsers.parse('a guest user can write to the {share_type:w} samba share')
|
||||
)
|
||||
def samba_share_should_be_writable_to_guest(share_type):
|
||||
_assert_share_is_writable(share_type, as_guest=True)
|
||||
|
||||
|
||||
@then(
|
||||
parsers.parse('a guest user can\'t access the {share_type:w} samba share'))
|
||||
def samba_share_should_not_be_accessible_to_guest(share_type):
|
||||
_assert_share_is_not_accessible(share_type, as_guest=True)
|
||||
|
||||
|
||||
@then(parsers.parse('the {share_type:w} samba share should not be available'))
|
||||
def samba_share_should_not_be_available(share_type):
|
||||
_set_share(session_browser, share_type, status='disabled')
|
||||
_assert_share_is_not_available(share_type)
|
||||
|
||||
|
||||
@ -91,7 +116,7 @@ def _write_to_share(share_type, as_guest=False):
|
||||
|
||||
def _assert_share_is_writable(share_type, as_guest=False):
|
||||
"""Assert that samba share is writable."""
|
||||
output = _write_to_share(share_type, as_guest=False)
|
||||
output = _write_to_share(share_type, as_guest)
|
||||
|
||||
assert not output, output
|
||||
|
||||
@ -108,7 +133,7 @@ def _assert_share_is_not_accessible(share_type, as_guest=False):
|
||||
|
||||
|
||||
def _assert_share_is_not_available(share_type):
|
||||
"""Assert that samba share is not accessible."""
|
||||
"""Assert that samba share is not available."""
|
||||
try:
|
||||
_write_to_share(share_type)
|
||||
except subprocess.CalledProcessError as err:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user