Esempio n. 1
0
    def test_make_token(self):
        remote_client = self.remote_document_client_1
        token = remote_client.request_token()
        if token is None:
            raise SkipTest('nuxeo-platform-login-token is not deployed')
        self.assertGreater(len(token), 5)
        self.assertEqual(remote_client.auth[0], 'X-Authentication-Token')
        self.assertEqual(remote_client.auth[1], token)

        remote_client.unregister_as_root(self.workspace)
        self.wait()

        # Requesting token is an idempotent operation
        token2 = remote_client.request_token()
        self.assertEqual(token, token2)

        # It's possible to create a new client using the same token
        remote_client2 = RemoteDocumentClient(
            remote_client.server_url, remote_client.user_id,
            remote_client.device_id, remote_client.client_version,
            token=token, base_folder=self.workspace)

        token3 = remote_client.request_token()
        self.assertEqual(token, token3)

        # Register a root with client 2 and see it with client one
        folder_1 = remote_client2.make_folder('/', 'Folder 1')
        remote_client2.register_as_root(folder_1)

        roots = remote_client.get_roots()
        self.assertEqual(len(roots), 1)
        self.assertEqual(roots[0].name, 'Folder 1')

        # The root can also been seen with a new client connected using
        # password based auth
        remote_client3 = RemoteDocumentClient(
            remote_client.server_url, remote_client.user_id,
            remote_client.device_id, remote_client.client_version,
            password=self.password_1, base_folder=None)
        roots = remote_client3.get_roots()
        self.assertEqual(len(roots), 1)
        self.assertEqual(roots[0].name, 'Folder 1')

        # Another device using the same user credentials will get a different
        # token
        remote_client4 = RemoteDocumentClient(
            remote_client.server_url, remote_client.user_id,
            'other-test-device', remote_client.client_version,
            password=self.password_1, base_folder=None)
        token4 = remote_client4.request_token()
        self.assertNotEquals(token, token4)

        # A client can revoke a token explicitly and thus lose credentials
        remote_client4.revoke_token()
        with self.assertRaises(IOError):
            remote_client4.get_roots()
Esempio n. 2
0
    def test_migration_db_v1(self):
        # Initialize old DB
        db = open(self._get_db('test_manager_migration.db'), 'rb')
        old_db = os.path.join(self.test_folder, 'nxdrive.db')
        with open(old_db, 'wb') as f:
            f.write(db.read())
        db.close()

        # Update token with one acquired against the test server
        conn = sqlite3.connect(old_db)
        c = conn.cursor()
        device_id = c.execute("SELECT device_id FROM device_config LIMIT 1").fetchone()[0]
        remote_client = RemoteDocumentClient(self.nuxeo_url, self.admin_user, device_id, nxdrive.__version__,
                                             password=self.admin_password)
        token = remote_client.request_token()
        c.execute("UPDATE server_bindings SET remote_token='%s' WHERE local_folder='%s'" % (
            token, '/home/ataillefer/Nuxeo Drive'))

        # Update server URL with test server URL
        c.execute("UPDATE server_bindings SET server_url='%s' WHERE local_folder='%s'" % (
            self.nuxeo_url, '/home/ataillefer/Nuxeo Drive'))

        # Update local folder with test temp dir
        local_folder = os.path.join(self.test_folder, 'Nuxeo Drive')
        c.execute("UPDATE server_bindings SET local_folder='%s' WHERE local_folder='%s'" % (
            local_folder, '/home/ataillefer/Nuxeo Drive'))
        conn.commit()
        conn.close()

        # Create Manager with old DB migration
        manager = self._create_manager()
        dao = manager.get_dao()

        # Check Manager config
        self.assertEquals(dao.get_config('device_id'), device_id)
        self.assertEquals(dao.get_config('proxy_config'), 'Manual')
        self.assertEquals(dao.get_config('proxy_type'), 'http')
        self.assertEquals(dao.get_config('proxy_server'), 'proxy.server.com')
        self.assertEquals(dao.get_config('proxy_port'), '80')
        self.assertEquals(dao.get_config('proxy_authenticated'), '1')
        self.assertEquals(dao.get_config('proxy_username'), 'Administrator')
        self.assertEquals(dao.get_config('auto_update'), '1')
        self.assertEquals(dao.get_config('proxy_config'), 'Manual')

        # Check engine definition
        engines = dao.get_engines()
        self.assertEquals(len(engines), 1)
        engine = engines[0]
        self.assertEquals(engine.engine, 'NXDRIVE')
        self.assertEquals(engine.name, manager._get_engine_name(self.nuxeo_url))
        self.assertTrue(local_folder in engine.local_folder)

        # Check engine config
        engine_uid = engine.uid
        engine_db = os.path.join(self.test_folder, 'ndrive_%s.db' % engine_uid)
        engine_dao = EngineDAO(engine_db)
        self.assertEquals(engine_dao.get_config('server_url'), self.nuxeo_url)
        self.assertEquals(engine_dao.get_config('remote_user'), 'Administrator')
        self.assertEquals(engine_dao.get_config('remote_token'), token)

        engine_dao.dispose()
        manager.dispose_all()
Esempio n. 3
0
    def test_migration_db_v1(self):
        # Initialize old DB
        db = open(self._get_db('test_manager_migration.db'), 'rb')
        old_db = os.path.join(self.test_folder, 'nxdrive.db')
        with open(old_db, 'wb') as f:
            f.write(db.read())
        db.close()

        # Update token with one acquired against the test server
        conn = sqlite3.connect(old_db)
        c = conn.cursor()
        device_id = c.execute(
            "SELECT device_id FROM device_config LIMIT 1").fetchone()[0]
        remote_client = RemoteDocumentClient(self.nuxeo_url,
                                             self.admin_user,
                                             device_id,
                                             nxdrive.__version__,
                                             password=self.admin_password)
        token = remote_client.request_token()
        c.execute(
            "UPDATE server_bindings SET remote_token='%s' WHERE local_folder='%s'"
            % (token, '/home/ataillefer/Nuxeo Drive'))

        # Update server URL with test server URL
        c.execute(
            "UPDATE server_bindings SET server_url='%s' WHERE local_folder='%s'"
            % (self.nuxeo_url, '/home/ataillefer/Nuxeo Drive'))

        # Update local folder with test temp dir
        local_folder = os.path.join(self.test_folder, 'Nuxeo Drive')
        c.execute(
            "UPDATE server_bindings SET local_folder='%s' WHERE local_folder='%s'"
            % (local_folder, '/home/ataillefer/Nuxeo Drive'))
        conn.commit()
        conn.close()

        # Create Manager with old DB migration
        manager = self._create_manager()
        dao = manager.get_dao()

        # Check Manager config
        self.assertEquals(dao.get_config('device_id'), device_id)
        self.assertEquals(dao.get_config('proxy_config'), 'Manual')
        self.assertEquals(dao.get_config('proxy_type'), 'http')
        self.assertEquals(dao.get_config('proxy_server'), 'proxy.server.com')
        self.assertEquals(dao.get_config('proxy_port'), '80')
        self.assertEquals(dao.get_config('proxy_authenticated'), '1')
        self.assertEquals(dao.get_config('proxy_username'), 'Administrator')
        self.assertEquals(dao.get_config('auto_update'), '1')
        self.assertEquals(dao.get_config('proxy_config'), 'Manual')

        # Check engine definition
        engines = dao.get_engines()
        self.assertEquals(len(engines), 1)
        engine = engines[0]
        self.assertEquals(engine.engine, 'NXDRIVE')
        self.assertEquals(engine.name,
                          manager._get_engine_name(self.nuxeo_url))
        self.assertTrue(local_folder in engine.local_folder)

        # Check engine config
        engine_uid = engine.uid
        engine_db = os.path.join(self.test_folder, 'ndrive_%s.db' % engine_uid)
        engine_dao = EngineDAO(engine_db)
        self.assertEquals(engine_dao.get_config('server_url'), self.nuxeo_url)
        self.assertEquals(engine_dao.get_config('remote_user'),
                          'Administrator')
        self.assertEquals(engine_dao.get_config('remote_token'), token)

        engine_dao.dispose()
        manager.dispose_all()