コード例 #1
0
def test_request_token(server):
    app_name = 'Nuxeo Drive'
    device_id = '41f0711a-f008-4c11-b3f1-c5bddcb50d77'
    device = 'GNU/Linux'
    permission = 'ReadWrite'

    prev_auth = server.client.auth
    try:
        token = server.client.request_auth_token(device_id,
                                                 permission,
                                                 app_name=app_name,
                                                 device=device)
        assert server.client.auth.token == token
        assert server.client.auth == TokenAuth(token)
        assert server.client.auth != TokenAuth('0')
        assert server.client.is_reachable()

        # Calling twice should return the same token
        same_token = server.client.request_auth_token(device_id,
                                                      permission,
                                                      app_name=app_name,
                                                      device=device)
        assert token == same_token
    finally:
        server.client.auth = prev_auth
コード例 #2
0
    def __init__(
        self,
        url: str,
        user_id: str,
        device_id: str,
        version: str,
        password: str = None,
        token: str = None,
        proxy: Proxy = None,
        upload_tmp_dir: str = None,
        check_suspended: Callable = None,
        base_folder: str = None,
        dao: "EngineDAO" = None,
        repository: str = Options.remote_repo,
        timeout: int = TIMEOUT,
        **kwargs: Any,
    ) -> None:
        auth = TokenAuth(token) if token else (user_id, password)
        self.kwargs = kwargs

        super().__init__(
            auth=auth,
            host=url,
            app_name=APP_NAME,
            version=version,
            repository=repository,
            **kwargs,
        )

        self.client.headers.update({
            "X-User-Id": user_id,
            "X-Device-Id": device_id,
            "Cache-Control": "no-cache",
        })

        self.set_proxy(proxy)

        if dao:
            self._dao = dao

        self.timeout = timeout if timeout > 0 else TIMEOUT

        self.device_id = device_id
        self.user_id = user_id
        self.version = version
        self.check_suspended = check_suspended
        self._has_new_trash_service = not version_le(
            self.client.server_version, "10.1")

        self.upload_tmp_dir = (upload_tmp_dir if upload_tmp_dir is not None
                               else tempfile.gettempdir())

        self.upload_lock = Lock()

        if base_folder is not None:
            base_folder_doc = self.fetch(base_folder)
            self._base_folder_ref = base_folder_doc["uid"]
            self._base_folder_path = base_folder_doc["path"]
        else:
            self._base_folder_ref, self._base_folder_path = None, None
コード例 #3
0
def test_token_equality():
    auth1 = TokenAuth("secure_token")
    auth2 = TokenAuth("0")
    assert auth1 != auth2
コード例 #4
0
def test_token():
    auth = TokenAuth("secure_token")
    req = Request("GET", "https://httpbin.org/get", auth=auth)
    prepared = req.prepare()
    assert prepared.headers[auth.HEADER_TOKEN] == "secure_token"
コード例 #5
0
    def __init__(
        self,
        url: str,
        user_id: str,
        device_id: str,
        version: str,
        password: str = None,
        token: str = None,
        proxy: Proxy = None,
        download_callback: Callable = None,
        upload_callback: Callable = None,
        base_folder: str = None,
        dao: "EngineDAO" = None,
        repository: str = Options.remote_repo,
        timeout: int = Options.timeout,
        **kwargs: Any,
    ) -> None:
        auth = TokenAuth(token) if token else (user_id, password)

        super().__init__(
            auth=auth,
            host=url,
            app_name=APP_NAME,
            version=version,
            repository=repository,
            **kwargs,
        )

        self.client.headers.update({
            "X-User-Id": user_id,
            "X-Device-Id": device_id,
            "Cache-Control": "no-cache",
        })

        self.set_proxy(proxy)

        if dao:
            self.dao = dao

        self.timeout = timeout if timeout > 0 else TIMEOUT

        self.device_id = device_id
        self.user_id = user_id
        self.version = version

        # Callback function used for downloads.
        # Note: the order is important, keep it!
        self.download_callback = (
            self.transfer_start_callback,
            download_callback,
            self.transfer_end_callback,
        )

        # Callback function used for chunked uploads.
        # It will be forwarded to Batch.get_uploader() on the Nuxeo Python Client side.
        # Note: the order is important, keep it!
        self.upload_callback = (
            self.transfer_start_callback,
            upload_callback,
            self.transfer_end_callback,
        )

        self._has_new_trash_service = not version_le(
            self.client.server_version, "10.1")

        if base_folder is not None:
            base_folder_doc = self.fetch(base_folder)
            self.base_folder_ref = base_folder_doc["uid"]
            self._base_folder_path = base_folder_doc["path"]
        else:
            self.base_folder_ref, self._base_folder_path = None, None
コード例 #6
0
 def update_token(self, token: str) -> None:
     self.auth = TokenAuth(token)
     self.client.auth = self.auth