File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1+ import os
12import json
23import webbrowser
34import httplib2
@@ -224,6 +225,9 @@ def LocalWebserverAuth(
224225 This function is not for web server application. It creates local web
225226 server for user from standalone application.
226227
228+ If GDRIVE_NON_INTERACTIVE environment variable is set, this function
229+ raises AuthenticationError.
230+
227231 :param host_name: host name of the local web server.
228232 :type host_name: str.
229233 :param port_numbers: list of port numbers to be tried to used.
@@ -237,6 +241,11 @@ def LocalWebserverAuth(
237241 :returns: str -- code returned from local web server
238242 :raises: AuthenticationRejected, AuthenticationError
239243 """
244+ if os .getenv ("GDRIVE_NON_INTERACTIVE" ):
245+ raise AuthenticationError (
246+ "Non interactive mode (GDRIVE_NON_INTERACTIVE env) is enabled"
247+ )
248+
240249 if port_numbers is None :
241250 port_numbers = [
242251 8080 ,
Original file line number Diff line number Diff line change 11import json
22import os
3+ import re
34import time
45import pytest
6+ from pytest import MonkeyPatch
57
6- from pydrive2 .auth import GoogleAuth
8+ from pydrive2 .auth import AuthenticationError , GoogleAuth
79from pydrive2 .test .test_util import (
810 setup_credentials ,
911 delete_file ,
@@ -188,6 +190,27 @@ def test_12_ServiceAuthFromJsonDictNoCredentialsSaving():
188190 time .sleep (1 )
189191
190192
193+ def test_13_LocalWebServerAuthNonInterativeRaises ():
194+ settings = {
195+ "client_config_backend" : "file" ,
196+ "client_config_file" : "client_secrets.json" ,
197+ "oauth_scope" : ["https://www.googleapis.com/auth/drive" ],
198+ }
199+ ga = GoogleAuth (settings = settings )
200+
201+ with MonkeyPatch .context () as m :
202+ m .setenv ("GDRIVE_NON_INTERACTIVE" , "true" )
203+ # Test that exception is raised on trying to do browser auth if
204+ # we are running in a non interactive environment.
205+ with pytest .raises (
206+ AuthenticationError ,
207+ match = re .escape (
208+ "Non interactive mode (GDRIVE_NON_INTERACTIVE env) is enabled"
209+ ),
210+ ):
211+ ga .LocalWebserverAuth ()
212+
213+
191214def CheckCredentialsFile (credentials , no_file = False ):
192215 ga = GoogleAuth (settings_file_path ("test_oauth_default.yaml" ))
193216 ga .LoadCredentialsFile (credentials )
You can’t perform that action at this time.
0 commit comments