def test_read_yaml_file_missing_with_raise(self, isfile_mock):
     isfile_mock.return_value = False
     with self.assertRaises(IOError):
         Config.read_yaml(
             "./.config/aws_okta_keyman.yml",
             raise_on_error=True,
         )
    def test_read_yaml_scan_error_with_raise(self, isfile_mock):
        isfile_mock.return_value = True
        yml = ("username: [email protected]\n"
               "org: example\n"
               "appid app/id\n")

        m = mock.mock_open(read_data=yml)
        with mock.patch('aws_okta_keyman.config.open', m):
            with self.assertRaises(yaml.scanner.ScannerError):
                Config.read_yaml('./.config/aws_okta_keyman.yml',
                                 raise_on_error=True)
    def test_read_yaml_parse_error_with_raise(self, isfile_mock):
        isfile_mock.return_value = True
        yml = "username: [email protected]\n" "org: example\n" "- appid: foo\n"

        m = mock.mock_open(read_data=yml)
        with mock.patch("aws_okta_keyman.config.open", m):
            with self.assertRaises(yaml.parser.ParserError):
                Config.read_yaml(
                    "./.config/aws_okta_keyman.yml",
                    raise_on_error=True,
                )
    def test_read_yaml_scan_error_no_raise(self, isfile_mock):
        isfile_mock.return_value = True
        yml = "username: [email protected]\n" "org: example\n" "appid app/id\n"

        m = mock.mock_open(read_data=yml)
        with mock.patch("aws_okta_keyman.config.open", m):
            ret = Config.read_yaml("./.config/aws_okta_keyman.yml")

        self.assertEqual(ret, {})
    def test_read_yaml_parse_error_no_raise(self, isfile_mock):
        isfile_mock.return_value = True
        yml = ("username: [email protected]\n"
               "org: example\n"
               "- appid: foo\n")

        m = mock.mock_open(read_data=yml)
        with mock.patch('aws_okta_keyman.config.open', m):
            ret = Config.read_yaml('./.config/aws_okta_keyman.yml')

        self.assertEqual(ret, {})
    def test_parse_config(self):
        config = Config(['aws_okta_keyman.py'])
        config.read_yaml = mock.MagicMock()
        config.read_yaml.return_value = {
            'username': '******',
            'org': 'example',
            'appid': 'app/id',
        }

        config.parse_config('./.config/aws_okta_keyman.yml')

        self.assertEqual(config.appid, 'app/id')
        self.assertEqual(config.org, 'example')
        self.assertEqual(config.username, '*****@*****.**')
    def test_parse_config(self):
        config = Config(["aws_okta_keyman.py"])
        config.read_yaml = mock.MagicMock()
        config.read_yaml.return_value = {
            "username": "******",
            "org": "example",
            "appid": "app/id",
        }

        config.parse_config("./.config/aws_okta_keyman.yml")

        self.assertEqual(config.appid, "app/id")
        self.assertEqual(config.org, "example")
        self.assertEqual(config.username, "*****@*****.**")
    def test_read_yaml(self, isfile_mock):
        isfile_mock.return_value = True
        yml = "username: [email protected]\n" "org: example\n" "appid: app/id\n"

        m = mock.mock_open(read_data=yml)
        with mock.patch("aws_okta_keyman.config.open", m):
            ret = Config.read_yaml("./.config/aws_okta_keyman.yml")

        expected = {
            "username": "******",
            "org": "example",
            "appid": "app/id",
        }
        self.assertEqual(ret, expected)
    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)])
    def test_read_yaml(self, isfile_mock):
        isfile_mock.return_value = True
        yml = ("username: [email protected]\n"
               "org: example\n"
               "appid: app/id\n")

        m = mock.mock_open(read_data=yml)
        with mock.patch('aws_okta_keyman.config.open', m):
            ret = Config.read_yaml('./.config/aws_okta_keyman.yml')

        expected = {
            'username': '******',
            'org': 'example',
            'appid': 'app/id'
        }
        self.assertEqual(ret, expected)
    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')
Beispiel #13
0
    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")
Beispiel #14
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")])
Beispiel #15
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),
            ],
        )
    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(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)
        ])
Beispiel #18
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),
            ],
        )
 def test_read_yaml_file_missing_no_raise(self, isfile_mock):
     isfile_mock.return_value = False
     ret = Config.read_yaml('./.config/aws_okta_keyman.yml')
     self.assertEqual(ret, {})