def test_get_proxies(self): for k in ('http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY'): os.environ[k] = 'http://foo/bar' authenticator = od_auth.OneDriveAuthenticator() self.assertIsInstance(authenticator.client.http_provider, HttpProviderWithProxy) self.assertEqual({k.split('_')[0].lower(): 'http://foo/bar'}, authenticator.client.http_provider.proxies) del os.environ[k]
def get_sample_authenticator(): auth = od_auth.OneDriveAuthenticator() session_params = json.loads( get_resource('data/session_response.json', pkg_name='tests')) session_params['token_type'] = 'code' session_params['client_id'] = auth.APP_CLIENT_ID session_params['scope_string'] = session_params['scope'] session_params['redirect_uri'] = auth.APP_REDIRECT_URL session_params['auth_server_url'] = 'https://localhost/auth' del session_params['scope'] auth.client.auth_provider._session = od_api_session.OneDriveAPISession( **session_params) auth.refresh_session = lambda x: None return auth
def authenticate_account(get_auth_url=False, code=None, for_business=False): if for_business: authenticator = od_auth.OneDriveBusinessAuthenticator() else: # personal account authenticator = od_auth.OneDriveAuthenticator() click.echo(translator['od_pref.authenticate_account.permission_note']) if code is None: click.echo(translator['od_pref.authenticate_account.paste_url_note']) click.echo('\n' + click.style(authenticator.get_auth_url(), underline=True) + '\n') if get_auth_url: return click.echo(translator['od_pref.authenticate_account.paste_url_instruction'].format( redirect_url=click.style(authenticator.APP_REDIRECT_URL, bold=True))) url = click.prompt(translator['od_pref.authenticate_account.paste_url_prompt'], type=str) code = extract_qs_param(url, 'code') if code is None: error(translator['od_pref.authenticate_account.error.code_not_found_in_url']) return # Second authorization for the business accounts if for_business: auth_url = authenticator.authentication_url redirect_url = authenticator.REDIRECT_URL try: # Get user information click.echo(translator['od_pref.authenticate_account.second_authentication']) click.echo(translator['od_pref.authenticate_account.paste_url_note']) click.echo('\n' + click.style(auth_url, underline=True) + '\n') click.echo(translator['od_pref.authenticate_account.paste_url_instruction'].format( redirect_url=click.style(redirect_url, bold=True))) url = click.prompt( translator['od_pref.authenticate_account.paste_url_prompt'], type=str) authenticator.code = extract_qs_param(url, 'code') click.echo() except Exception as e: error(translator[ 'od_pref.authenticate_account.error.authorization'].format( error_message=str(e))) try: authenticator.authenticate(code) success(translator['od_pref.authenticate_account.success.authorized']) save_account(authenticator) except Exception as e: error(translator['od_pref.authenticate_account.error.authorization'].format(error_message=str(e)))
def test_get_auth_url(self): authenticator = od_auth.OneDriveAuthenticator() self.assertIsInstance(authenticator.get_auth_url(), str)