mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
monkeysphere: Add functional tests for import/publish keys
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
a75b415624
commit
f52e13d316
41
functional_tests/features/monkeysphere.feature
Normal file
41
functional_tests/features/monkeysphere.feature
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#
|
||||||
|
# This file is part of FreedomBox.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
@apps @monkeysphere
|
||||||
|
Feature: Monkeysphere
|
||||||
|
Import and publish OpenPGP keys for SSH and HTTPS keys
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given I'm a logged in user
|
||||||
|
And the monkeysphere application is installed
|
||||||
|
And the domain name is set to mydomain.example
|
||||||
|
|
||||||
|
Scenario: Import SSH keys
|
||||||
|
When I import SSH key for mydomain.example in monkeysphere
|
||||||
|
Then the SSH key should imported for mydomain.example in monkeysphere
|
||||||
|
|
||||||
|
Scenario: Import HTTPS keys
|
||||||
|
When I import HTTPS key for mydomain.example in monkeysphere
|
||||||
|
Then the HTTPS key should imported for mydomain.example in monkeysphere
|
||||||
|
|
||||||
|
Scenario: Publish SSH keys
|
||||||
|
Given the SSH key for mydomain.example is imported in monkeysphere
|
||||||
|
Then I should be able to publish SSH key for mydomain.example in monkeysphere
|
||||||
|
|
||||||
|
Scenario: Publish HTTPS keys
|
||||||
|
Given the HTTPS key for mydomain.example is imported in monkeysphere
|
||||||
|
Then I should be able to publish HTTPS key for mydomain.example in monkeysphere
|
||||||
@ -295,3 +295,30 @@ def upgrades_enable_automatic(browser, enable):
|
|||||||
def upgrades_assert_automatic(browser, enabled):
|
def upgrades_assert_automatic(browser, enabled):
|
||||||
should_be_enabled = (enabled == 'enabled')
|
should_be_enabled = (enabled == 'enabled')
|
||||||
assert system.upgrades_get_automatic(browser) == should_be_enabled
|
assert system.upgrades_get_automatic(browser) == should_be_enabled
|
||||||
|
|
||||||
|
|
||||||
|
@given(
|
||||||
|
parsers.parse(
|
||||||
|
'the {key_type:w} key for {domain:S} is imported in monkeysphere'))
|
||||||
|
def monkeysphere_given_import_key(browser, key_type, domain):
|
||||||
|
system.monkeysphere_import_key(browser, key_type.lower(), domain)
|
||||||
|
|
||||||
|
|
||||||
|
@when(
|
||||||
|
parsers.parse('I import {key_type:w} key for {domain:S} in monkeysphere'))
|
||||||
|
def monkeysphere_import_key(browser, key_type, domain):
|
||||||
|
system.monkeysphere_import_key(browser, key_type.lower(), domain)
|
||||||
|
|
||||||
|
|
||||||
|
@then(
|
||||||
|
parsers.parse(
|
||||||
|
'the {key_type:w} key should imported for {domain:S} in monkeysphere'))
|
||||||
|
def monkeysphere_assert_imported_key(browser, key_type, domain):
|
||||||
|
system.monkeysphere_assert_imported_key(browser, key_type.lower(), domain)
|
||||||
|
|
||||||
|
|
||||||
|
@then(
|
||||||
|
parsers.parse('I should be able to publish {key_type:w} key for '
|
||||||
|
'{domain:S} in monkeysphere'))
|
||||||
|
def monkeysphere_publish_key(browser, key_type, domain):
|
||||||
|
system.monkeysphere_publish_key(browser, key_type.lower(), domain)
|
||||||
|
|||||||
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
from support import application, config
|
from support import application, config
|
||||||
|
|
||||||
|
from . import application
|
||||||
from .interface import default_url, nav_to_module, submit
|
from .interface import default_url, nav_to_module, submit
|
||||||
|
from .service import wait_for_page_update
|
||||||
|
|
||||||
config_page_title_language_map = {
|
config_page_title_language_map = {
|
||||||
'da': 'Generel Konfiguration',
|
'da': 'Generel Konfiguration',
|
||||||
@ -329,3 +331,47 @@ def upgrades_get_automatic(browser):
|
|||||||
"""Return whether automatic software upgrades is enabled."""
|
"""Return whether automatic software upgrades is enabled."""
|
||||||
nav_to_module(browser, 'upgrades')
|
nav_to_module(browser, 'upgrades')
|
||||||
return browser.find_by_name('auto_upgrades_enabled').first.checked
|
return browser.find_by_name('auto_upgrades_enabled').first.checked
|
||||||
|
|
||||||
|
|
||||||
|
def _monkeysphere_find_domain(browser, key_type, domain_type, domain):
|
||||||
|
"""Iterate every domain of a given type which given key type."""
|
||||||
|
keys_of_type = browser.find_by_css(
|
||||||
|
'.monkeysphere-service-{}'.format(key_type))
|
||||||
|
for key_of_type in keys_of_type:
|
||||||
|
search_domains = key_of_type.find_by_css(
|
||||||
|
'.monkeysphere-{}-domain'.format(domain_type))
|
||||||
|
for search_domain in search_domains:
|
||||||
|
if search_domain.text == domain:
|
||||||
|
return key_of_type, search_domain
|
||||||
|
|
||||||
|
raise IndexError('Domain not found')
|
||||||
|
|
||||||
|
|
||||||
|
def monkeysphere_import_key(browser, key_type, domain):
|
||||||
|
"""Import a key of specified type for given domain into monkeysphere."""
|
||||||
|
try:
|
||||||
|
monkeysphere_assert_imported_key(browser, key_type, domain)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
key, _ = _monkeysphere_find_domain(browser, key_type, 'importable', domain)
|
||||||
|
with wait_for_page_update(browser):
|
||||||
|
key.find_by_css('.button-import').click()
|
||||||
|
|
||||||
|
|
||||||
|
def monkeysphere_assert_imported_key(browser, key_type, domain):
|
||||||
|
"""Assert that a key of specified type for given domain was imported.."""
|
||||||
|
nav_to_module(browser, 'monkeysphere')
|
||||||
|
return _monkeysphere_find_domain(browser, key_type, 'imported', domain)
|
||||||
|
|
||||||
|
|
||||||
|
def monkeysphere_publish_key(browser, key_type, domain):
|
||||||
|
"""Publish a key of specified type for given domain from monkeysphere."""
|
||||||
|
nav_to_module(browser, 'monkeysphere')
|
||||||
|
key, _ = _monkeysphere_find_domain(browser, key_type, 'imported', domain)
|
||||||
|
with wait_for_page_update(browser):
|
||||||
|
key.find_by_css('.button-publish').click()
|
||||||
|
|
||||||
|
application.wait_for_config_update(browser, 'monkeysphere')
|
||||||
|
|||||||
@ -80,7 +80,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for key in status.keys.values|dictsort:"ssh_fingerprint" %}
|
{% for key in status.keys.values|dictsort:"ssh_fingerprint" %}
|
||||||
<tr>
|
<tr class="monkeysphere-service-{{ key.service }}">
|
||||||
<td>
|
<td>
|
||||||
{% if key.service == 'ssh' %}
|
{% if key.service == 'ssh' %}
|
||||||
{% trans "Secure Shell" %}
|
{% trans "Secure Shell" %}
|
||||||
@ -93,22 +93,31 @@
|
|||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
{% for domain in key.all_domains %}
|
{% for domain in key.all_domains %}
|
||||||
<li>
|
{% if domain not in key.imported_domains %}
|
||||||
{% if domain not in key.imported_domains %}
|
<li>
|
||||||
<span class="label label-default"
|
<span class="label label-default"
|
||||||
><span class="glyphicon glyphicon-remove"
|
><span class="glyphicon glyphicon-remove"
|
||||||
aria-hidden="true"></span></span>
|
aria-hidden="true"></span></span>
|
||||||
{% elif domain not in key.available_domains %}
|
<span class="monkeysphere-importable-domain"
|
||||||
|
>{{ domain }}</span>
|
||||||
|
</li>
|
||||||
|
{% elif domain not in key.available_domains %}
|
||||||
|
<li>
|
||||||
<span class="label label-warning"
|
<span class="label label-warning"
|
||||||
><span class="glyphicon glyphicon-warning-sign"
|
><span class="glyphicon glyphicon-warning-sign"
|
||||||
aria-hidden="true"></span></span>
|
aria-hidden="true"></span></span>
|
||||||
{% else %}
|
<span class="monkeysphere-unavailable-domain"
|
||||||
|
>{{ domain }}</span>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li>
|
||||||
<span class="label label-success"
|
<span class="label label-success"
|
||||||
><span class="glyphicon glyphicon-ok"
|
><span class="glyphicon glyphicon-ok"
|
||||||
aria-hidden="true"></span></span>
|
aria-hidden="true"></span></span>
|
||||||
{% endif %}
|
<span class="monkeysphere-imported-domain"
|
||||||
{{ domain }}
|
>{{ domain }}</span>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
@ -126,29 +135,29 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if not key.openpgp_fingerprint %}
|
{% if not key.openpgp_fingerprint %}
|
||||||
<form class="form pull-right" method="post"
|
<form class="form pull-right form-import" method="post"
|
||||||
action="{% url 'monkeysphere:import' key.ssh_fingerprint %}">
|
action="{% url 'monkeysphere:import' key.ssh_fingerprint %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary btn-sm pull-right">
|
<button type="submit" class="btn btn-primary btn-sm pull-right button-import">
|
||||||
{% trans "Import Key" %}</button>
|
{% trans "Import Key" %}</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if not running %}
|
{% if not running %}
|
||||||
<form class="form pull-right" method="post"
|
<form class="form pull-right form-publish" method="post"
|
||||||
action="{% url 'monkeysphere:publish' key.openpgp_fingerprint %}">
|
action="{% url 'monkeysphere:publish' key.openpgp_fingerprint %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<button type="submit" class="btn btn-warning btn-sm pull-right">
|
<button type="submit" class="btn btn-warning btn-sm pull-right button-publish">
|
||||||
{% trans "Publish Key" %}</button>
|
{% trans "Publish Key" %}</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if key.importable_domains %}
|
{% if key.importable_domains %}
|
||||||
<form class="form pull-right" method="post"
|
<form class="form pull-right form-add-domain" method="post"
|
||||||
action="{% url 'monkeysphere:import' key.ssh_fingerprint %}">
|
action="{% url 'monkeysphere:import' key.ssh_fingerprint %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary btn-sm pull-right">
|
<button type="submit" class="btn btn-primary btn-sm pull-right button-add-domains">
|
||||||
{% trans "Add Domains" %}</button>
|
{% trans "Add Domains" %}</button>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user