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,47 +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
- # 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
-
177
146
def test_multi_auth (self , dbx_from_env , dbx_app_auth_from_env , dbx_share_url_from_env ):
178
147
# Test for user (with oauth token)
179
148
preview_result , resp = dbx_from_env .files_get_thumbnail_v2 (
@@ -288,7 +257,10 @@ def test_versioned_route(self, dbx_from_env):
288
257
# Verify response type is of v2 route
289
258
assert isinstance (resp , DeleteResult )
290
259
291
- @pytest .mark .usefixtures ("dbx_team_from_env" )
260
+ @pytest .mark .usefixtures (
261
+ "pytest_setup" ,
262
+ "dbx_team_from_env" ,
263
+ )
292
264
class TestDropboxTeam :
293
265
def test_team (self , dbx_team_from_env ):
294
266
dbx_team_from_env .team_groups_list ()
@@ -318,3 +290,41 @@ def test_clone_when_team_linked(self, dbx_team_from_env):
318
290
new_dbxt = dbx_team_from_env .clone ()
319
291
assert dbx_team_from_env is not new_dbxt
320
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
+ # 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