From 78950b1ba3dfaddc7bb2672dfa0fb1cac11432cc Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Mon, 29 Oct 2018 18:59:51 -0700 Subject: [PATCH] tahoe: Add functional tests Reviewed-by: James Valleroy --- functional_tests/features/tahoe.feature | 57 +++++++++++++++++++ .../step_definitions/application.py | 32 +++++++++++ functional_tests/support/application.py | 28 +++++++++ 3 files changed, 117 insertions(+) create mode 100644 functional_tests/features/tahoe.feature diff --git a/functional_tests/features/tahoe.feature b/functional_tests/features/tahoe.feature new file mode 100644 index 000000000..fa78bcc59 --- /dev/null +++ b/functional_tests/features/tahoe.feature @@ -0,0 +1,57 @@ +# +# 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 . +# + +# TODO: When tahoe-lafs is restarted, it leaves a .gnupg folder in +# /var/lib/tahoe-lafs and failes to start in the next run. Enable tests after +# this is fixed. + +@apps @tahoe @skip +Feature: Tahoe-LAFS distribute file storage + Run the Tahoe distribute file storage server + +Background: + Given I'm a logged in user + And the domain name is set to mydomain.example + And the tahoe application is installed + And the domain name for tahoe is set to mydomain.example + +Scenario: Enable tahoe application + Given the tahoe application is disabled + When I enable the tahoe application + Then the tahoe service should be running + +Scenario: Disable tahoe application + Given the tahoe application is enabled + When I disable the tahoe application + Then the tahoe service should not be running + +Scenario: Default tahoe introducers + Given the tahoe application is enabled + Then mydomain.example should be a tahoe local introducer + And mydomain.example should be a tahoe connected introducer + +Scenario: Add tahoe introducer + Given the tahoe application is enabled + And anotherdomain.example is not a tahoe introducer + When I add anotherdomain.example as a tahoe introducer + Then anotherdomain.example should be a tahoe connected introducer + +Scenario: Remove tahoe introducer + Given the tahoe application is enabled + And anotherdomain.example is a tahoe introducer + When I remove anotherdomain.example as a tahoe introducer + Then anotherdomain.example should not be a tahoe connected introducer diff --git a/functional_tests/step_definitions/application.py b/functional_tests/step_definitions/application.py index 91cb1d2a8..d0e8f5e9a 100644 --- a/functional_tests/step_definitions/application.py +++ b/functional_tests/step_definitions/application.py @@ -328,3 +328,35 @@ def tor_download_software_over_tor_enable(browser, enable): parsers.parse('download software packages over tor should be {enabled:w}')) def tor_assert_download_software_over_tor(browser, enabled): application.tor_assert_feature_enabled(browser, 'software', enabled) + + +@then(parsers.parse('{domain:S} should be a tahoe {introducer_type:w} introducer')) +def tahoe_assert_introducer(browser, domain, introducer_type): + assert application.tahoe_get_introducer(browser, domain, introducer_type) + + +@then(parsers.parse('{domain:S} should not be a tahoe {introducer_type:w} introducer')) +def tahoe_assert_not_introducer(browser, domain, introducer_type): + assert not application.tahoe_get_introducer(browser, domain, introducer_type) + + +@given(parsers.parse('{domain:S} is not a tahoe introducer')) +def tahoe_given_remove_introducer(browser, domain): + if application.tahoe_get_introducer(browser, domain, 'connected'): + application.tahoe_remove_introducer(browser, domain) + + +@when(parsers.parse('I add {domain:S} as a tahoe introducer')) +def tahoe_add_introducer(browser, domain): + application.tahoe_add_introducer(browser, domain) + + +@given(parsers.parse('{domain:S} is a tahoe introducer')) +def tahoe_given_add_introducer(browser, domain): + if not application.tahoe_get_introducer(browser, domain, 'connected'): + application.tahoe_add_introducer(browser, domain) + + +@when(parsers.parse('I remove {domain:S} as a tahoe introducer')) +def tahoe_remove_introducer(browser, domain): + application.tahoe_remove_introducer(browser, domain) diff --git a/functional_tests/support/application.py b/functional_tests/support/application.py index 390809ad3..f96fd600d 100644 --- a/functional_tests/support/application.py +++ b/functional_tests/support/application.py @@ -391,3 +391,31 @@ def tor_assert_hidden_services(browser): """Assert that hidden service information is shown.""" interface.nav_to_module(browser, 'tor') assert browser.find_by_css('.tor-hs .tor-hs-hostname') + + +def tahoe_get_introducer(browser, domain, introducer_type): + """Return an introducer element with a given type from tahoe-lafs.""" + interface.nav_to_module(browser, 'tahoe') + css_class = '.{}-introducers .introducer-furl'.format(introducer_type) + for furl in browser.find_by_css(css_class): + if domain in furl.text: + return furl.parent + + return None + + +def tahoe_add_introducer(browser, domain): + """Add a new introducer into tahoe-lafs.""" + interface.nav_to_module(browser, 'tahoe') + + furl = 'pb://ewe4zdz6kxn7xhuvc7izj2da2gpbgeir@tcp:{}:3456/' \ + 'fko4ivfwgqvybppwar3uehkx6spaaou7'.format(domain) + browser.fill('pet_name', 'testintroducer') + browser.fill('furl', furl) + submit(browser, form_class='form-add-introducer') + + +def tahoe_remove_introducer(browser, domain): + """Remove an introducer from tahoe-lafs.""" + introducer = tahoe_get_introducer(browser, domain, 'connected') + submit(browser, element=introducer.find_by_css('.form-remove'))