Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid HTML escaping. 'role' not required in pre-existing accounts. #443

Merged
merged 4 commits into from
Dec 27, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $(VENV) :
$(VENV)/bin/pip install ruff mypy pylint

lint : build
$(VENV)/bin/ruff check src
$(VENV)/bin/ruff check
MYPYPATH=src $(VENV)/bin/mypy --namespace-packages --explicit-package-bases --install-types --non-interactive src
@# These options should be the same flags as in .pre-commit-config.yml, except that I can't get it to
@# work there without the "--ignore-missing-imports" flag, while it does work without it here
Expand Down
24 changes: 10 additions & 14 deletions src/feditest/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,21 @@ def properties_validate(self) -> None:

if self.accounts:
for account in self.accounts:
if 'role' not in account:
raise ValueError('No role name given in account')
if 'role' in account:
if not account['role']:
raise ValueError('Invalid TestPlanConstellationNode account role name: cannot be empty')

if not account['role']:
raise ValueError('Invalid TestPlanConstellationNode account role name: cannot be empty')

if not symbolic_name_validate(account['role']):
raise ValueError(f'Invalid role name in account: "{ account["role" ]}')
if not symbolic_name_validate(account['role']):
raise ValueError(f'Invalid role name in account: "{ account["role" ]}')

if self.non_existing_accounts:
for non_existing_account in self.non_existing_accounts:
if 'role' not in non_existing_account:
raise ValueError('No role name given in non_existing_account')

if not non_existing_account['role']:
raise ValueError('Invalid TestPlanConstellationNode non_existing_account role name: cannot be empty')
if 'role' in non_existing_account:
if not non_existing_account['role']:
raise ValueError('Invalid TestPlanConstellationNode non_existing_account role name: cannot be empty')

if not symbolic_name_validate(non_existing_account['role']):
raise ValueError(f'Invalid role name in non_existing_account: "{ non_existing_account["role" ]}')
if not symbolic_name_validate(non_existing_account['role']):
raise ValueError(f'Invalid role name in non_existing_account: "{ non_existing_account["role" ]}')


@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{%- for test_index, ( _, test_meta ) in enumerate(sorted(transcript.test_meta.items())) %}
<tr>
<td class="namedesc">
<span class="name">{{ permit_line_breaks_in_identifier(test_meta.name) | e }}</span>
<span class="name">{{ permit_line_breaks_in_identifier(test_meta.name) | safe }}</span>
{%- if test_meta.description %}
<span class="description">{{ test_meta.description | e }}</span>
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Test that Accounts and NonExistingAccounts are parsed correctly when given in a TestPlan that
specifies a FallbackFediverseNode
specifies a FallbackFediverseNode. This is the test in which the Accounts have pre-assigned roles.
"""

from typing import cast
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_plan_fixture() -> TestPlan:
return ret


def test_parse(test_plan_fixture: TestPlan) -> None:
def test_populate(test_plan_fixture: TestPlan) -> None:
"""
Tests parsing the TestPlan
"""
Expand All @@ -79,8 +79,14 @@ def test_parse(test_plan_fixture: TestPlan) -> None:
assert acc1.role == 'role1'
assert acc1.actor_acct_uri == 'acct:[email protected]'

acc11 = account_manager.obtain_account_by_role('role1')
assert acc11 == acc1

non_acc1 = cast(FediverseNonExistingAccount | None, account_manager.get_non_existing_account_by_role('nonrole1'))
assert non_acc1
assert non_acc1.role == 'nonrole1'
assert non_acc1.actor_acct_uri == 'acct:[email protected]'

non_acc11 = account_manager.obtain_non_existing_account_by_role('nonrole1')
assert non_acc11 == non_acc1

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
Test that Accounts and NonExistingAccounts are parsed correctly when given in a TestPlan that
specifies a FallbackFediverseNode. This is the test in which the Accounts do not have pre-assigned roles.
"""

from typing import cast

import pytest

import feditest
from feditest.nodedrivers.saas import FediverseSaasNodeDriver
from feditest.protocols.fediverse import (
USERID_ACCOUNT_FIELD,
USERID_NON_EXISTING_ACCOUNT_FIELD,
FediverseAccount,
FediverseNonExistingAccount
)
from feditest.testplan import TestPlan, TestPlanConstellation, TestPlanConstellationNode, TestPlanSessionTemplate


HOSTNAME = 'localhost'
NODE1_ROLE = 'node1-role'


@pytest.fixture(scope="module", autouse=True)
def init():
""" Clean init """
feditest.all_tests = {}
feditest._registered_as_test = {}
feditest._registered_as_test_step = {}
feditest._loading_tests = True

feditest._loading_tests = False
feditest._load_tests_pass2()


@pytest.fixture(autouse=True)
def test_plan_fixture() -> TestPlan:
node_driver = FediverseSaasNodeDriver()
parameters = {
'hostname' : 'example.com', # Avoid interactive question
'app' : 'test-dummy' # Avoid interactive question
}
plan_accounts = [
{
USERID_ACCOUNT_FIELD.name : 'foo'
}
]
plan_non_existing_accounts = [
{
USERID_NON_EXISTING_ACCOUNT_FIELD.name : 'nonfoo'
}
]
node1 = TestPlanConstellationNode(node_driver, parameters, plan_accounts, plan_non_existing_accounts)
constellation = TestPlanConstellation({ NODE1_ROLE : node1 })
session_template = TestPlanSessionTemplate([])
ret = TestPlan(session_template, [ constellation ])
ret.properties_validate()
return ret


def test_populate(test_plan_fixture: TestPlan) -> None:
"""
Tests parsing the TestPlan
"""
node1 = test_plan_fixture.constellations[0].roles[NODE1_ROLE]
node_driver = node1.nodedriver

node_config, account_manager = node_driver.create_configuration_account_manager(NODE1_ROLE, node1)
node_driver.provision_node('test', node_config, account_manager)

acc1 = cast(FediverseAccount | None, account_manager.get_account_by_role('role1'))

assert acc1 is None

acc1 = account_manager.obtain_account_by_role('role1')

assert acc1
assert acc1.role is None
assert acc1.actor_acct_uri == 'acct:[email protected]'

non_acc1 = cast(FediverseNonExistingAccount | None, account_manager.get_non_existing_account_by_role('nonrole1'))

assert non_acc1 is None

non_acc1 = account_manager.obtain_non_existing_account_by_role('nonrole1')

assert non_acc1
assert non_acc1.role is None
assert non_acc1.actor_acct_uri == 'acct:[email protected]'

Loading