From 2491ba82cae3bff0d22cb861868e0359dc4a8124 Mon Sep 17 00:00:00 2001 From: Leo Arias Date: Fri, 5 Feb 2016 10:59:26 -0600 Subject: [PATCH] integration-tests: add login and logout tests LP: #1541391 --- .travis.yml | 7 ++- debian/tests/control | 1 + integration_tests/test_login_logout.py | 83 ++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 integration_tests/test_login_logout.py diff --git a/.travis.yml b/.travis.yml index 2def7fc5d7..b91301f614 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,9 @@ env: # Encrypted Coveralls token. The secret token for your repository can be found at the # bottom of your repository's page on Coveralls. To encrypt it, install the travis gem # and run: - # travis encrypt -r ubuntu-core/snappy COVERALLS_REPO_TOKEN=$secret_token + # travis encrypt -r ubuntu-core/snapcraft COVERALLS_REPO_TOKEN=$secret_token - secure: sc/JVLmOF6OESRSvPqRe3WFujYYbBX6FL0PH8jb6wUeALuqqFJPnb/5aLup0lCxCd+yJ0Puazo7EOX8Rk0txqmEYbufaPiPIxO3e5e32Md5qG5LX9JEUNiG1YAhB9IKqUeZBhWX6H3oOTCfko87j+NfJUOsqlKY4hWvYi4huGamrzIjLOK/lbPS6lSxaejEVACx8xUJax0KaVCu44JJQb1EfNjVkkhN374yFHfo5a8mBT1XwQCvkqXdPJ4phD4gFqqPy5zCrny3cKD10V8DhhhXtyDn71yP2saH4GXyPb9Uzv42n9hvafyZGElqNMgucpwgcnw1zBcHx3JvBye+MPJQhxAebMJ9kRbRsVp5xNh3YlcYw61st4aKutY5L3A42u+rlFzh+5I77ATj5XnPijd0IcHDCPMvaCoqQ2oQcBPtqHSYWMT0kVMA/u/THKwu8A6EtMWv55KNqd+ZW9Y5YHn5ODaAVi8rZby/QFLrMwrrO3Yq11VQFIB3ipafVNtTnAtACG4XkkxSiZ7U5eJQAX4B6Wn4anE9d+b3MzwKOD34pW9UNDqtA2KPutNdKRy6Pt7XAh+fPp9X71hNRegyxVNtqkTozaKCbbmfzZWb1bjC3esKBd9aLgjVy3IAQpQRklHWS6zyMNAXHFg29V16/K2d6KiD1zH+vPY7Kfmkfctc= + - secure: "H58yffyxq1y5RxbEBroXgdkmfc2ttvD8Y6ARh1HCNv0AvAfJ6FA5/Ly2rzBMh/ghXnwumkLHKUYa9dGnbJl0R26U4b7w4YkmSKsrWgNWL1M3iqXdiVsZRJ3K3RaVRya3m9k9DL6b3gR2ZVhz6FeDlaKuOZqCeFxRgXGTB71NrFUKSwXqqE5w10u3woItG3upqr2fPDjJ4bIaffpINpX2MabghfboBB9VbKdLvWiEkH7kEJKNh9zNHZJ4FK5LVt/GAR7CHQhuQsJVQOO+dPE7ZL7FlvqYg33b4ly75kpoo30muzSRXbs+qoSaBe6K41vbVhGdBmtJ9SXxYeuVGunFq8hKOGrSq00vIcPyOonTIZmkWVA/oxuo6viIzuzP1BlU5ulEmQjIbJj5trEzLo3Nd5o8WF19fLpp5MYuU0w28F/TzjarWYU9mw/sPkTJTrV5wHP5jGa/2mcExJBg+MgH60Q8I/uObz9EdovOjLKb1d8x2NSlWozXDyLYVTWIecetEPArhNVuOaGFLpGorDVVTvcrvkLR/rnvY+iqxthuQWuzfEsmkafWFwxgEO/G1mZUI66aq7UdtkToLKCcwi6FCYASQ7AA0mzizWI76teUXr3iJ/HFh7+BfKblfbkgS+eYIjLuAJBxp0NXY6J+eO0gG6n2Pp0emy+PFDJ4xD0XkR0=" matrix: - TEST_SUITE=static - TEST_SUITE=unit @@ -33,9 +34,9 @@ before_script: - sudo lxc config device add xenial /dev/sda1 disk source=$(pwd) path=$(pwd) # Install the snapcraft dependencies. - sudo lxc exec xenial -- apt-get update - - sudo lxc exec xenial -- apt-get install -y pyflakes python-flake8 python3.5 python3-apt python3-docopt python3-coverage python3-fixtures python3-flake8 python3-jsonschema python3-mccabe python3-mock python3-pep8 python3-pip python3-requests python3-requests-oauthlib python3-responses python3-ssoclient python3-testscenarios python3-testtools python3-xdg python3-yaml python3-lxml squashfs-tools python3-progressbar python3-requests-toolbelt + - sudo lxc exec xenial -- apt-get install -y pyflakes python-flake8 python3.5 python3-apt python3-docopt python3-coverage python3-fixtures python3-flake8 python3-jsonschema python3-mccabe python3-mock python3-pep8 python3-pexpect python3-pip python3-requests python3-requests-oauthlib python3-responses python3-ssoclient python3-testscenarios python3-testtools python3-xdg python3-yaml python3-lxml squashfs-tools python3-progressbar python3-requests-toolbelt script: - - sudo -E lxc exec xenial -- su - ubuntu -c "cd $(pwd); ./runtests.sh $TEST_SUITE" + - sudo -E lxc exec xenial -- su - ubuntu -c "cd $(pwd); TEST_USER_PASSWORD=$TEST_USER_PASSWORD ./runtests.sh $TEST_SUITE" after_success: - sudo apt-get install -qq python3-docopt python3-coverage python3-requests || true - pip install coveralls diff --git a/debian/tests/control b/debian/tests/control index 0550dd7385..ce6ece0d84 100644 --- a/debian/tests/control +++ b/debian/tests/control @@ -11,4 +11,5 @@ Depends: @, python3-fixtures, python3-flake8, python3-mccabe, + python3-pexpect, python3-testscenarios diff --git a/integration_tests/test_login_logout.py b/integration_tests/test_login_logout.py new file mode 100644 index 0000000000..40055aeb96 --- /dev/null +++ b/integration_tests/test_login_logout.py @@ -0,0 +1,83 @@ +# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- +# +# Copyright (C) 2016 Canonical Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os + +import fixtures +import pexpect + +import integration_tests + + +class LoginLogoutTestCase(integration_tests.TestCase): + + def setUp(self): + super().setUp() + self.useFixture(fixtures.EnvironmentVariable( + 'UBUNTU_STORE_API_ROOT_URL', + 'https://myapps.developer.staging.ubuntu.com/dev/api/')) + self.useFixture(fixtures.EnvironmentVariable( + 'UBUNTU_STORE_UPLOAD_ROOT_URL', + 'https://upload.apps.staging.ubuntu.com/')) + self.useFixture(fixtures.EnvironmentVariable( + 'UBUNTU_SSO_API_ROOT_URL', + 'https://login.staging.ubuntu.com/api/v2/')) + + def _login(self, email, password, expect_success=True): + process = pexpect.spawn(self.snapcraft_command, ['login']) + process.expect_exact( + 'Enter your Ubuntu One SSO credentials.\r\n' + 'Email: ') + process.sendline(email) + process.expect_exact('Password: ') + process.sendline(password) + process.expect_exact( + "One-time password (just press enter if you don't use two-factor " + "authentication): ") + process.sendline('') + process.expect_exact( + # bold. + '\r\n\x1b[1m' + 'Authenticating against Ubuntu One SSO.' + '\x1b[0m\r\n') + result = 'successful' if expect_success else 'failed' + process.expect_exact( + # bold. + '\x1b[1m' + 'Login {}.'.format(result) + + '\x1b[0m\r\n') + + def _logout(self): + output = self.run_snapcraft('logout') + expected = ('Clearing credentials for Ubuntu One SSO.\n' + 'Credentials cleared.\n') + self.assertEqual(expected, output) + + def test_successful_login(self): + self.addCleanup(self._logout) + password = os.getenv('TEST_USER_PASSWORD', None) + if not password: + self.skipTest('No password provided for the test user.') + + self._login( + 'u1test+snapcraft@canonical.com', password, + expect_success=True) + + def test_failed_login(self): + self._login( + 'u1test+snapcraft@canonical.com', + 'wrongpassword', + expect_success=False)