X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=modules%2Flibjuju%2Ftests%2Fintegration%2Ftest_controller.py;h=93e2883b42e4e7e8a16b447a1f841ad2cf64a62f;hp=9c6f7ac45eb939e735b990e29c800ef4b3697d79;hb=refs%2Fchanges%2F94%2F6394%2F1;hpb=421c4a23dc5e60db9596b79ea87cdc19cc463e9b diff --git a/modules/libjuju/tests/integration/test_controller.py b/modules/libjuju/tests/integration/test_controller.py index 9c6f7ac..93e2883 100644 --- a/modules/libjuju/tests/integration/test_controller.py +++ b/modules/libjuju/tests/integration/test_controller.py @@ -1,8 +1,10 @@ import asyncio -import pytest +import subprocess import uuid from juju.client.connection import Connection +from juju.client.jujudata import FileJujuData +from juju.controller import Controller from juju.errors import JujuAPIError import pytest @@ -168,3 +170,31 @@ async def test_add_destroy_model_by_uuid(event_loop): await asyncio.wait_for(_wait_for_model_gone(controller, model_name), timeout=60) + + +# this test must be run serially because it modifies the login password +@pytest.mark.serial +@base.bootstrapped +@pytest.mark.asyncio +async def test_macaroon_auth(event_loop): + jujudata = FileJujuData() + account = jujudata.accounts()[jujudata.current_controller()] + with base.patch_file('~/.local/share/juju/accounts.yaml'): + if 'password' in account: + # force macaroon auth by "changing" password to current password + result = subprocess.run( + ['juju', 'change-user-password'], + input='{0}\n{0}\n'.format(account['password']), + universal_newlines=True, + stderr=subprocess.PIPE) + assert result.returncode == 0, ('Failed to change password: ' + '{}'.format(result.stderr)) + controller = Controller() + try: + await controller.connect() + assert controller.is_connected() + finally: + if controller.is_connected(): + await controller.disconnect() + async with base.CleanModel(): + pass # create and login to model works