Skip to content

Commit

Permalink
resolves #26
Browse files Browse the repository at this point in the history
  • Loading branch information
leifj committed Jun 30, 2015
1 parent b260667 commit f0a8743
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
10 changes: 9 additions & 1 deletion src/pyff/mdrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This is the implementation of the active repository of SAML metadata. The 'local' and 'remote' pipes operate on this.
"""
import traceback
from pyff.stats import set_metadata_info, get_metadata_info

try:
Expand Down Expand Up @@ -690,8 +691,15 @@ def load_dir(self, directory, ext=".xml", url=None, validate=False, post=None, d
log.debug("parsing from file %s" % nm)
fn = os.path.join(top, nm)
try:
t, valid_until = self.parse_metadata(fn, fail_on_error=True, validate=validate, post=post)
validation_errors = dict()
t, valid_until = self.parse_metadata(fn,
fail_on_error=True,
validate=validate,
validation_errors=validation_errors,
post=post)
entities.extend(entities_list(t)) # local metadata is assumed to be ok
for (eid, error) in validation_errors.iteritems():
log.error(error)
except Exception, ex:
log.error(ex)

Expand Down
42 changes: 20 additions & 22 deletions src/pyff/test/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from traceback import print_exc
import os
import shutil
import mock
Expand All @@ -13,8 +12,6 @@
from StringIO import StringIO
from pyff.utils import hash_id, parse_xml, resource_filename, root
from pyff.test import SignerTestCase
import pkg_resources
from pyff import mdx
from mock import patch

__author__ = 'leifj'
Expand Down Expand Up @@ -45,25 +42,6 @@ def exec_pipeline(self, pstr):
def setUpClass(cls):
SignerTestCase.setUpClass()

def run_pyffd(self, *args):
def _mock_exit(n):
if n != 0:
raise ExitException(n)

filename = pkg_resources.resource_filename(__name__, '../mdx.py')
opts = list(args)
opts.insert(0, filename)
sys.argv = opts
orig_exit = sys.exit
sys.exit = _mock_exit
try:
exit_code = 0
mdx.main()
except ExitException, ex:
exit_code = ex.code
finally:
sys.exit = orig_exit

def setUp(self):
SignerTestCase.setUpClass()
print "setup called for PipeLineTest"
Expand All @@ -82,7 +60,27 @@ def write(self, data):
self.captured.append(data)
self.stream.write(data)

class ParseTest(PipeLineTest):
def parse_test(self):
self.output = tempfile.NamedTemporaryFile('w').name
with patch.multiple("sys", exit=self.sys_exit, stdout=StreamCapturing(sys.stdout), stderr=StreamCapturing(sys.stderr)):
from testfixtures import LogCapture
with LogCapture() as l:
res, md = self.exec_pipeline("""
- load:
- %s/metadata
- select
- stats
""" % self.datadir)
print sys.stdout.captured
print sys.stderr.captured
eIDs = [e.get('entityID') for e in md.store]
assert('https://idp.example.com/saml2/idp/metadata.php1' not in eIDs)
assert('https://idp.example.com/saml2/idp/metadata.php' in eIDs)
assert("removing 'https://idp.example.com/saml2/idp/metadata.php1': schema validation failed" in str(l))


# noinspection PyUnresolvedReferences
class SigningTest(PipeLineTest):
def test_signing(self):
self.output = tempfile.NamedTemporaryFile('w').name
Expand Down
2 changes: 2 additions & 0 deletions src/pyff/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ def entities_list(t=None):


def iter_entities(t):
if t is None:
return []
return t.iter('{%s}EntityDescriptor' % NS['md'])


Expand Down

0 comments on commit f0a8743

Please sign in to comment.