40
40
PathRoot ,
41
41
PathRoot_validator ,
42
42
)
43
+ from dropbox .session import SSLError
43
44
44
45
# Key Types
45
46
REFRESH_TOKEN_KEY = "REFRESH_TOKEN"
@@ -67,6 +68,7 @@ def _value_from_env_or_die(env_name):
67
68
return value
68
69
69
70
_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" )
70
72
71
73
@pytest .fixture (params = [None , _TRUSTED_CERTS_FILE ], ids = ["no-pinning" , "pinning" ])
72
74
def dbx_session (request ):
@@ -118,7 +120,7 @@ def dbx_share_url_from_env():
118
120
TIMESTAMP = str (datetime .datetime .utcnow ())
119
121
STATIC_FILE = "/test.txt"
120
122
121
- @pytest .fixture (scope = 'module' , autouse = True )
123
+ @pytest .fixture (scope = 'module' )
122
124
def pytest_setup ():
123
125
print ("Setup" )
124
126
dbx = Dropbox (_value_from_env_or_die (format_env_name ()))
@@ -133,44 +135,14 @@ def pytest_setup():
133
135
except Exception :
134
136
print ("File not found" )
135
137
136
-
137
138
@pytest .mark .usefixtures (
139
+ "pytest_setup" ,
138
140
"dbx_from_env" ,
139
141
"refresh_dbx_from_env" ,
140
142
"dbx_app_auth_from_env" ,
141
- "dbx_share_url_from_env"
143
+ "dbx_share_url_from_env" ,
142
144
)
143
145
class 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
-
174
146
def test_multi_auth (self , dbx_from_env , dbx_app_auth_from_env , dbx_share_url_from_env ):
175
147
# Test for user (with oauth token)
176
148
preview_result , resp = dbx_from_env .files_get_thumbnail_v2 (
@@ -285,7 +257,10 @@ def test_versioned_route(self, dbx_from_env):
285
257
# Verify response type is of v2 route
286
258
assert isinstance (resp , DeleteResult )
287
259
288
- @pytest .mark .usefixtures ("dbx_team_from_env" )
260
+ @pytest .mark .usefixtures (
261
+ "pytest_setup" ,
262
+ "dbx_team_from_env" ,
263
+ )
289
264
class TestDropboxTeam :
290
265
def test_team (self , dbx_team_from_env ):
291
266
dbx_team_from_env .team_groups_list ()
@@ -315,3 +290,40 @@ def test_clone_when_team_linked(self, dbx_team_from_env):
315
290
new_dbxt = dbx_team_from_env .clone ()
316
291
assert dbx_team_from_env is not new_dbxt
317
292
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