def test_print_export_vars_default_profile(self): with ArgvContext(program, '-e', '--default', '-t'): # clean up as going to mutate this self.config.close() # now start new test case self.config = tempfile.NamedTemporaryFile() conf_ini = b""" [default] sso_start_url = https://petshop.awsapps.com/start sso_region = ap-southeast-2 sso_account_id = 123456789 sso_role_name = Engineering region = ap-southeast-2 output = json """ self.config.write(conf_ini) self.config.seek(0) self.config.read() cli.aws_config_file = self.config.name cli.main() verify(cli, times=3).invoke(...)
def test_sso_cache_expires(self): with ArgvContext(program, '-p', 'dev', '-d'), self.assertRaises(SystemExit) as x: # clean up as going to mutate this self.sso_cache_json.close() self.sso_cache_dir.cleanup() # start new test case self.sso_cache_dir = tempfile.TemporaryDirectory() self.sso_cache_json = tempfile.NamedTemporaryFile( dir=self.sso_cache_dir.name, suffix='.json') cache_json = { "startUrl": "https://petshop.awsapps.com/start", "region": "ap-southeast-2", "accessToken": "longTextA.AverylOngText", "expiresAt": f"{str((datetime.utcnow()).isoformat())[:-7]}UTC" } self.sso_cache_json.write(json.dumps(cache_json).encode('utf-8')) self.sso_cache_json.seek(0) self.sso_cache_json.read() cli.AWS_SSO_CACHE_PATH = self.sso_cache_dir.name cli.main() self.assertEqual(x.exception.code, 1)
def test_not_equal_sso_region(self): with ArgvContext(program, '-p', 'dev', '-t'), self.assertRaises(SystemExit) as x: # clean up as going to mutate this self.config.close() # now start new test case self.config = tempfile.NamedTemporaryFile() conf_ini = b""" [profile dev] sso_start_url = https://petshop.awsapps.com/start sso_region = us-east-2 sso_account_id = 123456789 sso_role_name = AdministratorAccess region = us-east-2 output = json """ self.config.write(conf_ini) self.config.seek(0) self.config.read() cli.aws_config_file = self.config.name cli.main() self.assertEqual(x.exception.code, 1)
def test_sso_cache_not_found(self): with ArgvContext(program, '-d'), self.assertRaises(SystemExit) as x: cli.AWS_SSO_CACHE_PATH = "mock.sso.cache.json" cli.main() self.assertEqual(x.exception.code, 1)
def test_credential_not_found(self): with ArgvContext(program, '-d'), self.assertRaises(SystemExit) as x: cli.AWS_CREDENTIAL_PATH = "mock.credentials" cli.main() self.assertEqual(x.exception.code, 1)
def test_config_not_found(self): with ArgvContext(program, '-d'), self.assertRaises(SystemExit) as x: cli.AWS_CONFIG_PATH = "mock.config" cli.main() self.assertEqual(x.exception.code, 1)
def test_profile_not_found(self): with ArgvContext(program, '-p', uuid.uuid4().hex, '-d'), self.assertRaises(SystemExit) as x: cli.main() self.assertEqual(x.exception.code, 1)
def test_invalid_bin(self): with ArgvContext(program, '-b', f'/usr/local/bin/aws{randint(3, 9)}', '-d'), self.assertRaises(SystemExit) as x: cli.main() self.assertEqual(x.exception.code, 1)
def test_unknown_command(self): with ArgvContext(program, uuid.uuid4().hex), self.assertRaises(SystemExit) as x: cli.main() self.assertEqual(x.exception.code, 2)
def test_version_command(self): with ArgvContext(program, 'version'), self.assertRaises(SystemExit) as x: cli.main() self.assertEqual(x.exception.code, 0)
def test_sso_cache_not_found(self): with ArgvContext(program, '-t'), self.assertRaises(SystemExit) as x: cli.aws_sso_cache_path = "mock.sso.cache.json" cli.main() self.assertEqual(x.exception.code, 1)
def test_credential_not_found(self): with ArgvContext(program, '-t'), self.assertRaises(SystemExit) as x: cli.aws_shared_credentials_file = "mock.credentials" cli.main() self.assertEqual(x.exception.code, 1)
def test_config_not_found(self): with ArgvContext(program, '-t'), self.assertRaises(SystemExit) as x: cli.aws_config_file = "mock.config" cli.main() self.assertEqual(x.exception.code, 1)
def test_profile_not_found(self): with ArgvContext(program, '-p', uuid.uuid4().hex, '-t'): cli.main() self.assertEqual(len(cli.profiles), 0)
from yawsso.cli import main main()
import sys # pragma: no cover if sys.version_info >= (3, 6): # pragma: no cover from yawsso.cli import main # pragma: no cover main() # pragma: no cover else: python_version = ".".join(map(str, sys.version_info[:3])) # pragma: no cover print("This tool requires Python >=3.6. Found {}".format(python_version)) # pragma: no cover sys.exit(1) # pragma: no cover