def setUp(self): BaseTest.setUp(self) stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream)
def setUp(self): BaseTest.setUp(self) self.config.handler.allow_downloads = True self.config.key_info_server = 'http://localhost:3333/key-info' self.config.fetcher = fetch.Fetcher(self.config) child_config = config.Config() child_config.key_info_server = 'http://localhost:3333/key-info' child_config.save_globals() stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) stream.close() trust.trust_db.watchers = [] helpers.get_selections_gui = raise_gui global ran_gui ran_gui = False global traced_downloads traced_downloads = []
def setUp(self): BaseTest.setUp(self) stream = tempfile.TemporaryFile(mode = 'w+b') stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) stream.close()
def testTimes(self): iface_cache = self.config.iface_cache with tempfile.TemporaryFile() as stream: stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) upstream_dir = basedir.save_cache_path(config_site, 'interfaces') cached = os.path.join(upstream_dir, model.escape('http://foo')) with open(cached, 'wb') as stream: stream.write(data.foo_signed_xml) signed = iface_cache._get_signature_date('http://foo') assert signed == None trust.trust_db.trust_key( '92429807C9853C0744A68B9AAE07828059A53CC1') signed = iface_cache._get_signature_date('http://foo') self.assertEqual(1154850229, signed) with open(cached, 'w+b') as stream: stream.seek(0) stream.write(b'Hello') # When the signature is invalid, we just return None. # This is because versions < 0.22 used to corrupt the signatue # by adding an attribute to the XML signed = iface_cache._get_signature_date('http://foo') assert signed == None
def setUp(self): BaseTest.setUp(self) with tempfile.TemporaryFile(mode="w+b") as stream: stream.write(thomas_key) stream.seek(0) gpg.import_key(stream) warnings.filterwarnings("ignore", category=DeprecationWarning)
def setUp(self): BaseTest.setUp(self) with tempfile.TemporaryFile(mode = 'w+b') as stream: stream.write(thomas_key) stream.seek(0) gpg.import_key(stream) trust.trust_db.trust_key(THOMAS_FINGERPRINT) warnings.filterwarnings("ignore", category = DeprecationWarning)
def setUp(self): BaseTest.setUp(self) stream = tempfile.TemporaryFile() stream.write(thomas_key) stream.seek(0) gpg.import_key(stream) trust.trust_db.trust_key(THOMAS_FINGERPRINT) warnings.filterwarnings("ignore", category = DeprecationWarning)
def testImportBad(self): with tempfile.TemporaryFile(mode="w+b") as stream: stream.write(b"Bad key") stream.seek(0) try: gpg.import_key(stream) assert False except model.SafeException: pass # OK
def testImportBad(self): with tempfile.TemporaryFile(mode = 'w+b') as stream: stream.write(b"Bad key") stream.seek(0) try: gpg.import_key(stream) assert False except model.SafeException: pass # OK
def testXMLupdate(self): iface_cache = self.config.iface_cache trust.trust_db.trust_key( '92429807C9853C0744A68B9AAE07828059A53CC1') with tempfile.TemporaryFile() as stream: stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) iface = iface_cache.get_interface('http://foo') with tempfile.TemporaryFile() as src: src.write(data.foo_signed_xml) src.seek(0) pending = PendingFeed(iface.uri, src) assert iface_cache.update_feed_if_trusted(iface.uri, pending.sigs, pending.new_xml) iface_cache.__init__() feed = iface_cache.get_feed('http://foo') assert feed.last_modified == 1154850229 # mtimes are unreliable because copying often changes them - # check that we extract the time from the signature when upgrading upstream_dir = basedir.save_cache_path(config_site, 'interfaces') cached = os.path.join(upstream_dir, model.escape(feed.url)) os.utime(cached, None) iface_cache.__init__() feed = iface_cache.get_feed('http://foo') assert feed.last_modified > 1154850229 with tempfile.TemporaryFile() as src: src.write(data.new_foo_signed_xml) src.seek(0) pending = PendingFeed(feed.url, src) old_stdout = sys.stdout sys.stdout = StringIO() try: assert iface_cache.update_feed_if_trusted(feed.url, pending.sigs, pending.new_xml, dry_run = True) finally: sys.stdout = old_stdout assert iface_cache.update_feed_if_trusted(feed.url, pending.sigs, pending.new_xml) # Can't 'update' to an older copy with tempfile.TemporaryFile() as src: src.write(data.foo_signed_xml) src.seek(0) try: pending = PendingFeed(feed.url, src) assert iface_cache.update_feed_if_trusted(feed.url, pending.sigs, pending.new_xml) assert 0 except model.SafeException: pass
def testImport(self): out, err = self.run_0install(['import']) assert out.lower().startswith("usage:") assert 'FEED' in out stream = open('6FCF121BE2390E0B.gpg') gpg.import_key(stream) stream.close() sys.stdin = Reply('Y\n') out, err = self.run_0install(['import', 'Hello.xml']) assert not out, out assert 'Trusting DE937DD411906ACF7C263B396FCF121BE2390E0B for example.com:8000' in err, out
def testImport(self): out, err = self.run_0install(["import"]) assert out.lower().startswith("usage:") assert "FEED" in out stream = open("6FCF121BE2390E0B.gpg") gpg.import_key(stream) stream.close() sys.stdin = Reply("Y\n") out, err = self.run_0install(["import", "Hello.xml"]) assert not out, out assert "Trusting DE937DD411906ACF7C263B396FCF121BE2390E0B for example.com:8000" in err, out
def setUp(self): BaseTest.setUp(self) self.config.handler.allow_downloads = True self.config.fetcher = fetch.Fetcher(self.config.handler) stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) self.child = None trust.trust_db.watchers = []
def testXMLupdate(self): iface_cache = self.config.iface_cache trust.trust_db.trust_key('92429807C9853C0744A68B9AAE07828059A53CC1') stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) iface = iface_cache.get_interface('http://foo') src = tempfile.TemporaryFile() src.write(data.foo_signed_xml) src.seek(0) pending = PendingFeed(iface.uri, src) assert iface_cache.update_feed_if_trusted(iface.uri, pending.sigs, pending.new_xml) iface_cache.__init__() feed = iface_cache.get_feed('http://foo') assert feed.last_modified == 1154850229 # mtimes are unreliable because copying often changes them - # check that we extract the time from the signature when upgrading upstream_dir = basedir.save_cache_path(config_site, 'interfaces') cached = os.path.join(upstream_dir, model.escape(feed.url)) os.utime(cached, None) iface_cache.__init__() feed = iface_cache.get_feed('http://foo') assert feed.last_modified > 1154850229 src = tempfile.TemporaryFile() src.write(data.new_foo_signed_xml) src.seek(0) pending = PendingFeed(feed.url, src) assert iface_cache.update_feed_if_trusted(feed.url, pending.sigs, pending.new_xml) # Can't 'update' to an older copy src = tempfile.TemporaryFile() src.write(data.foo_signed_xml) src.seek(0) try: pending = PendingFeed(feed.url, src) assert iface_cache.update_feed_if_trusted(feed.url, pending.sigs, pending.new_xml) assert 0 except model.SafeException: pass
def setUp(self): BaseTest.setUp(self) self.config.handler.allow_downloads = True self.config.key_info_server = 'http://localhost:3333/key-info' self.config.fetcher = fetch.Fetcher(self.config) stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) self.child = None trust.trust_db.watchers = []
def setUp(self): BaseTest.setUp(self) self.config.handler.allow_downloads = True self.config.key_info_server = 'http://localhost:3333/key-info' self.config.fetcher = fetch.Fetcher(self.config) stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) stream.close() trust.trust_db.watchers = []
def _downloaded_key(self, stream): import shutil, tempfile from zeroinstall.injector import gpg info(_("Importing key for feed '%s'"), self.url) # Python2.4: can't call fileno() on stream, so save to tmp file instead tmpfile = tempfile.TemporaryFile(prefix='injector-dl-data-') try: shutil.copyfileobj(stream, tmpfile) tmpfile.flush() tmpfile.seek(0) gpg.import_key(tmpfile) finally: tmpfile.close()
def _downloaded_key(self, stream): import shutil, tempfile from zeroinstall.injector import gpg info(_("Importing key for feed '%s'"), self.url) # Python2.4: can't call fileno() on stream, so save to tmp file instead tmpfile = tempfile.TemporaryFile(prefix = 'injector-dl-data-') try: shutil.copyfileobj(stream, tmpfile) tmpfile.flush() tmpfile.seek(0) gpg.import_key(tmpfile) finally: tmpfile.close()
def testImport(self): child_config = config.Config() child_config.auto_approve_keys = False child_config.key_info_server = None child_config.save_globals() out, err = self.run_ocaml(['import']) assert out.lower().startswith("usage:") assert 'FEED' in out stream = open('6FCF121BE2390E0B.gpg') gpg.import_key(stream) stream.close() out, err = self.run_ocaml(['import', '-v', 'Hello.xml'], stdin = 'Y\n') assert not out, out assert 'Trusting DE937DD411906ACF7C263B396FCF121BE2390E0B for example.com:8000' in err, err
def setUp(self): BaseTest.setUp(self) background._detach = lambda: False self.config.handler.allow_downloads = True self.config.key_info_server = 'http://localhost:3333/key-info' self.config.fetcher = fetch.Fetcher(self.config) stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) stream.close() trust.trust_db.watchers = [] helpers.get_selections_gui = raise_gui global ran_gui ran_gui = False
def testCheckSigned(self): iface_cache = self.config.iface_cache trust.trust_db.trust_key( '92429807C9853C0744A68B9AAE07828059A53CC1') feed_url = 'http://foo' src = tempfile.TemporaryFile() # Unsigned src.write("hello") src.flush() src.seek(0) try: PendingFeed(feed_url, src) assert 0 except model.SafeException: pass stream = tempfile.TemporaryFile() stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) # Signed src.seek(0) src.write(data.foo_signed_xml) src.flush() src.seek(0) pending = PendingFeed(feed_url, src) assert iface_cache.update_feed_if_trusted(feed_url, pending.sigs, pending.new_xml) self.assertEquals(['http://foo'], iface_cache.list_all_interfaces()) feed = iface_cache.get_feed(feed_url) self.assertEquals(1154850229, feed.last_modified)
def testCheckSigned(self): iface_cache = self.config.iface_cache trust.trust_db.trust_key( '92429807C9853C0744A68B9AAE07828059A53CC1') feed_url = 'http://foo' with tempfile.TemporaryFile(mode = 'w+b') as src: # Unsigned src.write(b"hello") src.flush() src.seek(0) try: PendingFeed(feed_url, src) assert 0 except model.SafeException: pass with tempfile.TemporaryFile(mode = 'w+b') as stream: stream.write(data.thomas_key) stream.seek(0) gpg.import_key(stream) # Signed src.seek(0) src.write(data.foo_signed_xml) src.flush() src.seek(0) pending = PendingFeed(feed_url, src) assert iface_cache.update_feed_if_trusted(feed_url, pending.sigs, pending.new_xml) self.assertEqual(['http://foo'], iface_cache.list_all_interfaces()) feed = iface_cache.get_feed(feed_url) self.assertEqual(1154850229, feed.last_modified)