Skip to content

Commit

Permalink
cilogon: test with new name, old name confirmed to work
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Feb 9, 2025
1 parent cfa9328 commit 4e907fd
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions oauthenticator/tests/test_cilogon.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def test_cilogon(
print(f"Running test variation id {test_variation_id}")
c = Config()
c.CILogonOAuthenticator = Config(class_config)
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
"https://some-idp.com/login/oauth/authorize": {
"username_derivation": {
"username_claim": "name",
Expand Down Expand Up @@ -449,7 +449,7 @@ async def test_cilogon_idps(
c = Config()
c.CILogonOAuthenticator = Config(class_config)
test_idp = "https://some-idp.com/login/oauth/authorize"
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
test_idp: idp_config,
}
authenticator = CILogonOAuthenticator(config=c)
Expand Down Expand Up @@ -533,12 +533,13 @@ async def test_cilogon_idps(
{
"idps": {
"https://github.com/login/oauth/authorize": {
"username_derivation": {"username_claim": "email"}
'allowed_domains': [],
"username_derivation": {"username_claim": "email"},
}
}
},
logging.WARNING,
"CILogonOAuthenticator.allowed_idps is deprecated in CILogonOAuthenticator 16.1.0, use CILogonOAuthenticator.idps instead",
"CILogonOAuthenticator.allowed_idps is deprecated in CILogonOAuthenticator 17.4.0, use CILogonOAuthenticator.idps instead",
),
],
)
Expand Down Expand Up @@ -579,16 +580,16 @@ async def test_config_idps_wrong_type(caplog):
Test alllowed_idps is a dict
"""
c = Config()
c.CILogonOAuthenticator.allowed_idps = ['pink']
c.CILogonOAuthenticator.idps = ['pink']

with raises(TraitError):
CILogonOAuthenticator(config=c)


async def test_config_idps_required_username_derivation(caplog):
# Test username_derivation is a required field of allowed_idps
# Test username_derivation is a required field of idps
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://github.com/login/oauth/authorize': {},
}

Expand All @@ -598,11 +599,11 @@ async def test_config_idps_required_username_derivation(caplog):

async def test_config_idps_invalid_entity_id(caplog):
"""
Test allowed_idps keys cannot be domains, but only valid CILogon entity ids,
Test idps keys cannot be domains, but only valid CILogon entity ids,
i.e. only fully formed URLs
"""
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'uni.edu': {
'username_derivation': {
'username_claim': 'email',
Expand All @@ -627,7 +628,7 @@ async def test_config_idps_invalid_entity_id(caplog):

async def test_config_idps_invalid_type(caplog):
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://github.com/login/oauth/authorize': 'should-be-a-dict'
}
with raises(ValidationError, match="'should-be-a-dict' is not of type 'object'"):
Expand All @@ -636,7 +637,7 @@ async def test_config_idps_invalid_type(caplog):

async def test_config_idps_unrecognized_options(caplog):
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://github.com/login/oauth/authorize': {
'username_derivation': {'a': 1, 'b': 2}
}
Expand All @@ -647,7 +648,7 @@ async def test_config_idps_unrecognized_options(caplog):

async def test_config_idps_domain_required(caplog):
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://github.com/login/oauth/authorize': {
'username_derivation': {
'username_claim': 'email',
Expand All @@ -661,7 +662,7 @@ async def test_config_idps_domain_required(caplog):

async def test_config_idps_prefix_required(caplog):
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://github.com/login/oauth/authorize': {
'username_derivation': {
'username_claim': 'email',
Expand All @@ -678,7 +679,7 @@ async def test_config_scopes_validation():
Test that required scopes are appended if not configured.
"""
c = Config()
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://some-idp.com/login/oauth/authorize': {
'username_derivation': {
'username_claim': 'email',
Expand All @@ -694,14 +695,14 @@ async def test_config_scopes_validation():
assert authenticator.scope == expected_scopes


async def test_allowed_idps_username_derivation_actions(cilogon_client):
async def test_idps_username_derivation_actions(cilogon_client):
"""
Tests all `allowed_idps[].username_derivation.action` config choices:
Tests all `idps[].username_derivation.action` config choices:
`strip_idp_domain`, `prefix`, and no action specified.
"""
c = Config()
c.CILogonOAuthenticator.allow_all = True
c.CILogonOAuthenticator.allowed_idps = {
c.CILogonOAuthenticator.idps = {
'https://strip-idp-domain.example.com/login/oauth/authorize': {
'default': True,
'username_derivation': {
Expand Down Expand Up @@ -773,7 +774,7 @@ async def test_allowed_idps_username_derivation_actions(cilogon_client):


@mark.parametrize(
"test_variation_id,allowed_idps,expected_return_value",
"test_variation_id,idps,expected_return_value",
[
(
"default-specified",
Expand Down Expand Up @@ -807,7 +808,5 @@ async def test_allowed_idps_username_derivation_actions(cilogon_client):
),
],
)
async def test__get_selected_idp_param(
test_variation_id, allowed_idps, expected_return_value
):
assert _get_select_idp_param(allowed_idps) == expected_return_value
async def test__get_selected_idp_param(test_variation_id, idps, expected_return_value):
assert _get_select_idp_param(idps) == expected_return_value

0 comments on commit 4e907fd

Please sign in to comment.