Skip to content

Commit

Permalink
Added factory method and test of the same
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Hedberg committed Apr 21, 2013
1 parent 6dec8bf commit 2b58b8b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/saml2/authn_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
PASSWORD = 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password'
TLSCLIENT = 'urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient'

from saml2.authn_context import ippword
from saml2.authn_context import mobiletwofactor
from saml2.authn_context import ppt
from saml2.authn_context import pword
from saml2.authn_context import sslcert


class Authn(object):
def __init__(self):
Expand Down Expand Up @@ -68,4 +74,14 @@ def match(self, requested, provided):
if requested == provided:
return True
else:
return False
return False


def authn_context_factory(text):
# brute force
for mod in [ippword, mobiletwofactor, ppt, pword, sslcert]:
inst = mod.authentication_context_declaration_from_string(text)
if inst:
return inst

return None
11 changes: 9 additions & 2 deletions tests/test_77_authn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</AuthenticationContextDeclaration>"""

from saml2.authn_context import pword

from saml2.authn_context import authn_context_factory

def test_passwd():
length = pword.Length(min="4")
Expand All @@ -25,5 +25,12 @@ def test_passwd():

assert inst == inst2


def test_factory():
inst_pw = pword.authentication_context_declaration_from_string(ex1)
inst = authn_context_factory(ex1)

assert inst_pw == inst

if __name__ == "__main__":
test_passwd()
test_factory()

0 comments on commit 2b58b8b

Please sign in to comment.