def testFileLoads(self): def _doTest(cfg, server, content, value): fullPath = os.path.join(cfg.entitlementDir, server) open(fullPath, "w").write(content) os.chmod(fullPath, 0644) rc = conarycfg.loadEntitlement(cfg.entitlementDir, server) assert (rc == value) os.unlink(fullPath) f = open(fullPath, "w") f.write("#!/bin/bash\n") f.write("cat <<EOFEOF\n") f.write(content) f.write("EOFEOF\n") f.close() os.chmod(fullPath, 0755) rc = conarycfg.loadEntitlement(cfg.entitlementDir, server) assert (rc == value) cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.entitlementDir = tempfile.mkdtemp() try: # test full-blown generated version generatedContent = conarycfg.emitEntitlement( 'localhost', 'customer', 'ABCD01234') _doTest(cfg, 'localhost', generatedContent, ('localhost', 'customer', 'ABCD01234')) # test hand-written file with entitlement tags _doTest( cfg, 'localhost', "<entitlement>" "<server>localhost</server><class>customer</class>" "<key>ABCD01234</key>\n" "</entitlement>\n", ('localhost', 'customer', 'ABCD01234')) # test hand-written file without entitlement tags _doTest( cfg, 'somehost', "<server>somehost</server><class>customer</class>" "<key>ABCD01234</key>\n", ('somehost', 'customer', 'ABCD01234')) # make sure a globbed entitlements gets loaded properly xml = conarycfg.emitEntitlement('*', key='ABCD01234') _doTest(cfg, 'localhost', xml, ('*', None, 'ABCD01234')) finally: shutil.rmtree(cfg.entitlementDir)
def testTimeoutParsing(self): xml = conarycfg.emitEntitlement('server', key = 'ABCD01234', retryOnTimeout = True, timeout = 60) ent = conarycfg.loadEntitlementFromString(xml, returnTimeout = True) assert(ent[3] == 60 and ent[4] is True) xml = conarycfg.emitEntitlement('server', key = 'ABCD01234') ent = conarycfg.loadEntitlementFromString(xml, returnTimeout = True) assert(ent[3] is None and ent[4] is True) xml = conarycfg.emitEntitlement('server', key = 'ABCD01234', timeout = 30) ent = conarycfg.loadEntitlementFromString(xml, returnTimeout = True) assert(ent[3] == 30 and ent[4] is True)
def testFileLoads(self): def _doTest(cfg, server, content, value): fullPath = os.path.join(cfg.entitlementDir, server) open(fullPath, "w").write(content) os.chmod(fullPath, 0644) rc = conarycfg.loadEntitlement(cfg.entitlementDir, server) assert(rc == value) os.unlink(fullPath) f = open(fullPath, "w") f.write("#!/bin/bash\n") f.write("cat <<EOFEOF\n") f.write(content) f.write("EOFEOF\n") f.close() os.chmod(fullPath, 0755) rc = conarycfg.loadEntitlement(cfg.entitlementDir, server) assert(rc == value) cfg = conarycfg.ConaryConfiguration(readConfigFiles=False) cfg.entitlementDir = tempfile.mkdtemp() try: # test full-blown generated version generatedContent = conarycfg.emitEntitlement('localhost', 'customer', 'ABCD01234') _doTest(cfg, 'localhost', generatedContent, ('localhost', 'customer', 'ABCD01234')) # test hand-written file with entitlement tags _doTest(cfg, 'localhost', "<entitlement>" "<server>localhost</server><class>customer</class>" "<key>ABCD01234</key>\n" "</entitlement>\n", ('localhost', 'customer', 'ABCD01234')) # test hand-written file without entitlement tags _doTest(cfg, 'somehost', "<server>somehost</server><class>customer</class>" "<key>ABCD01234</key>\n", ('somehost', 'customer', 'ABCD01234')) # make sure a globbed entitlements gets loaded properly xml = conarycfg.emitEntitlement('*', key = 'ABCD01234') _doTest(cfg, 'localhost', xml, ('*', None, 'ABCD01234')) finally: shutil.rmtree(cfg.entitlementDir)
def testParsing(self): withoutClass = ('<entitlement><server>localhost</server>' '<key>ABCD01234</key></entitlement>\n') assert(conarycfg.loadEntitlementFromString(withoutClass) == ('localhost', None, 'ABCD01234')) withoutClass = conarycfg.emitEntitlement('localhost', key = 'ABCD01234') assert(conarycfg.loadEntitlementFromString(withoutClass) == ('localhost', None, 'ABCD01234')) rc, s = self.captureOutput(conarycfg.loadEntitlementFromString, withoutClass, 'localhost', '<foo>') self.assertTrue('The serverName argument to loadEntitlementFromString has been deprecated' in s)
def testParsing(self): withoutClass = ('<entitlement><server>localhost</server>' '<key>ABCD01234</key></entitlement>\n') assert (conarycfg.loadEntitlementFromString(withoutClass) == ( 'localhost', None, 'ABCD01234')) withoutClass = conarycfg.emitEntitlement('localhost', key='ABCD01234') assert (conarycfg.loadEntitlementFromString(withoutClass) == ( 'localhost', None, 'ABCD01234')) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") conarycfg.loadEntitlementFromString(withoutClass, 'localhost', '<foo>') self.assertIn( 'The serverName argument to loadEntitlementFromString has been deprecated', w[-1].message)