4040 PathRoot ,
4141 PathRoot_validator ,
4242)
43+ from dropbox .session import SSLError
4344
4445# Key Types
4546REFRESH_TOKEN_KEY = "REFRESH_TOKEN"
@@ -67,6 +68,7 @@ def _value_from_env_or_die(env_name):
6768 return value
6869
6970_TRUSTED_CERTS_FILE = os .path .join (os .path .dirname (__file__ ), "trusted-certs.crt" )
71+ _EXPIRED_CERTS_FILE = os .path .join (os .path .dirname (__file__ ), "expired-certs.crt" )
7072
7173@pytest .fixture (params = [None , _TRUSTED_CERTS_FILE ], ids = ["no-pinning" , "pinning" ])
7274def dbx_session (request ):
@@ -118,7 +120,7 @@ def dbx_share_url_from_env():
118120TIMESTAMP = str (datetime .datetime .utcnow ())
119121STATIC_FILE = "/test.txt"
120122
121- @pytest .fixture (scope = 'module' , autouse = True )
123+ @pytest .fixture (scope = 'module' )
122124def pytest_setup ():
123125 print ("Setup" )
124126 dbx = Dropbox (_value_from_env_or_die (format_env_name ()))
@@ -133,44 +135,14 @@ def pytest_setup():
133135 except Exception :
134136 print ("File not found" )
135137
136-
137138@pytest .mark .usefixtures (
139+ "pytest_setup" ,
138140 "dbx_from_env" ,
139141 "refresh_dbx_from_env" ,
140142 "dbx_app_auth_from_env" ,
141- "dbx_share_url_from_env"
143+ "dbx_share_url_from_env" ,
142144)
143145class TestDropbox :
144- def test_default_oauth2_urls (self ):
145- flow_obj = DropboxOAuth2Flow ('dummy_app_key' , 'dummy_app_secret' ,
146- 'http://localhost/dummy' , 'dummy_session' , 'dbx-auth-csrf-token' )
147-
148- assert re .match (
149- r'^https://{}/oauth2/authorize\?' .format (re .escape (session .WEB_HOST )),
150- flow_obj ._get_authorize_url ('http://localhost/redirect' , 'state' , 'legacy' ),
151- )
152-
153- assert flow_obj .build_url (
154- '/oauth2/authorize'
155- ) == 'https://{}/oauth2/authorize' .format (session .API_HOST )
156-
157- assert flow_obj .build_url (
158- '/oauth2/authorize' , host = session .WEB_HOST
159- ) == 'https://{}/oauth2/authorize' .format (session .WEB_HOST )
160-
161- def test_bad_auth (self ):
162- # Test malformed token
163- malformed_token_dbx = Dropbox (MALFORMED_TOKEN )
164- with pytest .raises (BadInputError ,) as cm :
165- malformed_token_dbx .files_list_folder ('' )
166- assert 'token is malformed' in cm .value .message
167-
168- # Test reasonable-looking invalid token
169- invalid_token_dbx = Dropbox (INVALID_TOKEN )
170- with pytest .raises (AuthError ) as cm :
171- invalid_token_dbx .files_list_folder ('' )
172- assert cm .value .error .is_invalid_access_token ()
173-
174146 def test_multi_auth (self , dbx_from_env , dbx_app_auth_from_env , dbx_share_url_from_env ):
175147 # Test for user (with oauth token)
176148 preview_result , resp = dbx_from_env .files_get_thumbnail_v2 (
@@ -285,7 +257,10 @@ def test_versioned_route(self, dbx_from_env):
285257 # Verify response type is of v2 route
286258 assert isinstance (resp , DeleteResult )
287259
288- @pytest .mark .usefixtures ("dbx_team_from_env" )
260+ @pytest .mark .usefixtures (
261+ "pytest_setup" ,
262+ "dbx_team_from_env" ,
263+ )
289264class TestDropboxTeam :
290265 def test_team (self , dbx_team_from_env ):
291266 dbx_team_from_env .team_groups_list ()
@@ -315,3 +290,40 @@ def test_clone_when_team_linked(self, dbx_team_from_env):
315290 new_dbxt = dbx_team_from_env .clone ()
316291 assert dbx_team_from_env is not new_dbxt
317292 assert isinstance (new_dbxt , dbx_team_from_env .__class__ )
293+
294+ def test_default_oauth2_urls ():
295+ flow_obj = DropboxOAuth2Flow ('dummy_app_key' , 'dummy_app_secret' ,
296+ 'http://localhost/dummy' , 'dummy_session' , 'dbx-auth-csrf-token' )
297+
298+ assert re .match (
299+ r'^https://{}/oauth2/authorize\?' .format (re .escape (session .WEB_HOST )),
300+ flow_obj ._get_authorize_url ('http://localhost/redirect' , 'state' , 'legacy' ),
301+ )
302+
303+ assert flow_obj .build_url (
304+ '/oauth2/authorize'
305+ ) == 'https://{}/oauth2/authorize' .format (session .API_HOST )
306+
307+ assert flow_obj .build_url (
308+ '/oauth2/authorize' , host = session .WEB_HOST
309+ ) == 'https://{}/oauth2/authorize' .format (session .WEB_HOST )
310+
311+ def test_bad_auth (dbx_session ):
312+ # Test malformed token
313+ malformed_token_dbx = Dropbox (MALFORMED_TOKEN , session = dbx_session )
314+ # TODO: backend is no longer returning `BadInputError`
315+ #with pytest.raises(BadInputError,) as cm:
316+ with pytest .raises (AuthError ):
317+ malformed_token_dbx .files_list_folder ('' )
318+ #assert 'token is malformed' in cm.value.message
319+
320+ # Test reasonable-looking invalid token
321+ invalid_token_dbx = Dropbox (INVALID_TOKEN , session = dbx_session )
322+ with pytest .raises (AuthError ) as cm :
323+ invalid_token_dbx .files_list_folder ('' )
324+ assert cm .value .error .is_invalid_access_token ()
325+
326+ def test_bad_pins ():
327+ _dbx = Dropbox ("dummy_token" , ca_certs = _EXPIRED_CERTS_FILE )
328+ with pytest .raises (SSLError ,) as cm :
329+ _dbx .files_list_folder ('' )
0 commit comments