forked from keitaroinc/ckanext-saml2auth
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,19 @@ | |
<saml:Attribute Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> | ||
<saml:AttributeValue xsi:type="xs:string">[email protected]</saml:AttributeValue> | ||
</saml:Attribute> | ||
<saml:Attribute Name="firstname" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> | ||
<saml:AttributeValue>John</saml:AttributeValue> | ||
</saml:Attribute> | ||
<saml:Attribute Name="lastname" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> | ||
<saml:AttributeValue>Smith</saml:AttributeValue> | ||
</saml:Attribute> | ||
<saml:Attribute Name="fullname" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> | ||
<saml:AttributeValue>John Smith (Operations)</saml:AttributeValue> | ||
</saml:Attribute> | ||
<saml:Attribute Name="eduPersonAffiliation" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"> | ||
<saml:AttributeValue xsi:type="xs:string">users</saml:AttributeValue> | ||
<saml:AttributeValue xsi:type="xs:string">examplerole1</saml:AttributeValue> | ||
</saml:Attribute> | ||
</saml:AttributeStatement> | ||
</saml:Assertion> | ||
</samlp:Response> | ||
</samlp:Response> |
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 |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import os | ||
import pytest | ||
|
||
from ckan import model | ||
|
||
from saml2.xmldsig import SIG_RSA_SHA256 | ||
from saml2.xmldsig import DIGEST_SHA256 | ||
from saml2.saml import NAMEID_FORMAT_ENTITY | ||
|
@@ -338,3 +340,74 @@ def test_signed_not_encrypted_assertion(self, app): | |
} | ||
response = app.post(url=url, params=data) | ||
assert_equal(200, response.status_code) | ||
|
||
@pytest.mark.ckan_config(u'ckanext.saml2auth.entity_id', u'urn:gov:gsa:SAML:2.0.profiles:sp:sso:test:entity') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.idp_metadata.location', u'local') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.idp_metadata.local_path', os.path.join(extras_folder, 'provider0', 'idp.xml')) | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.want_response_signed', u'False') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.want_assertions_signed', u'False') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.want_assertions_or_response_signed', u'False') | ||
def test_user_fullname_using_first_last_name(self, app): | ||
|
||
# read about saml2 responses: https://www.samltool.com/generic_sso_res.php | ||
unsigned_response_file = os.path.join(responses_folder, 'unsigned0.xml') | ||
unsigned_response = open(unsigned_response_file).read() | ||
# parse values | ||
context = { | ||
'entity_id': 'urn:gov:gsa:SAML:2.0.profiles:sp:sso:test:entity', | ||
'destination': 'http://test.ckan.net/acs', | ||
'recipient': 'http://test.ckan.net/acs', | ||
'issue_instant': datetime.now().isoformat() | ||
} | ||
t = Template(unsigned_response) | ||
final_response = t.render(**context) | ||
|
||
encoded_response = self._b4_encode_string(final_response) | ||
url = '/acs' | ||
|
||
data = { | ||
'SAMLResponse': encoded_response | ||
} | ||
response = app.post(url=url, params=data) | ||
assert_equal(200, response.status_code) | ||
|
||
user = model.User.by_email('[email protected]')[0] | ||
|
||
assert user.fullname == 'John Smith' | ||
|
||
@pytest.mark.ckan_config(u'ckanext.saml2auth.entity_id', u'urn:gov:gsa:SAML:2.0.profiles:sp:sso:test:entity') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.idp_metadata.location', u'local') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.idp_metadata.local_path', os.path.join(extras_folder, 'provider0', 'idp.xml')) | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.want_response_signed', u'False') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.want_assertions_signed', u'False') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.want_assertions_or_response_signed', u'False') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.user_fullname', u'fullname') | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.user_firstname', None) | ||
@pytest.mark.ckan_config(u'ckanext.saml2auth.user_lastname', None) | ||
def test_user_fullname_using_fullname(self, app): | ||
|
||
# read about saml2 responses: https://www.samltool.com/generic_sso_res.php | ||
unsigned_response_file = os.path.join(responses_folder, 'unsigned0.xml') | ||
unsigned_response = open(unsigned_response_file).read() | ||
# parse values | ||
context = { | ||
'entity_id': 'urn:gov:gsa:SAML:2.0.profiles:sp:sso:test:entity', | ||
'destination': 'http://test.ckan.net/acs', | ||
'recipient': 'http://test.ckan.net/acs', | ||
'issue_instant': datetime.now().isoformat() | ||
} | ||
t = Template(unsigned_response) | ||
final_response = t.render(**context) | ||
|
||
encoded_response = self._b4_encode_string(final_response) | ||
url = '/acs' | ||
|
||
data = { | ||
'SAMLResponse': encoded_response | ||
} | ||
response = app.post(url=url, params=data) | ||
assert_equal(200, response.status_code) | ||
|
||
user = model.User.by_email('[email protected]')[0] | ||
|
||
assert user.fullname == 'John Smith (Operations)' |
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