Ejemplo n.º 1
0
    def _compileQuery(self, name, queryString, args=None):
        p = self.rep.findPath('//Queries')
        k = self.rep.findPath('//Schema/Core/Query')
        q = Query.Query(name, p, k, queryString)
        if args is not None:
            q.args = args
#        q.compile()
        return q
Ejemplo n.º 2
0
 def testWhereVariableQuery(self):
     """ Test using a variable in the where clause """
     queryString = 'for i in "//Schema/Core/Kind" where contains(i.itsName,$0)'
     import repository.query.Query as Query
     p = self.rep.findPath('//Queries')
     k = self.rep.findPath('//Schema/Core/Query')
     q = Query.Query('testWhereQuery', p, k, queryString)
     pattern = 'arc'
     q.args["$0"] = (pattern, )  # one item tuple
     self._checkQuery(lambda i: not pattern in i.itsName, q)
Ejemplo n.º 3
0
 def testResetQueryString(self):
     """ Make sure we can change the query string and still get an answer"""
     import repository.query.Query as Query
     p = self.rep.findPath('//Queries')
     k = self.rep.findPath('//Schema/Core/Query')
     q = Query.Query('testResetQuery', p, k)
     self.assert_(len([i for i in q]) == 0)
     q.queryString = 'for i in "//Schema/Core/Kind" where True'
     self.assert_(len([i for i in q]) == 17)
     q.queryString = 'for i in "//Schema/Core/Kind" where contains(i.itsName,"o")'
     self.assert_(len([i for i in q]) == 6)
Ejemplo n.º 4
0
def _allCertificatesQuery(repView):
    qName = 'allCertificatesQuery'
    q = repView.findPath('//Queries/%s' % (qName))
    if q is None:
        p = repView.findPath('//Queries')
        k = repView.findPath('//Schema/Core/Query')
        q = Query.Query(qName, p, k, ALL_CERTS_QUERY)
        notificationItem = repView.findPath(
            '//parcels/osaf/framework/certstore/dummyCertNotification')
        q.subscribe(notificationItem, 'handle', True, True)

    return q
Ejemplo n.º 5
0
    def testRefCollectionQuery(self):
        """ Test a query over ref collections """
        import repository.query.Query as Query
        kind = self.rep.findPath('//Schema/Core/Kind')

        queryString = u"for i in $0 where contains(i.itsName,'ttributes')"
        p = self.rep.findPath('//Queries')
        k = self.rep.findPath('//Schema/Core/Query')
        q = Query.Query('testRefCollctionQuery', p, k, queryString)
        q.args["$0"] = (kind.itsUUID, "attributes")

        self._checkQuery(lambda i: not 'ttributes' in i.itsName, q)
Ejemplo n.º 6
0
    def findUID(self, uid):
        view = self.itsView
        queryString='union(for i in "%s" where i.icalUID == $0, \
                           for i in "%s" where i.icalUID == $0)'                                                                 % \
                           (self._calendarEventPath, self._taskPath)
        p = view.findPath('//Queries')
        k = view.findPath('//Schema/Core/Query')
        q = Query.Query(None, p, k, queryString)

        q.args["$0"] = (uid, )
        for match in q:
            return match.getMaster()
        return None
Ejemplo n.º 7
0
    def testReloadQuery(self):
        """ Test to see that we can reload a query and it's result set from the store without recomputing the query contents """
        import repository.query.Query as Query
        p = self.rep.findPath('//Queries')
        k = self.rep.findPath('//Schema/Core/Query')
        q = Query.Query('testResetQuery', p, k,
                        'for i in "//Schema/Core/Kind" where True')
        self.assert_(len([i for i in q]) == 17)
        self.rep.check()
        self.rep.commit()
        uuid = q.itsUUID

        self._reopenRepository()
        q1 = self.rep.findUUID(uuid)
        self.assert_(len([i for i in q1]) == 17)
Ejemplo n.º 8
0
 def sharedWebDAVCollections (self):
     # return the list of all the shared collections
     # @@@DLD - use new query, once it can handle method calls, or when our item.isShared
     #  attribute is correctly set.
     UseNewQuery = False
     if UseNewQuery:
         qString = u"for i in '//parcels/osaf/pim/ItemCollection' where len (i.sharedURL) > 0"
         collQuery = Query.Query (self.itsView.repository, qString)
         collQuery.recursive = False
         collections = list(collQuery)
     else:
         collections = [
             coll for coll in ItemCollection.iterItems(self.itsView)
                  if Sharing.isShared(coll)
         ]
     return collections
Ejemplo n.º 9
0
    def testCopyQuery(self):
        """ Test to see that we can copy a query """
        import repository.query.Query as Query
        p = self.rep.findPath('//Queries')
        k = self.rep.findPath('//Schema/Core/Query')
        q = Query.Query('testCopyQuery', p, k,
                        'for i in "//Schema/Core/Kind" where True')
        self.assert_(len([i for i in q]) == 17)

        c = q.copy('testCopyQuery1')
        self.assert_(len([i for i in c]) == 17)
        self.assert_(c is not q)
        for i in q:
            if i not in c:
                self.fail()
        self.assert_(True)
Ejemplo n.º 10
0
    def _importAndFind(self, pem, trust):
        x509 = X509.load_cert_string(pem)
        fingerprint = certificate._fingerprint(x509)
        certificate._importCertificate(x509, fingerprint, trust, self.rep.view)

        qString = u'for i in "//parcels/osaf/framework/certstore/Certificate" where i.fingerprint == "%s"' % fingerprint

        qName = 'fpCertQuery' + fingerprint
        q = self.rep.view.findPath('//Queries/%s' % (qName))
        if q is None:
            p = self.rep.view.findPath('//Queries')
            k = self.rep.view.findPath('//Schema/Core/Query')
            q = Query.Query(qName, p, k, qString)

        assert len(q) == 1

        for cert in q:  #q[0] does not seem to work
            return cert
Ejemplo n.º 11
0
def addCertificates(repView, ctx):
    """
    Add certificates to SSL Context.
    
    @param repView: repository view
    @param ctx: SSL.Context
    """
    
    qName = 'sslCertificateQuery'
    q = repView.findPath('//Queries/%s' %(qName))
    if q is None:
        p = repView.findPath('//Queries')
        k = repView.findPath('//Schema/Core/Query')
        q = Query.Query(qName, p, k, u'for i in "//parcels/osaf/framework/certstore/Certificate" where i.type == "root" and i.trust == %d' % (certificate.TRUST_AUTHENTICITY | certificate.TRUST_SITE))
        notificationItem = repView.findPath('//parcels/osaf/framework/certstore/dummyCertNotification')
        q.subscribe(notificationItem, 'handle', True, True)
        
    store = ctx.get_cert_store()
    for cert in q:
        store.add_x509(cert.asX509())
Ejemplo n.º 12
0
def _importCertificate(x509, fingerprint, trust, repView):
    pem = x509.as_pem()
    if _isInRepository(repView, pem):
        raise ValueError, 'X.509 certificate is already in the repository'

    subjectCommonName = x509.get_subject().CN
    asText = x509.as_text()

    type = _certificateType(x509)
    if type == 'root':
        if not x509.verify():
            raise ValueError, 'X.509 certificate does not verify'

    cert = Certificate(view=repView)
    text = cert.getAttributeAspect('pem', 'type').makeValue(pem,
                                                            compression=None)
    cert.pem = text
    text = cert.getAttributeAspect('asText', 'type').makeValue(asText)
    cert.asText = text
    cert.type = type
    cert.trust = trust
    cert.fingerprintAlgorithm = 'sha1'
    cert.fingerprint = fingerprint
    cert.subjectCommonName = subjectCommonName

    qName = TRUSTED_SITE_CERTS_QUERY_NAME
    q = repView.findPath('//Queries/%s' % (qName))
    if q is None:
        p = repView.findPath('//Queries')
        k = repView.findPath('//Schema/Core/Query')
        q = Query.Query(
            qName, p, k,
            u'for i in "//parcels/osaf/framework/certstore/Certificate" where i.type == "site" and i.trust == %d'
            % (TRUST_AUTHENTICITY))
        notificationItem = repView.findPath(
            '//parcels/osaf/framework/certstore/dummyCertNotification')
        q.subscribe(notificationItem, 'handle', True, True)

    repView.commit()
Ejemplo n.º 13
0
    def disabled_testPreloadedCertificates(self):
        # XXX This test does not work right, verify fails in certain situations
        self.loadParcel("parcel:osaf.framework.certstore.data")

        qString = u'for i in "//parcels/osaf/framework/certstore/Certificate" where i.type == "root"'

        qName = 'rootCertsQuery'
        q = self.rep.view.findPath('//Queries/%s' % (qName))
        if q is None:
            p = self.rep.view.findPath('//Queries')
            k = self.rep.view.findPath('//Schema/Core/Query')
            q = Query.Query(qName, p, k, qString)

        now = time.gmtime()
        format = '%b %d %H:%M:%S %Y %Z'

        for cert in q:
            print cert.subjectCommonName
            x509 = cert.asX509()
            self.assertTrue(x509.verify())

            # verify() should have caught bad times, but just in case:
            before = x509.get_not_before()
            after = x509.get_not_after()
            try:
                assert time.strptime(str(before), format) < now, before
                assert now < time.strptime(str(after), format), after
            except ValueError:
                raise ValueError, 'bad time value in ' + cert.subjectCommonName

            self.assertTrue(len(cert.subjectCommonName) > 0)
            self.assertTrue(cert.type == 'root')
            self.assertTrue(cert.trust == certificate.TRUST_AUTHENTICITY
                            | certificate.TRUST_SITE)
            self.assertTrue(cert.fingerprintAlgorithm == 'sha1')
            self.assertTrue(len(cert.fingerprint) > 3)
            self.assertTrue(cert.asTextAsString()[:12] == 'Certificate:')