Exemplo n.º 1
0
    def test_get_auth(self):
        auth_lines = [
            """id = a1; type = InfrastructureManager; username = someuser; password = somepass """,
            """id = ''; type = VMRC; username = someuser; password = somepass; """
        ]
        auth = Authentication(Authentication.read_auth_data(auth_lines))
        auth_data = auth.getAuthInfoByID("a1")
        self.assertEqual(auth_data, [{
            'id': 'a1',
            'password': "******",
            'type': 'InfrastructureManager',
            'username': '******'
        }])
        auth_data = auth.getAuthInfo("VMRC")
        self.assertEqual(auth_data, [{
            'id': '',
            'password': "******",
            'type': 'VMRC',
            'username': '******'
        }])

        auth_lines = [
            """id = 1a; type = InfrastructureManager; username = someuser; password = somepass """
        ]
        with self.assertRaises(Exception) as ex:
            auth = Authentication(Authentication.read_auth_data(auth_lines))
        self.assertEqual("Incorrect value in auth item id: 1a",
                         str(ex.exception))
Exemplo n.º 2
0
Arquivo: auth.py Projeto: vigial/im
 def test_get_auth(self):
     auth_lines = [
         """id = 1; type = InfrastructureManager; username = someuser; password = somepass """,
         """id = 2; type = VMRC; username = someuser; password = somepass; """
     ]
     auth = Authentication(Authentication.read_auth_data(auth_lines))
     auth_data = auth.getAuthInfoByID("1")
     self.assertEqual(auth_data, [{
         'id': '1',
         'password': "******",
         'type': 'InfrastructureManager',
         'username': '******'
     }])
     auth_data = auth.getAuthInfo("VMRC")
     self.assertEqual(auth_data, [{
         'id': '2',
         'password': "******",
         'type': 'VMRC',
         'username': '******'
     }])
Exemplo n.º 3
0
    def test_auth_read(self):
        auth_lines = [
            """id = a1; type = InfrastructureManager; username = someuser; password = somepass """,
            """id = a2; type = VMRC; username = someuser; password = somepass; """,
            """id = a3; type = OpenNebula; username = someuser; password = "******" """,
            """id = a4; type = EC2; username = someuser; password = '******' """
        ]
        auth = Authentication.read_auth_data(auth_lines)
        self.assertEqual(auth, [{
            'id': 'a1',
            'password': "******",
            'type': 'InfrastructureManager',
            'username': '******'
        }, {
            'id': 'a2',
            'password': "******",
            'type': 'VMRC',
            'username': '******'
        }, {
            'id': 'a3',
            'password': "******",
            'type': 'OpenNebula',
            'username': '******'
        }, {
            'id': 'a4',
            'password': '******',
            'type': 'EC2',
            'username': '******'
        }])

        tests_path = os.path.dirname(os.path.abspath(__file__))
        shutil.copyfile(os.path.join(tests_path, "../files/privatekey.pem"),
                        "/tmp/privatekey.pem")
        auth = Authentication(
            Authentication.read_auth_data(
                os.path.join(tests_path, "../files/auth.dat")))
        auth_data = auth.getAuthInfoByID("occi")
        self.assertEqual(auth_data[0]['proxy'][:37],
                         "-----BEGIN RSA PRIVATE KEY-----\nMIIEo")
        os.unlink("/tmp/privatekey.pem")