示例#1
0
    def test_resolvealiases(self):

        parser = parse_args(['--resolve-aliases'])

        self.assertTrue(parser.saml_cache)
        self.assertFalse(parser.ask_role)
        self.assertFalse(parser.keyring)
        self.assertTrue(parser.resolve_aliases)
        self.assertEqual(parser.duration, None)
        self.assertEqual(parser.duration, None)
        self.assertEqual(parser.idp_id, None)
        self.assertEqual(parser.profile, None)
        self.assertEqual(parser.region, None)
        self.assertEqual(parser.role_arn, None)
        self.assertEqual(parser.username, None)
示例#2
0
    def test_username(self):

        parser = parse_args(['-u', '*****@*****.**'])

        self.assertTrue(parser.saml_cache)
        self.assertFalse(parser.ask_role)
        self.assertFalse(parser.keyring)
        self.assertFalse(parser.resolve_aliases)
        self.assertEqual(parser.duration, None)
        self.assertEqual(parser.duration, None)
        self.assertEqual(parser.idp_id, None)
        self.assertEqual(parser.profile, None)
        self.assertEqual(parser.region, None)
        self.assertEqual(parser.role_arn, None)
        self.assertEqual(parser.username, '*****@*****.**')
示例#3
0
    def test_nocache(self):

        parser = parse_args(['--no-cache'])

        self.assertFalse(parser.saml_cache)
        self.assertFalse(parser.ask_role)
        self.assertFalse(parser.keyring)
        self.assertFalse(parser.resolve_aliases)
        self.assertEqual(parser.duration, None)
        self.assertEqual(parser.auto_duration, False)
        self.assertEqual(parser.idp_id, None)
        self.assertEqual(parser.profile, None)
        self.assertEqual(parser.region, None)
        self.assertEqual(parser.role_arn, None)
        self.assertEqual(parser.username, None)
        self.assertEqual(parser.account, None)
示例#4
0
 def test_cli_param_supplied(self):
     args = parse_args(['--account', "123456789012"])
     config = resolve_config(args)
     self.assertEqual("123456789012", config.account)
示例#5
0
 def test_cli_param_supplied(self):
     args = parse_args(['--region', "ap-southeast-4"])
     config = resolve_config(args)
     self.assertEqual("ap-southeast-4", config.region)
    def test_process_auth_with_saml_cache(self, mock_google, mock_amazon, mock_util, mock_getpass):

        mock_config = Mock()
        mock_config.saml_cache = True
        mock_config.username = None
        mock_config.idp_id = None
        mock_config.sp_id = None
        mock_config.password = None
        mock_config.return_value = None
        mock_config.role_arn = 'arn:aws:iam::123456789012:role/admin'

        mock_amazon_client = Mock()
        mock_google_client = Mock()

        mock_getpass.return_value = "pass"

        mock_amazon_client.roles = {
            'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
            'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'
        }

        mock_util_obj = MagicMock()
        mock_util_obj.pick_a_role = MagicMock(return_value=("da_role", "da_provider"))
        mock_util_obj.get_input = MagicMock(side_effect=["input", "input2", "input3"])

        mock_util.Util = mock_util_obj

        mock_amazon_client.resolve_aws_aliases = MagicMock(return_value=[])

        mock_amazon.Amazon = MagicMock(return_value=mock_amazon_client)
        mock_google.Google = MagicMock(return_value=mock_google_client)

        args = aws_google_auth.parse_args([])

        # Method Under Test
        aws_google_auth.process_auth(args, mock_config)

        # Assert values collected
        self.assertEqual(mock_config.username, None)
        self.assertEqual(mock_config.idp_id, None)
        self.assertEqual(mock_config.sp_id, None)
        self.assertEqual(mock_config.password, None)
        self.assertEqual(mock_config.provider, "da_provider")
        self.assertEqual(mock_config.role_arn, "da_role")

        # Assert calls occur
        self.assertEqual([call.Util.pick_a_role({'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
                                                'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'}, [])],
                         mock_util.mock_calls)

        # Cache means no password request
        self.assertEqual([],
                         mock_getpass.mock_calls)

        # Cache means no google calls
        self.assertEqual([],
                         mock_google_client.mock_calls)

        self.assertEqual([call.write(mock_amazon_client)],
                         mock_config.mock_calls)

        self.assertEqual([call({'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
                                'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'
                                })],
                         mock_amazon_client.resolve_aws_aliases.mock_calls)

        self.assertEqual([call({'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
                                'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'}, [])
                          ], mock_util_obj.pick_a_role.mock_calls)
示例#7
0
 def test_default(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertEqual(None, config.idp_id)
示例#8
0
 def test_cli_param_supplied(self):
     args = parse_args(['-d', "500"])
     config = resolve_config(args)
     self.assertEqual(500, config.duration)
示例#9
0
 def test_cli_param_supplied(self):
     args = parse_args(['-D'])
     config = resolve_config(args)
     self.assertTrue(config.u2f_disabled)
示例#10
0
 def test_default(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertFalse(config.u2f_disabled)
示例#11
0
 def test_cli_param_supplied(self):
     args = parse_args(['-a'])
     config = resolve_config(args)
     self.assertTrue(config.ask_role)
示例#12
0
 def test_with_environment(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertEqual("4567-role", config.role_arn)
示例#13
0
 def test_cli_param_supplied(self):
     args = parse_args(['-r', "role1234"])
     config = resolve_config(args)
     self.assertEqual("role1234", config.role_arn)
示例#14
0
 def test_cli_param_supplied(self):
     args = parse_args(['-p', 'profile'])
     config = resolve_config(args)
     self.assertEqual('profile', config.profile)
示例#15
0
 def test_cli_param_supplied(self):
     args = parse_args(['-u', '*****@*****.**'])
     config = resolve_config(args)
     self.assertEqual('*****@*****.**', config.username)
示例#16
0
 def test_default(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertEqual(43200, config.duration)
示例#17
0
 def test_with_environment(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertTrue(config.u2f_disabled)
示例#18
0
    def test_invalid_cli_param_supplied(self):

        with self.assertRaises(SystemExit):
            args = parse_args(['-d', "blart"])
            resolve_config(args)
示例#19
0
 def test_cli_param_supplied(self):
     args = parse_args(['--resolve-aliases'])
     config = resolve_config(args)
     self.assertTrue(config.resolve_aliases)
示例#20
0
 def test_cli_param_supplied(self):
     args = parse_args(['-I', "kjl2342"])
     config = resolve_config(args)
     self.assertEqual("kjl2342", config.idp_id)
示例#21
0
 def test_with_environment(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertTrue(config.resolve_aliases)
示例#22
0
 def test_default(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertFalse(config.resolve_aliases)
示例#23
0
 def test_cli_param_supplied(self):
     args = parse_args(['--bg-response=foo'])
     config = resolve_config(args)
     self.assertEqual(config.bg_response, 'foo')
    def test_ask_and_supply_role(self):

        with self.assertRaises(SystemExit):
            parse_args(['-a', '-r', 'da-role'])
示例#25
0
 def test_with_environment(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertEqual(config.bg_response, 'foo')
    def test_process_auth_standard(self, mock_google, mock_amazon, mock_util, mock_getpass):

        mock_config = Mock()
        mock_config.profile = False
        mock_config.saml_cache = False
        mock_config.keyring = False
        mock_config.username = None
        mock_config.idp_id = None
        mock_config.sp_id = None
        mock_config.return_value = None

        mock_amazon_client = Mock()
        mock_google_client = Mock()

        mock_getpass.return_value = "pass"

        mock_amazon_client.roles = {
            'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
            'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'
        }

        mock_util_obj = MagicMock()
        mock_util_obj.pick_a_role = MagicMock(return_value=("da_role", "da_provider"))
        mock_util_obj.get_input = MagicMock(side_effect=["input", "input2", "input3"])

        mock_util.Util = mock_util_obj

        mock_amazon_client.resolve_aws_aliases = MagicMock(return_value=[])
        mock_amazon_client.print_export_line = Mock()

        mock_amazon.Amazon = MagicMock(return_value=mock_amazon_client)
        mock_google.Google = MagicMock(return_value=mock_google_client)

        args = aws_google_auth.parse_args([])

        # Method Under Test
        aws_google_auth.process_auth(args, mock_config)

        # Assert values collected
        self.assertEqual(mock_config.username, "input")
        self.assertEqual(mock_config.idp_id, "input2")
        self.assertEqual(mock_config.sp_id, "input3")
        self.assertEqual(mock_config.password, "pass")
        self.assertEqual(mock_config.provider, "da_provider")
        self.assertEqual(mock_config.role_arn, "da_role")

        # Assert calls occur
        self.assertEqual([call.Util.get_input('Google username: '******'Google IDP ID: '),
                          call.Util.get_input('Google SP ID: '),
                          call.Util.pick_a_role({'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
                                                'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'}, [])],
                         mock_util.mock_calls)

        self.assertEqual([call()],
                         mock_amazon_client.print_export_line.mock_calls)

        self.assertEqual([call('Google Password: '******'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
                                'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'
                                })],
                         mock_amazon_client.resolve_aws_aliases.mock_calls)

        self.assertEqual([call({'arn:aws:iam::123456789012:role/read-only': 'arn:aws:iam::123456789012:saml-provider/GoogleApps',
                                'arn:aws:iam::123456789012:role/admin': 'arn:aws:iam::123456789012:saml-provider/GoogleApps'}, [])
                          ], mock_util_obj.pick_a_role.mock_calls)
示例#27
0
 def test_default(self):
     args = parse_args([])
     config = resolve_config(args)
     self.assertEqual("sts", config.profile)