Esempio n. 1
0
    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)
        ])
Esempio n. 2
0
    def test_write_config(self, isfile_mock):
        isfile_mock.return_value = True

        config = Config(['aws_okta_keyman.py'])
        config.writepath = './.config/aws_okta_keyman.yml'
        config.username = '******'
        yaml = ("username: [email protected]\n"
                "org: example\n"
                "appid: app/id\n"
                "accounts:\n"
                "  - name: Dev\n"
                "    appid: A123/123\n")

        m = mock.mock_open(read_data=yaml)
        with mock.patch('aws_okta_keyman.config.open', m):
            config.write_config()

        m.assert_has_calls([
            mock.call('./.config/aws_okta_keyman.yml', 'r'),
        ])
        m.assert_has_calls([
            mock.call(u'./.config/aws_okta_keyman.yml', 'w'),
        ])
        m.assert_has_calls([
            mock.call().write('accounts'),
            mock.call().write(':'),
            mock.call().write('\n'),
            mock.call().write('-'),
            mock.call().write(' '),
            mock.call().write('appid'),
            mock.call().write(':'),
            mock.call().write(' '),
            mock.call().write('A123/123'),
            mock.call().write('\n'),
            mock.call().write('  '),
            mock.call().write('name'),
            mock.call().write(':'),
            mock.call().write(' '),
            mock.call().write('Dev'),
            mock.call().write('\n'),
            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)
        ])
Esempio n. 3
0
    def test_write_config_path_create_when_missing(self, os_mock):
        config = Config(['aws_okta_keyman.py'])
        config.clean_config_for_write = mock.MagicMock()
        config.clean_config_for_write.return_value = {}
        config.read_yaml = mock.MagicMock()
        config.read_yaml.return_value = {}
        folderpath = '/home/user/.config/'
        os_mock.path.dirname.return_value = folderpath
        os_mock.path.exists.return_value = False

        m = mock.mock_open()
        with mock.patch('aws_okta_keyman.config.open', m):
            config.write_config()

        os_mock.assert_has_calls([mock.call.makedirs(folderpath)])
Esempio n. 4
0
    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')])
Esempio n. 5
0
    def test_interactive_config_auto_account(self, input_mock, _getpass_mock):
        input_mock.side_effect = ['org', 'user', '']
        config = Config(['aws_okta_keyman.py'])
        config.write_config = mock.MagicMock()

        config.interactive_config()

        self.assertEqual(config.accounts, None)
Esempio n. 6
0
    def test_interactive_config_keyboardexit(self, input_mock, getpass_mock):
        input_mock.side_effect = ['org', 'user', KeyboardInterrupt]
        getpass_mock.return_value = 'fakeuser'
        config = Config(['aws_okta_keyman.py'])
        config.write_config = mock.MagicMock()

        ret = config.interactive_config()
        self.assertEqual(ret, None)
        assert not config.write_config.called
Esempio n. 7
0
    def test_interactive_config_auto_user(self, input_mock, getpass_mock):
        input_mock.side_effect = ['org', '', 'appid', 'test', '']
        getpass_mock.return_value = 'fakeuser'
        config = Config(['aws_okta_keyman.py'])
        config.write_config = mock.MagicMock()

        config.interactive_config()

        self.assertEqual(config.username, 'automatic-username')
Esempio n. 8
0
    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')])
Esempio n. 9
0
    def test_interactive_config_auto_user(self, input_mock, getpass_mock):
        input_mock.side_effect = ["org", "", "appid", "test", ""]
        getpass_mock.return_value = "fakeuser"
        config = Config(["aws_okta_keyman.py"])
        config.write_config = mock.MagicMock()

        config.interactive_config()

        self.assertEqual(config.username, "automatic-username")
Esempio n. 10
0
    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")])
Esempio n. 11
0
    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),
            ],
        )
Esempio n. 12
0
    def test_interactive_config(self, input_mock, getpass_mock):
        input_mock.side_effect = ['org', 'user', 'appid', 'test', '']
        getpass_mock.return_value = 'fakeuser'
        config = Config(['aws_okta_keyman.py'])
        config.write_config = mock.MagicMock()

        config.interactive_config()

        self.assertEqual(config.org, 'org')
        self.assertEqual(config.username, 'user')
        self.assertEqual(config.accounts, [{'name': 'test', 'appid': 'appid'}])
        config.write_config.assert_has_calls([mock.call()])
Esempio n. 13
0
    def test_interactive_config(self, input_mock, getpass_mock):
        input_mock.side_effect = ["org", "user", "appid", "test", ""]
        getpass_mock.return_value = "fakeuser"
        config = Config(["aws_okta_keyman.py"])
        config.write_config = mock.MagicMock()

        config.interactive_config()

        self.assertEqual(config.org, "org")
        self.assertEqual(config.username, "user")
        self.assertEqual(config.accounts, [{"name": "test", "appid": "appid"}])
        config.write_config.assert_has_calls([mock.call()])
Esempio n. 14
0
    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)
        ])
Esempio n. 15
0
    def test_write_config(self):
        config = Config(['aws_okta_keyman.py'])
        config.clean_config_for_write = mock.MagicMock()
        config_clean = {
            'accounts': [{
                'name': 'Dev',
                'appid': 'A123/123'
            }],
            'org': 'example',
            'reup': None,
            'username': '******',
        }
        config.clean_config_for_write.return_value = config_clean
        config.writepath = './.config/aws_okta_keyman.yml'
        config.username = '******'
        config.read_yaml = mock.MagicMock()
        config.read_yaml.return_value = {
            'username': '******',
            'org': 'example',
            'appid': 'app/id',
        }

        m = mock.mock_open()
        with mock.patch('aws_okta_keyman.config.open', m):
            config.write_config()

        m.assert_has_calls([
            mock.call(u'./.config/aws_okta_keyman.yml', 'w'),
        ])
        m.assert_has_calls([
            mock.call().write('accounts'),
            mock.call().write(':'),
            mock.call().write('\n'),
            mock.call().write('-'),
            mock.call().write(' '),
            mock.call().write('appid'),
            mock.call().write(':'),
            mock.call().write(' '),
            mock.call().write('A123/123'),
            mock.call().write('\n'),
            mock.call().write('  '),
            mock.call().write('name'),
            mock.call().write(':'),
            mock.call().write(' '),
            mock.call().write('Dev'),
            mock.call().write('\n'),
            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)
        ])
Esempio n. 16
0
    def test_write_config(self):
        config = Config(["aws_okta_keyman.py"])
        config.clean_config_for_write = mock.MagicMock()
        config_clean = {
            "accounts": [{"name": "Dev", "appid": "A123/123"}],
            "org": "example",
            "reup": None,
            "username": "******",
        }
        config.clean_config_for_write.return_value = config_clean
        config.writepath = "./.config/aws_okta_keyman.yml"
        config.username = "******"
        config.read_yaml = mock.MagicMock()
        config.read_yaml.return_value = {
            "username": "******",
            "org": "example",
            "appid": "app/id",
        }

        m = mock.mock_open()
        with mock.patch("aws_okta_keyman.config.open", m):
            config.write_config()

        m.assert_has_calls(
            [
                mock.call("./.config/aws_okta_keyman.yml", "w"),
            ],
        )
        m.assert_has_calls(
            [
                mock.call().write("accounts"),
                mock.call().write(":"),
                mock.call().write("\n"),
                mock.call().write("-"),
                mock.call().write(" "),
                mock.call().write("appid"),
                mock.call().write(":"),
                mock.call().write(" "),
                mock.call().write("A123/123"),
                mock.call().write("\n"),
                mock.call().write("  "),
                mock.call().write("name"),
                mock.call().write(":"),
                mock.call().write(" "),
                mock.call().write("Dev"),
                mock.call().write("\n"),
                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),
            ],
        )