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,47 +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- # TODO: backend is no longer returning `BadInputError`
165- # with pytest.raises(BadInputError,) as cm:
166- # malformed_token_dbx.files_list_folder('')
167- # assert 'token is malformed' in cm.value.message
168- with pytest .raises (AuthError ,):
169- malformed_token_dbx .files_list_folder ('' )
170-
171- # Test reasonable-looking invalid token
172- invalid_token_dbx = Dropbox (INVALID_TOKEN )
173- with pytest .raises (AuthError ) as cm :
174- invalid_token_dbx .files_list_folder ('' )
175- assert cm .value .error .is_invalid_access_token ()
176-
177146 def test_multi_auth (self , dbx_from_env , dbx_app_auth_from_env , dbx_share_url_from_env ):
178147 # Test for user (with oauth token)
179148 preview_result , resp = dbx_from_env .files_get_thumbnail_v2 (
@@ -288,7 +257,10 @@ def test_versioned_route(self, dbx_from_env):
288257 # Verify response type is of v2 route
289258 assert isinstance (resp , DeleteResult )
290259
291- @pytest .mark .usefixtures ("dbx_team_from_env" )
260+ @pytest .mark .usefixtures (
261+ "pytest_setup" ,
262+ "dbx_team_from_env" ,
263+ )
292264class TestDropboxTeam :
293265 def test_team (self , dbx_team_from_env ):
294266 dbx_team_from_env .team_groups_list ()
@@ -318,3 +290,41 @@ def test_clone_when_team_linked(self, dbx_team_from_env):
318290 new_dbxt = dbx_team_from_env .clone ()
319291 assert dbx_team_from_env is not new_dbxt
320292 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+ # malformed_token_dbx.files_list_folder('')
317+ # assert 'token is malformed' in cm.value.message
318+ with pytest .raises (AuthError ):
319+ malformed_token_dbx .files_list_folder ('' )
320+
321+ # Test reasonable-looking invalid token
322+ invalid_token_dbx = Dropbox (INVALID_TOKEN , session = dbx_session )
323+ with pytest .raises (AuthError ) as cm :
324+ invalid_token_dbx .files_list_folder ('' )
325+ assert cm .value .error .is_invalid_access_token ()
326+
327+ def test_bad_pins ():
328+ _dbx = Dropbox ("dummy_token" , ca_certs = _EXPIRED_CERTS_FILE )
329+ with pytest .raises (SSLError ,) as cm :
330+ _dbx .files_list_folder ('' )
0 commit comments