File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change
1
+ import os
1
2
import json
2
3
import webbrowser
3
4
import httplib2
@@ -224,6 +225,9 @@ def LocalWebserverAuth(
224
225
This function is not for web server application. It creates local web
225
226
server for user from standalone application.
226
227
228
+ If GDRIVE_NON_INTERACTIVE environment variable is set, this function
229
+ raises AuthenticationError.
230
+
227
231
:param host_name: host name of the local web server.
228
232
:type host_name: str.
229
233
:param port_numbers: list of port numbers to be tried to used.
@@ -237,6 +241,11 @@ def LocalWebserverAuth(
237
241
:returns: str -- code returned from local web server
238
242
:raises: AuthenticationRejected, AuthenticationError
239
243
"""
244
+ if os .getenv ("GDRIVE_NON_INTERACTIVE" ):
245
+ raise AuthenticationError (
246
+ "Non interactive mode (GDRIVE_NON_INTERACTIVE env) is enabled"
247
+ )
248
+
240
249
if port_numbers is None :
241
250
port_numbers = [
242
251
8080 ,
Original file line number Diff line number Diff line change 1
1
import json
2
2
import os
3
+ import re
3
4
import time
4
5
import pytest
6
+ from pytest import MonkeyPatch
5
7
6
- from pydrive2 .auth import GoogleAuth
8
+ from pydrive2 .auth import AuthenticationError , GoogleAuth
7
9
from pydrive2 .test .test_util import (
8
10
setup_credentials ,
9
11
delete_file ,
@@ -188,6 +190,27 @@ def test_12_ServiceAuthFromJsonDictNoCredentialsSaving():
188
190
time .sleep (1 )
189
191
190
192
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
+
191
214
def CheckCredentialsFile (credentials , no_file = False ):
192
215
ga = GoogleAuth (settings_file_path ("test_oauth_default.yaml" ))
193
216
ga .LoadCredentialsFile (credentials )
You can’t perform that action at this time.
0 commit comments