def test_exposed_fk(self): # see # http://stackoverflow.com/questions/3296040/why-arent-my-sqlite3-foreign-keys-working fk_version = params.ProductToken('sqlite', '3.6.19') sqlite_version = params.ProductToken('sqlite', sqlite3.sqlite_version) if sqlite_version < fk_version: skip_fk = True logging.warning( "SQLite Foreign Key support not available in sqlite %s", str(sqlite_version)) else: skip_fk = False self.db.create_all_tables() files = self.container['Files'] blobs = self.container['Blobs'] with files.OpenCollection() as file_coll: with blobs.OpenCollection() as blob_coll: f = file_coll.new_entity() f['path'].set_from_value("hello.txt") f['mime']['type'].set_from_value("text") f['mime']['subtype'].set_from_value("plain") f['hash'].set_from_value("deadbeef") try: file_coll.insert_entity(f) if not skip_fk: self.fail("Insert FK with invalid value succeeded") else: # clean up after fk failure del file_coll[f.key()] f.exists = False except edm.ConstraintError: pass f['hash'].set_null() file_coll.insert_entity(f) f2 = file_coll["hello.txt"] self.assertTrue(f2['path'].value == "hello.txt") self.assertTrue(f2['mime']['subtype'].value == "plain") self.assertFalse(f2['hash'], "Readonly attribute NULL on insert") b = blob_coll.new_entity() b['hash'].set_from_value('deadbeef') b['data'].set_from_value('The quick brown fox jumped over...') f2['Blob'].BindEntity(b) with f2['Blob'].OpenCollection() as nav_coll: self.assertTrue(len(nav_coll) == 0) nav_coll.insert_entity(b) self.assertTrue(len(nav_coll) == 1) f3 = file_coll["hello.txt"] self.assertTrue(f3['hash'].value == 'deadbeef', "Exposed fk attribute non-Null after link")
def test_upgrade(self): """From RFC2616: the upgrade keyword MUST be supplied within a Connection header field (section 14.10) whenever Upgrade is present in an HTTP/1.1 message""" req = Request() req.set_header("Upgrade", "HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11") protocols = req.get_upgrade() self.assertTrue(isinstance(protocols, list)) self.assertTrue(len(protocols) == 4) for p in protocols: self.assertTrue(isinstance(p, params.ProductToken)) req = Request() req.set_upgrade([ params.ProductToken("HTTP", "2.0"), params.ProductToken("SHTTP", "1.3") ]) self.assertTrue(req.get_header("Upgrade") == b"HTTP/2.0, SHTTP/1.3") self.assertTrue("upgrade" in req.get_connection())
def test_upgrade(self): request = http.ClientRequest("http://www.domain9.com/socket") request.set_upgrade([params.ProductToken("happy")]) self.client.process_request(request) self.assertTrue(request.status == 101) try: self.assertTrue(isinstance(request.send_pipe, Pipe)) self.assertTrue(isinstance(request.recv_pipe, Pipe)) request.send_pipe.write(b'hello\r\n') request.send_pipe.write_eof() output = request.recv_pipe.read() self.assertTrue(output == b'hello\r\n', "Failed echo test on upgrade: %s" % str(output)) finally: request.recv_pipe.close()
def run_domain9(self, sock): while True: # simulates a server that supports upgrade to happy req = sock.recv_request() if req is None: break connection = req.get_connection() if "upgrade" in connection: response = messages.Response(req) response.set_status(101) response.set_upgrade([params.ProductToken("happy")]) sock.send_response(response) logging.debug("Switching to happy protocol") input = sock.send_pipe.readmatch() sock.recv_pipe.write(input) sock.recv_pipe.write_eof() else: response = messages.Response(req) response.set_status(400, "Test failed for domain9") sock.send_response(response) sock.mock_shutdown(socket.SHUT_RDWR) break