Ejemplo n.º 1
0
    def test_resource_filename(self):
        assert (resource_filename("missing") is None)
        assert (resource_filename("missing", "gone") is None)
        assert (os.path.isdir(resource_filename('test')))
        assert (os.path.isfile(resource_filename('test/data/empty.txt')))
        assert (os.path.isdir(resource_filename('metadata', 'test/data')))
        assert (os.path.isfile(resource_filename('empty.txt', 'test/data')))
        assert (resource_filename(
            'empty.txt',
            'test/data') == resource_filename('test/data/empty.txt'))
        tmp = tempfile.NamedTemporaryFile('w').name
        with open(tmp, "w") as fd:
            fd.write("test")

        try:
            assert (resource_filename(tmp) == tmp)
            (d, fn) = os.path.split(tmp)
            assert (resource_filename(fn, d) == tmp)
        except IOError as ex:
            raise ex
        finally:
            try:
                os.unlink(tmp)
            except Exception:
                pass
Ejemplo n.º 2
0
 def setUp(self):
     self.md = MDRepository(store=MemoryStore)
     self.datadir = resource_filename('metadata', 'test/data')
     self.xml_source = os.path.join(self.datadir, 'test01.xml')
     self.swamid_source = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.swamid = root(parse_xml(self.swamid_source))
     self.t = parse_xml(self.xml_source)
     self.non_metadata = parse_xml(resource_filename("not-metadata.xml", self.datadir))
Ejemplo n.º 3
0
 def setUp(self):
     self.md = MDRepository(store=MemoryStore)
     self.datadir = resource_filename('metadata', 'test/data')
     self.xml_source = os.path.join(self.datadir, 'test01.xml')
     self.swamid_source = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.swamid = root(parse_xml(self.swamid_source))
     self.t = parse_xml(self.xml_source)
     self.non_metadata = parse_xml(resource_filename("not-metadata.xml", self.datadir))
Ejemplo n.º 4
0
    def test_store_and_retrieve(self):
        with patch.multiple("sys",
                            exit=self.sys_exit,
                            stdout=StreamCapturing(sys.stdout)):
            tmpdir = tempfile.mkdtemp()
            os.rmdir(tmpdir)  # lets make sure 'store' can recreate it
            try:
                self.exec_pipeline("""
- load:
   - file://%s/metadata/test01.xml
- select
- store:
   directory: %s
""" % (self.datadir, tmpdir))
                t1 = parse_xml(
                    resource_filename("metadata/test01.xml", self.datadir))
                assert t1 is not None
                entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
                sha1id = hash_id(entity_id, prefix=False)
                fn = "%s/%s.xml" % (tmpdir, sha1id)
                assert os.path.exists(fn)
                t2 = parse_xml(fn)
                assert t2 is not None
                assert root(t1).get('entityID') == root(t2).get('entityID')
                assert root(t2).get('entityID') == entity_id
            except IOError:
                raise Skip
            finally:
                shutil.rmtree(tmpdir)
Ejemplo n.º 5
0
    def test_store_and_retrieve(self):
        with patch.multiple("sys", exit=self.sys_exit, stdout=StreamCapturing(sys.stdout)):
            tmpdir = tempfile.mkdtemp()
            os.rmdir(tmpdir)  # lets make sure 'store' can recreate it
            try:
                self.exec_pipeline("""
- load:
   - file://%s/metadata/test01.xml
- select
- store:
   directory: %s
""" % (self.datadir, tmpdir))
                t1 = parse_xml(resource_filename("metadata/test01.xml", self.datadir))
                assert t1 is not None
                entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
                sha1id = hash_id(entity_id, prefix=False)
                fn = "%s/%s.xml" % (tmpdir, sha1id)
                assert os.path.exists(fn)
                t2 = parse_xml(fn)
                assert t2 is not None
                assert root(t1).get('entityID') == root(t2).get('entityID')
                assert root(t2).get('entityID') == entity_id
            except IOError:
                raise Skip
            finally:
                shutil.rmtree(tmpdir)
Ejemplo n.º 6
0
 def setUp(self):
     self.datadir = resource_filename('metadata', 'test/data')
     self.test01_source = os.path.join(self.datadir, 'test01.xml')
     self.test01 = parse_xml(self.test01_source)
     self.swamid_source = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.swamid = parse_xml(self.swamid_source)
     self.dir = tempfile.mkdtemp()
Ejemplo n.º 7
0
    def test_prune(self):
        tmpfile = tempfile.NamedTemporaryFile('w').name
        try:
            self.exec_pipeline(f"""
- load:
   - file://{self.datadir}/metadata/test01.xml
- select
- prune:
    - .//{{urn:oasis:names:tc:SAML:metadata:ui}}UIInfo
- publish: {tmpfile}
""")
            t1 = parse_xml(
                resource_filename("metadata/test01.xml", self.datadir))
            uiinfo = t1.find(".//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo")
            assert uiinfo is not None
            t2 = parse_xml(tmpfile)
            assert t2 is not None
            gone = t2.find(".//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo")
            assert gone is None
        except PipeException:
            pass
        except IOError:
            pass
        finally:
            try:
                os.unlink(tmpfile)
            except:
                pass
Ejemplo n.º 8
0
    def test_first_select_as(self):
        with patch.multiple("sys", exit=self.sys_exit, stdout=StreamCapturing(sys.stdout)):
            tmpfile = tempfile.NamedTemporaryFile('w').name
            try:
                self.exec_pipeline("""
- load:
   - file://%s/metadata/test01.xml
- select as FOO
- first
- publish: %s
""" % (self.datadir, tmpfile))
                t1 = parse_xml(resource_filename("metadata/test01.xml", self.datadir))
                assert t1 is not None
                entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
                t2 = parse_xml(tmpfile)
                assert t2 is not None
                assert root(t1).get('entityID') == root(t2).get('entityID')
                assert root(t2).get('entityID') == entity_id
            except PipeException:
                pass
            except IOError:
                raise Skip
            finally:
                try:
                    os.unlink(tmpfile)
                except:
                    pass
Ejemplo n.º 9
0
    def test_store_and_retrieve(self):
        tmpdir = tempfile.mkdtemp()
        os.rmdir(tmpdir)  # lets make sure 'store' can recreate it
        try:
            self.exec_pipeline(f"""
- load:
   - file://{self.datadir}/metadata/test01.xml
- select
- store:
   directory: {tmpdir}
""")
            t1 = parse_xml(
                resource_filename("metadata/test01.xml", self.datadir))
            assert t1 is not None
            entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
            sha1id = hash_id(entity_id, prefix=False)
            fn = f"{tmpdir}/{sha1id}.xml"
            assert os.path.exists(fn)
            t2 = parse_xml(fn)
            assert t2 is not None
            assert root(t1).get('entityID') == root(t2).get('entityID')
            assert root(t2).get('entityID') == entity_id
        except IOError:
            pass
        finally:
            shutil.rmtree(tmpdir)
Ejemplo n.º 10
0
    def test_prune(self):
        with patch.multiple("sys", exit=self.sys_exit, stdout=StreamCapturing(sys.stdout)):
            tmpfile = tempfile.NamedTemporaryFile('w').name
            try:
                self.exec_pipeline("""
- load:
   - file://%s/metadata/test01.xml
- select
- prune:
    - .//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo
- publish: %s
""" % (self.datadir, tmpfile))
                t1 = parse_xml(resource_filename("metadata/test01.xml", self.datadir))
                uiinfo = t1.find(".//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo")
                assert uiinfo is not None
                t2 = parse_xml(tmpfile)
                assert t2 is not None
                gone = t2.find(".//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo")
                assert gone is None
            except PipeException:
                pass
            except IOError:
                raise Skip
            finally:
                try:
                    os.unlink(tmpfile)
                except:
                    pass
Ejemplo n.º 11
0
    def test_first_select_as(self):
        tmpfile = tempfile.NamedTemporaryFile('w').name
        try:
            self.exec_pipeline(f"""
- load:
   - file://{self.datadir}/metadata/test01.xml
- select as FOO:
- first
- publish: {tmpfile}
""")
            t1 = parse_xml(
                resource_filename("metadata/test01.xml", self.datadir))
            assert t1 is not None
            entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
            t2 = parse_xml(tmpfile)
            assert t2 is not None
            assert root(t1).get('entityID') == root(t2).get('entityID')
            assert root(t2).get('entityID') == entity_id
        except PipeException:
            pass
        except IOError:
            pass
        finally:
            try:
                os.unlink(tmpfile)
            except (IOError, OSError):
                pass
Ejemplo n.º 12
0
    def test_prune(self):
        with patch.multiple("sys",
                            exit=self.sys_exit,
                            stdout=StreamCapturing(sys.stdout)):
            tmpfile = tempfile.NamedTemporaryFile('w').name
            try:
                self.exec_pipeline("""
- load:
   - file://%s/metadata/test01.xml
- select
- prune:
    - .//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo
- publish: %s
""" % (self.datadir, tmpfile))
                t1 = parse_xml(
                    resource_filename("metadata/test01.xml", self.datadir))
                uiinfo = t1.find(
                    ".//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo")
                assert uiinfo is not None
                t2 = parse_xml(tmpfile)
                assert t2 is not None
                gone = t2.find(
                    ".//{urn:oasis:names:tc:SAML:metadata:ui}UIInfo")
                assert gone is None
            except PipeException:
                pass
            except IOError:
                raise Skip
            finally:
                try:
                    os.unlink(tmpfile)
                except:
                    pass
Ejemplo n.º 13
0
    def test_first_select_as(self):
        with patch.multiple("sys",
                            exit=self.sys_exit,
                            stdout=StreamCapturing(sys.stdout)):
            tmpfile = tempfile.NamedTemporaryFile('w').name
            try:
                self.exec_pipeline("""
- load:
   - file://%s/metadata/test01.xml
- select as FOO
- first
- publish: %s
""" % (self.datadir, tmpfile))
                t1 = parse_xml(
                    resource_filename("metadata/test01.xml", self.datadir))
                assert t1 is not None
                entity_id = 'https://idp.example.com/saml2/idp/metadata.php'
                t2 = parse_xml(tmpfile)
                assert t2 is not None
                assert root(t1).get('entityID') == root(t2).get('entityID')
                assert root(t2).get('entityID') == entity_id
            except PipeException:
                pass
            except IOError:
                raise Skip
            finally:
                try:
                    os.unlink(tmpfile)
                except:
                    pass
Ejemplo n.º 14
0
 def setUp(self):
     self.datadir = resource_filename('metadata', 'test/data')
     self.test01_source = os.path.join(self.datadir, 'test01.xml')
     self.test01 = parse_xml(self.test01_source)
     self.swamid_source = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.swamid = parse_xml(self.swamid_source)
     self.wayf_source = os.path.join(self.datadir, 'wayf-edugain-metadata.xml')
     self.wayf = parse_xml(self.wayf_source)
Ejemplo n.º 15
0
    def test_resource_filename(self):
        assert(resource_filename("missing") is None)
        assert(resource_filename("missing", "gone") is None)
        assert(os.path.isdir(resource_filename('test')))
        assert(os.path.isfile(resource_filename('test/data/empty.txt')))
        assert(os.path.isdir(resource_filename('metadata', 'test/data')))
        assert(os.path.isfile(resource_filename('empty.txt', 'test/data')))
        assert(resource_filename('empty.txt', 'test/data') == resource_filename('test/data/empty.txt'))
        tmp = tempfile.NamedTemporaryFile('w').name
        with open(tmp, "w") as fd:
            fd.write("test")

        try:
            assert(resource_filename(tmp) == tmp)
            (d, fn) = os.path.split(tmp)
            assert(resource_filename(fn, d) == tmp)
        except IOError, ex:
            raise ex
Ejemplo n.º 16
0
 def setUp(self):
     self.datadir = resource_filename('metadata', 'test/data')
     self.test01_source = os.path.join(self.datadir, 'test01.xml')
     self.test01 = parse_xml(self.test01_source)
     self.swamid_source = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.swamid = parse_xml(self.swamid_source)
Ejemplo n.º 17
0
 def setUp(self):
     self.datadir = resource_filename('metadata', 'test/data')
     self.xml_source1 = os.path.join(self.datadir, 'test01.xml')
     self.xml_source2 = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.t1 = parse_xml(self.xml_source1)
     self.t2 = parse_xml(self.xml_source2)
Ejemplo n.º 18
0
 def setUp(self):
     self.datadir = resource_filename('metadata', 'test/data')
     self.xml_source1 = os.path.join(self.datadir, 'test01.xml')
     self.xml_source2 = os.path.join(self.datadir, 'swamid-2.0-test.xml')
     self.t1 = parse_xml(self.xml_source1)
     self.t2 = parse_xml(self.xml_source2)
Ejemplo n.º 19
0
 def setUp(self):
     self.imagedir = resource_filename('images', 'test/data')
     self.files = [fn for fn in find_matching_files(self.imagedir, ['png', 'gif', 'jpeg', 'jpg', 'ico', 'svg'])]