Skip to content

Commit f133272

Browse files
committed
manually wrap some long lines
1 parent 3452cbd commit f133272

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

Allura/allura/controllers/rest.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,17 @@ def validate_redirect_uri(self, client_id, redirect_uri, request, *args, **kwarg
271271
client = M.OAuth2ClientApp.query.get(client_id=client_id)
272272
return redirect_uri in client.redirect_uris
273273

274-
def validate_response_type(self, client_id: str, response_type: str, client: oauthlib.oauth2.Client, request: oauthlib.common.Request, *args, **kwargs) -> bool:
274+
def validate_response_type(self, client_id: str, response_type: str, client: oauthlib.oauth2.Client,
275+
request: oauthlib.common.Request, *args, **kwargs) -> bool:
275276
res_type = M.OAuth2ClientApp.query.get(client_id=client_id).response_type
276277
return res_type == response_type
277278

278-
def validate_scopes(self, client_id: str, scopes, client: oauthlib.oauth2.Client, request: oauthlib.common.Request, *args, **kwargs) -> bool:
279+
def validate_scopes(self, client_id: str, scopes, client: oauthlib.oauth2.Client,
280+
request: oauthlib.common.Request, *args, **kwargs) -> bool:
279281
return True
280282

281-
def validate_grant_type(self, client_id: str, grant_type: str, client: oauthlib.oauth2.Client, request: oauthlib.common.Request, *args, **kwargs) -> bool:
283+
def validate_grant_type(self, client_id: str, grant_type: str, client: oauthlib.oauth2.Client,
284+
request: oauthlib.common.Request, *args, **kwargs) -> bool:
282285
return grant_type in ['authorization_code', 'refresh_token']
283286

284287
def get_default_scopes(self, client_id: str, request: oauthlib.common.Request, *args, **kwargs):
@@ -302,14 +305,16 @@ def get_code_challenge_method(self, code: str, request: oauthlib.common.Request)
302305
authorization_code = M.OAuth2AuthorizationCode.query.get(authorization_code=code)
303306
return authorization_code.code_challenge_method
304307

305-
def invalidate_authorization_code(self, client_id: str, code: str, request: oauthlib.common.Request, *args, **kwargs) -> None:
308+
def invalidate_authorization_code(self, client_id: str, code: str,
309+
request: oauthlib.common.Request, *args, **kwargs) -> None:
306310
M.OAuth2AuthorizationCode.query.remove({'client_id': client_id, 'authorization_code': code})
307311

308312
def authenticate_client(self, request: oauthlib.common.Request, *args, **kwargs) -> bool:
309313
request.client = M.OAuth2ClientApp.query.get(client_id=request.client_id, client_secret=request.client_secret)
310314
return request.client is not None
311315

312-
def validate_code(self, client_id: str, code: str, client: oauthlib.oauth2.Client, request: oauthlib.common.Request, *args, **kwargs) -> bool:
316+
def validate_code(self, client_id: str, code: str, client: oauthlib.oauth2.Client,
317+
request: oauthlib.common.Request, *args, **kwargs) -> bool:
313318
authorization = M.OAuth2AuthorizationCode.query.get(client_id=client_id, authorization_code=code)
314319
return authorization.expires_at >= datetime.utcnow() if authorization else False
315320

@@ -321,12 +326,15 @@ def validate_bearer_token(self, token: str, scopes: list[str], request: oauthlib
321326
else:
322327
return False
323328

324-
def validate_refresh_token(self, refresh_token: str, client: oauthlib.oauth2.Client, request: oauthlib.common.Request, *args, **kwargs) -> bool:
329+
def validate_refresh_token(self, refresh_token: str, client: oauthlib.oauth2.Client,
330+
request: oauthlib.common.Request, *args, **kwargs) -> bool:
325331
return M.OAuth2AccessToken.query.get(refresh_token=refresh_token, client_id=client.client_id) is not None
326332

327-
def confirm_redirect_uri(self, client_id: str, code: str, redirect_uri: str, client: oauthlib.oauth2.Client, request: oauthlib.common.Request, *args, **kwargs) -> bool:
333+
def confirm_redirect_uri(self, client_id: str, code: str, redirect_uri: str, client: oauthlib.oauth2.Client,
334+
request: oauthlib.common.Request, *args, **kwargs) -> bool:
328335
# This method is called when the client is exchanging the authorization code for an access token.
329-
# If a redirect uri was provided when the authorization code was created, it must match the redirect uri provided here.
336+
# If a redirect uri was provided when the authorization code was created,
337+
# it must match the redirect uri provided here.
330338
authorization = M.OAuth2AuthorizationCode.query.get(client_id=client_id, authorization_code=code)
331339
return authorization.redirect_uri == redirect_uri
332340

@@ -352,9 +360,15 @@ def save_authorization_code(self, client_id: str, code, request: oauthlib.common
352360

353361
def save_bearer_token(self, token, request: oauthlib.common.Request, *args, **kwargs) -> object:
354362
if request.grant_type == 'authorization_code':
355-
user_id = M.OAuth2AuthorizationCode.query.get(client_id=request.client_id, authorization_code=request.code).user_id
363+
user_id = M.OAuth2AuthorizationCode.query.get(
364+
client_id=request.client_id,
365+
authorization_code=request.code,
366+
).user_id
356367
elif request.grant_type == 'refresh_token':
357-
user_id = M.OAuth2AccessToken.query.get(client_id=request.client_id, refresh_token=request.refresh_token).user_id
368+
user_id = M.OAuth2AccessToken.query.get(
369+
client_id=request.client_id,
370+
refresh_token=request.refresh_token,
371+
).user_id
358372

359373
current_token = M.OAuth2AccessToken.query.get(client_id=request.client_id, user_id=user_id, is_bearer=False)
360374

@@ -541,7 +555,12 @@ def token(self, **kwargs):
541555
except json.decoder.JSONDecodeError:
542556
request_body = decoded_body
543557

544-
headers, body, status = self.server.create_token_response(uri=request.url, http_method=request.method, body=request_body, headers=request.headers)
558+
headers, body, status = self.server.create_token_response(
559+
uri=request.url,
560+
http_method=request.method,
561+
body=request_body,
562+
headers=request.headers,
563+
)
545564
response.headers.update(headers)
546565
response.status_int = status
547566
return body

Allura/allura/tests/functional/test_auth.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,20 @@ def test_login_redirect(self):
245245
assert r.location == 'http://localhost/'
246246

247247
# redir to requested location
248-
r = self.app.get('/auth/', extra_environ={'username': 'test-admin'}, params={'return_to': '/p/test/?a=b'},
248+
r = self.app.get('/auth/', extra_environ={'username': 'test-admin'},
249+
params={'return_to': '/p/test/?a=b'},
249250
status=302)
250251
assert r.location == 'http://localhost/p/test/?a=b'
251252

252253
# no redirect loop on /auth/
253-
r = self.app.get('/auth/', extra_environ={'username': 'test-admin'}, params={'return_to': '/auth/'},
254+
r = self.app.get('/auth/', extra_environ={'username': 'test-admin'},
255+
params={'return_to': '/auth/'},
254256
status=302)
255257
assert r.location == 'http://localhost/'
256258

257259
# no external redirect
258-
r = self.app.get('/auth/', extra_environ={'username': 'test-admin'}, params={'return_to': 'http://example.com/x'},
260+
r = self.app.get('/auth/', extra_environ={'username': 'test-admin'},
261+
params={'return_to': 'http://example.com/x'},
259262
status=302)
260263
assert r.location == 'http://localhost/'
261264

@@ -3510,7 +3513,9 @@ def test_navigation_with_invalid_session(self):
35103513
self.app.set_cookie('beaker.session.id', 'invalid-session-id')
35113514

35123515
# Navigating to a page with an invalid session id should redirect to the login page
3513-
r = self.app.get('/auth/preferences/', extra_environ={'username': 'test-user', 'disable_auth_magic': 'True'}, status=302)
3516+
r = self.app.get('/auth/preferences/',
3517+
extra_environ={'username': 'test-user', 'disable_auth_magic': 'True'},
3518+
status=302)
35143519
assert '/auth/?return_to=%2Fauth%2Fpreferences%2F' in r.location
35153520

35163521
@mock.patch.dict(config, {'auth.reject_untracked_sessions': True})

0 commit comments

Comments
 (0)