Example #1
0
    def test_handle_appid_selection(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar'])
        keyman.config.accounts = [{
            'name': 'myAccount',
            'appid': 'myID'
        }, {
            'name': 'myAccount',
            'appid': 'myID'
        }]
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name='selector_menu')
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()

        keyman.handle_appid_selection()

        keyman.selector_menu.assert_has_calls([
            mock.call([{
                'name': 'myAccount',
                'appid': 'myID'
            }, {
                'name': 'myAccount',
                'appid': 'myID'
            }], [{
                'name': 'Account'
            }])
        ])
        keyman.config.set_appid_from_account_id.assert_has_calls(
            [mock.call(0)])
Example #2
0
    def test_handle_appid_selection(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar"])
        keyman.config.accounts = [
            {"name": "myAccount", "appid": "myID"},
            {"name": "myAccount", "appid": "myID"},
        ]
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name="selector_menu")
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()

        keyman.handle_appid_selection()

        keyman.selector_menu.assert_has_calls(
            [
                mock.call(
                    [
                        {"name": "myAccount", "appid": "myID"},
                        {"name": "myAccount", "appid": "myID"},
                    ],
                    [{"name": "Account"}],
                ),
            ],
        )
        keyman.config.set_appid_from_account_id.assert_has_calls(
            [
                mock.call(0),
            ],
        )
Example #3
0
    def test_handle_appid_selection_one_account(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar'])
        keyman.config.accounts = [{'name': 'myAccount', 'appid': 'myID'}]
        keyman.config.appid = None
        keyman.config.set_appid_from_account_id = mock.MagicMock()
        keyman.handle_appid_selection()

        keyman.config.set_appid_from_account_id.assert_has_calls(
            [mock.call(0)])
Example #4
0
    def test_handle_appid_selection_one_account(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar"])
        keyman.config.accounts = [{"name": "myAccount", "appid": "myID"}]
        keyman.config.appid = None
        keyman.config.set_appid_from_account_id = mock.MagicMock()
        keyman.handle_appid_selection()

        keyman.config.set_appid_from_account_id.assert_has_calls(
            [
                mock.call(0),
            ],
        )
Example #5
0
    def test_handle_appid_selection_from_okta_no_aws(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar"])
        keyman.config.accounts = None
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name="selector_menu")
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()
        keyman.okta_client = mock.MagicMock()
        keyman.okta_client.get_aws_apps.return_value = []

        with self.assertRaises(NoAWSAccounts):
            keyman.handle_appid_selection(okta_ready=True)
Example #6
0
    def test_handle_appid_selection_from_okta(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar"])
        keyman.config.accounts = None
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name="selector_menu")
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()
        keyman.okta_client = mock.MagicMock()
        keyman.okta_client.get_aws_apps.return_value = [
            {"name": "myAccount", "appid": "myID"},
        ]

        keyman.handle_appid_selection(okta_ready=True)

        assert keyman.okta_client.get_aws_apps.called
Example #7
0
    def test_handle_appid_selection_from_okta(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar'])
        keyman.config.accounts = None
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name='selector_menu')
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()
        keyman.okta_client = mock.MagicMock()
        keyman.okta_client.get_aws_apps.return_value = [
            {'name': 'myAccount', 'appid': 'myID'}
        ]

        keyman.handle_appid_selection(okta_ready=True)

        assert keyman.okta_client.get_aws_apps.called
Example #8
0
    def test_main_post_okta_appid_selection(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar'])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.config.appid = None
        keyman.user_password = mock.MagicMock()
        keyman.user_password.return_value = 'foo'
        keyman.init_okta = mock.MagicMock()
        keyman.auth_okta = mock.MagicMock()
        keyman.aws_auth_loop = mock.MagicMock()
        keyman.aws_auth_loop.return_value = None
        keyman.handle_appid_selection = mock.MagicMock()

        keyman.main()

        keyman.handle_appid_selection.assert_has_calls(
            [mock.call(), mock.call(okta_ready=True)])
Example #9
0
    def test_main_keyboard_interrupt(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.side_effect = KeyboardInterrupt

        with self.assertRaises(SystemExit):
            keyman.main()
Example #10
0
    def test_main_unhandled_exception(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz'])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.side_effect = Exception()

        with self.assertRaises(SystemExit):
            keyman.main()
Example #11
0
    def test_main_keyboard_interrupt(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz'])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.side_effect = KeyboardInterrupt

        with self.assertRaises(SystemExit):
            keyman.main()
Example #12
0
    def test_main_unhandled_exception(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.side_effect = Exception()

        with self.assertRaises(SystemExit):
            keyman.main()
Example #13
0
    def test_handle_appid_selection_no_appid(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar"])
        keyman.config.accounts = None
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name="selector_menu")
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()

        ret = keyman.handle_appid_selection()

        self.assertEqual(ret, None)
Example #14
0
    def test_handle_appid_selection_no_appid(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar'])
        keyman.config.accounts = None
        keyman.config.appid = None
        keyman.selector_menu = mock.MagicMock(name='selector_menu')
        keyman.selector_menu.return_value = 0
        keyman.config.set_appid_from_account_id = mock.MagicMock()

        ret = keyman.handle_appid_selection()

        self.assertEqual(ret, None)
Example #15
0
    def test_main_no_aws_accounts(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz'])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.return_value = 'foo'
        keyman.init_okta = mock.MagicMock()
        keyman.auth_okta = mock.MagicMock()
        keyman.aws_auth_loop = mock.MagicMock()
        keyman.aws_auth_loop.return_value = 1

        with self.assertRaises(SystemExit):
            keyman.main()
Example #16
0
    def test_main_aws_auth_error(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.handle_appid_selection.side_effect = NoAWSAccounts()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.return_value = "foo"
        keyman.init_okta = mock.MagicMock()
        keyman.auth_okta = mock.MagicMock()
        keyman.aws_auth_loop = mock.MagicMock()

        with self.assertRaises(SystemExit):
            keyman.main()
Example #17
0
    def test_main_update(self, config_mock):
        config_mock().update = True
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"])
        keyman.update = mock.MagicMock()
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.return_value = "foo"
        keyman.init_okta = mock.MagicMock()
        keyman.auth_okta = mock.MagicMock()
        keyman.aws_auth_loop = mock.MagicMock()

        with self.assertRaises(SystemExit):
            keyman.main()

        keyman.update.assert_has_calls([mock.call(__version__)])
Example #18
0
    def test_main(self, _config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz'])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.return_value = 'foo'
        keyman.init_okta = mock.MagicMock()
        keyman.auth_okta = mock.MagicMock()
        keyman.aws_auth_loop = mock.MagicMock()

        keyman.main()

        assert keyman.handle_appid_selection.called
        assert keyman.user_password.called
        keyman.init_okta.assert_called_with('foo')
        assert keyman.auth_okta.called
        assert keyman.aws_auth_loop.called
Example #19
0
    def test_main(self, _config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"])
        keyman.handle_appid_selection = mock.MagicMock()
        keyman.user_password = mock.MagicMock()
        keyman.user_password.return_value = "foo"
        keyman.init_okta = mock.MagicMock()
        keyman.auth_okta = mock.MagicMock()
        keyman.aws_auth_loop = mock.MagicMock()
        keyman.aws_auth_loop.return_value = None

        keyman.main()

        assert keyman.handle_appid_selection.called
        assert keyman.user_password.called
        keyman.init_okta.assert_called_with("foo")
        assert keyman.auth_okta.called
        assert keyman.aws_auth_loop.called
Example #20
0
    def test_handle_appid_selection_when_appid_provided(self, config_mock):
        keyman = Keyman(['foo', '-o', 'foo', '-u', 'bar', '-a', 'baz'])
        config_mock().appid = 'someid'

        self.assertEqual(keyman.handle_appid_selection(), None)
Example #21
0
    def test_handle_appid_selection_when_appid_provided(self, config_mock):
        keyman = Keyman(["foo", "-o", "foo", "-u", "bar", "-a", "baz"])
        config_mock().appid = "someid"

        self.assertEqual(keyman.handle_appid_selection(), None)