This repository has been archived by the owner on Feb 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #883 from dissemin/shibboleth
Shibboleth
- Loading branch information
Showing
56 changed files
with
4,642 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from functools import wraps | ||
|
||
def shib_meta_to_user(view_func): | ||
""" | ||
Decorator that adds shib_meta dict from request.session to request.user | ||
This could also be done in the middleware, but just sometimes need to access the attributes; and request.session is usually the better place | ||
We use this, so we do not need to pass around a request to all the backend deposit functions that only care about the user | ||
""" | ||
@wraps(view_func) | ||
def inner(request, *args, **kwargs): | ||
request.user.shib = request.session.get('shib', {}) | ||
return view_func(request, *args, **kwargs) | ||
return inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.contrib.auth.middleware import AuthenticationMiddleware | ||
from django.contrib.sessions.middleware import SessionMiddleware | ||
from django.http import HttpResponse | ||
|
||
from deposit.decorators import shib_meta_to_user | ||
from website.middleware import ShibbolethRemoteUserMiddleware | ||
|
||
class TestShibMetaToUser: | ||
|
||
def test_with_values(self, db, monkeypatch, rf, shib_meta): | ||
monkeypatch.setattr(ShibbolethRemoteUserMiddleware, 'parse_attributes', lambda x, y: (shib_meta, None)) | ||
request = rf.get('/', REMOTE_USER=shib_meta.get('username')) | ||
SessionMiddleware().process_request(request) | ||
AuthenticationMiddleware().process_request(request) | ||
ShibbolethRemoteUserMiddleware().process_request(request) | ||
|
||
# Let's test the decorator | ||
@shib_meta_to_user | ||
def sample_view(request): | ||
# Let's check the attribute | ||
assert request.user.shib == shib_meta | ||
return HttpResponse() | ||
response = sample_view(request) | ||
assert response.status_code == 200 | ||
|
||
def test_without_values(self, rf): | ||
request = rf.get('/') | ||
SessionMiddleware().process_request(request) | ||
AuthenticationMiddleware().process_request(request) | ||
|
||
# Let's test the decorator | ||
@shib_meta_to_user | ||
def sample_view(request): | ||
# Let's check the attribute | ||
assert request.user.shib =={} | ||
return HttpResponse() | ||
response = sample_view(request) | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.