def test_validate_short_duration(self): config = Config(["aws_okta_keyman.py"]) config.org = "example" config.duration = 1 with self.assertRaises(ValueError): config.validate()
def test_full_app_url(self): config = Config(["aws_okta_keyman.py"]) config.org = "example" config.appid = "some/thing" ret = config.full_app_url() self.assertEqual(ret, "https://example.okta.com/some/thing")
def test_validate_long_duration(self): config = Config(['aws_okta_keyman.py']) config.org = 'example' config.duration = 100000000 with self.assertRaises(ValueError): config.validate()
def test_full_app_url(self): config = Config(['aws_okta_keyman.py']) config.org = 'example' config.appid = 'some/thing' ret = config.full_app_url() self.assertEqual(ret, 'https://example.okta.com/some/thing')
def test_write_config_new_file(self, isfile_mock): isfile_mock.return_value = False config = Config(['aws_okta_keyman.py']) config.writepath = './.config/aws_okta_keyman.yml' config.username = '******' config.appid = 'app/id' config.org = 'example' m = mock.mock_open() with mock.patch('aws_okta_keyman.config.open', m): config.write_config() m.assert_has_calls([ mock.call().write('org'), mock.call().write(':'), mock.call().write(' '), mock.call().write('example'), mock.call().write('\n'), mock.call().write('reup'), mock.call().write(':'), mock.call().write(' '), mock.call().write('null'), mock.call().write('\n'), mock.call().write('username'), mock.call().write(':'), mock.call().write(' '), mock.call().write('*****@*****.**'), mock.call().write('\n'), mock.call().flush(), mock.call().flush(), mock.call().__exit__(None, None, None) ])
def test_validate_automatic_username_from_none(self, getpass_mock): getpass_mock.getuser.return_value = 'user' config = Config(['aws_okta_keyman.py']) config.accounts = [{'appid': 'A123'}] config.org = 'example' config.validate() self.assertEqual(config.username, 'user')
def test_validate_automatic_username_from_full_config(self, getpass_mock): getpass_mock.getuser.return_value = "user" config = Config(["aws_okta_keyman.py"]) config.accounts = [{"appid": "A123"}] config.org = "example" config.username = "******" config.validate() self.assertEqual(config.username, "*****@*****.**")
def test_write_config_path_expansion(self, isfile_mock): isfile_mock.return_value = False config = Config(['aws_okta_keyman.py']) config.writepath = '~/.config/aws_okta_keyman.yml' config.username = '******' config.appid = 'app/id' config.org = 'example' expected_path = os.path.expanduser(config.writepath) m = mock.mock_open() with mock.patch('aws_okta_keyman.config.open', m): config.write_config() m.assert_has_calls([mock.call(expected_path, 'w')])
def test_parse_config_args_preferred(self): config = Config(["aws_okta_keyman.py"]) config.appid = "mysupercoolapp/id" config.org = "foobar" config.username = "******" config.read_yaml = mock.MagicMock() config.read_yaml.return_value = { "username": "******", "org": "example", "appid": "app/id", } config.parse_config("./.config/aws_okta_keyman.yml") # Make sure we're getting the args not the config values self.assertEqual(config.appid, "mysupercoolapp/id") self.assertEqual(config.org, "foobar") self.assertEqual(config.username, "test")
def test_write_config_path_expansion(self): config = Config(["aws_okta_keyman.py"]) config.clean_config_for_write = mock.MagicMock() config.clean_config_for_write.return_value = {} config.writepath = "~/.config/aws_okta_keyman.yml" config.username = "******" config.appid = "app/id" config.org = "example" config.read_yaml = mock.MagicMock() config.read_yaml.return_value = {} expected_path = os.path.expanduser(config.writepath) m = mock.mock_open() with mock.patch("aws_okta_keyman.config.open", m): config.write_config() m.assert_has_calls([mock.call(expected_path, "w")])
def test_write_config_path_expansion(self): config = Config(['aws_okta_keyman.py']) config.clean_config_for_write = mock.MagicMock() config.clean_config_for_write.return_value = {} config.writepath = '~/.config/aws_okta_keyman.yml' config.username = '******' config.appid = 'app/id' config.org = 'example' config.read_yaml = mock.MagicMock() config.read_yaml.return_value = {} expected_path = os.path.expanduser(config.writepath) m = mock.mock_open() with mock.patch('aws_okta_keyman.config.open', m): config.write_config() m.assert_has_calls([mock.call(expected_path, 'w')])
def test_parse_config_args_preferred(self): config = Config(['aws_okta_keyman.py']) config.appid = 'mysupercoolapp/id' config.org = 'foobar' config.username = '******' config.read_yaml = mock.MagicMock() config.read_yaml.return_value = { 'username': '******', 'org': 'example', 'appid': 'app/id', } config.parse_config('./.config/aws_okta_keyman.yml') # Make sure we're getting the args not the config values self.assertEqual(config.appid, 'mysupercoolapp/id') self.assertEqual(config.org, 'foobar') self.assertEqual(config.username, 'test')
def test_parse_config_args_preferred(self, isfile_mock): isfile_mock.return_value = True config = Config(['aws_okta_keyman.py']) config.appid = 'mysupercoolapp/id' config.org = 'foobar' config.username = '******' yaml = ("username: [email protected]\n" "org: example\n" "appid: app/id\n") m = mock.mock_open(read_data=yaml) with mock.patch('aws_okta_keyman.config.open', m): config.parse_config('./.config/aws_okta_keyman.yml') # Make sure we're getting the args not the config values self.assertEquals(config.appid, 'mysupercoolapp/id') self.assertEquals(config.org, 'foobar') self.assertEquals(config.username, 'test')
def test_write_config_new_file(self): config = Config(["aws_okta_keyman.py"]) config.clean_config_for_write = mock.MagicMock() config_clean = { "org": "example", "reup": None, "username": "******", } config.clean_config_for_write.return_value = config_clean config.writepath = "./.config/aws_okta_keyman.yml" config.username = "******" config.appid = "app/id" config.org = "example" config.read_yaml = mock.MagicMock() config.read_yaml.return_value = {} m = mock.mock_open() with mock.patch("aws_okta_keyman.config.open", m): config.write_config() m.assert_has_calls( [ mock.call().write("org"), mock.call().write(":"), mock.call().write(" "), mock.call().write("example"), mock.call().write("\n"), mock.call().write("reup"), mock.call().write(":"), mock.call().write(" "), mock.call().write("null"), mock.call().write("\n"), mock.call().write("username"), mock.call().write(":"), mock.call().write(" "), mock.call().write("*****@*****.**"), mock.call().write("\n"), mock.call().flush(), mock.call().flush(), mock.call().__exit__(None, None, None), ], )
def test_write_config_new_file(self): config = Config(['aws_okta_keyman.py']) config.clean_config_for_write = mock.MagicMock() config_clean = { 'org': 'example', 'reup': None, 'username': '******', } config.clean_config_for_write.return_value = config_clean config.writepath = './.config/aws_okta_keyman.yml' config.username = '******' config.appid = 'app/id' config.org = 'example' config.read_yaml = mock.MagicMock() config.read_yaml.return_value = {} m = mock.mock_open() with mock.patch('aws_okta_keyman.config.open', m): config.write_config() m.assert_has_calls([ mock.call().write('org'), mock.call().write(':'), mock.call().write(' '), mock.call().write('example'), mock.call().write('\n'), mock.call().write('reup'), mock.call().write(':'), mock.call().write(' '), mock.call().write('null'), mock.call().write('\n'), mock.call().write('username'), mock.call().write(':'), mock.call().write(' '), mock.call().write('*****@*****.**'), mock.call().write('\n'), mock.call().flush(), mock.call().flush(), mock.call().__exit__(None, None, None) ])
def test_validate_good_with_appid(self): config = Config(['aws_okta_keyman.py']) config.appid = 'A123' config.org = 'example' config.username = '******' self.assertEqual(config.validate(), None)
def test_validate_good_with_accounts(self): config = Config(['aws_okta_keyman.py']) config.accounts = [{'appid': 'A123'}] config.org = 'example' config.username = '******' self.assertEquals(config.validate(), None)
def test_validate_missing_username(self): config = Config(['aws_okta_keyman.py']) config.accounts = [{'appid': 'A123'}] config.org = 'example' with self.assertRaises(ValueError): config.validate()
def test_validate_missing_appid_and_accounts(self): config = Config(['aws_okta_keyman.py']) config.username = '******' config.org = 'example' with self.assertRaises(ValueError): config.validate()
def test_validate_good_with_appid(self): config = Config(["aws_okta_keyman.py"]) config.appid = "A123" config.org = "example" config.username = "******" self.assertEqual(config.validate(), None)
def test_validate_automatic_username_from_none(self, getpass_mock): getpass_mock.getuser.return_value = "user" config = Config(["aws_okta_keyman.py"]) config.org = "example" config.validate() self.assertEqual(config.username, "user")