Esempio n. 1
0
	def test_decodeFailedTrailingGarbage(self):
		"""
		If L{HelloFrame} has trailing garbage 'x' after the JSON,
		L{InvalidHello} is raised.
		"""
		s = _makeHelloFrame().encode()[:-1] + 'x' + 'H'
		self.assertRaises(InvalidHello, lambda: HelloFrame.decode(sf(s)))
Esempio n. 2
0
	def test_wantsStrings(self):
		s = _makeHelloFrame()
		self.assertEqual(False, s.wantsStrings())
		s.succeedsTransport = None
		self.assertEqual(True, s.wantsStrings())
		s.succeedsTransport = 3
		self.assertEqual(True, s.wantsStrings())
		del s.succeedsTransport
		self.assertEqual(False, s.wantsStrings())
Esempio n. 3
0
	def test_decodeFailed_nan_inf_neginf(self):
		"""
		If L{HelloFrame} contains NaN, Infinity, or -Infinity,
		L{InvalidHello} is raised.
		"""
		for bad in (float('nan'), float('inf'), float('-inf')):
			hello = _makeHelloFrame(dict(transportNumber=bad))
			s = simplejson.dumps(dict(hello._yieldMapping()))
			self.assertRaises(InvalidHello, lambda: HelloFrame.decode(sf(s)))
Esempio n. 4
0
	def test_decodeFailedInvalidValues(self):
		"""
		If L{HelloFrame} contains invalid values for various properties,
		L{InvalidHello} is raised.
		"""
		def listWithout(oldList, without):
			arr = oldList[:]
			for w in without:
				arr.remove(w)
			return arr

		genericBad = [
			-2**65, -1, -0.5, 0.5, 2**53+1, "", [], ["something"],
			{}, True, False, None]

		badMutations = dict(
			transportNumber=[DeleteProperty] + genericBad,
			protocolVersion=[DeleteProperty, 0, 1, "1", 1.001] + genericBad,
			streamId=[
				DeleteProperty, '', '\x00', 'x'*1, u'\ucccc'*25, u'\ucccc'*8,
				u'\x80'*25, 'x'*19, 'x'*31, 'x'*3000] + genericBad, # 19 is below limit, 31 is over limit
			httpFormat=[4, 1, 0] + genericBad,
			streamingResponse=[2, 3] + listWithout(genericBad, [True, False]),
			maxReceiveBytes=genericBad,
			maxOpenTime=genericBad,
			maxInactivity=[None, 0.5, 1.5, 601],
			# We can pass either a string or a SACK
			sack=['', '|', SACK(-2, ()), SACK(-1, (-2,))],
			lastSackSeenByClient=[DeleteProperty, '', '|', SACK(-2, ()), SACK(-1, (-2,))],
		)
		##print badMutations

		ran = 0

		for mutateProperty, mutateValues in badMutations.iteritems():
			for value in mutateValues:
				badHello = _makeHelloFrame()
				if value is not DeleteProperty:
					setattr(badHello, mutateProperty, value)
				else:
					try:
						delattr(badHello, mutateProperty)
					except AttributeError:
						 # It wasn't there in the first place.
						pass

				##print badHello
				s = badHello.encode()
				self.assertRaises(InvalidHello, lambda: HelloFrame.decode(sf(s)))

				ran += 1

		# sanity check; make sure we actually tested things
		assert ran == 116, "Ran %d times; change this assert as needed" % (ran,)
Esempio n. 5
0
	def test_decodeFailedBadEedsArgument(self):
		"""
		A too-low or too-high transport number (or a wrong type) for the 'eeds'
		argument causes L{InvalidHello} to be raised.
		In this case, the stream is never registered with the streamTracker.
		"""
		for succeedsTransport in [-1, -2**32, -0.5, 2**53+1, "4", True, False, [], {}]:
			s = _makeHelloFrame(dict(
				succeedsTransport=succeedsTransport)).encode()

			self.assertRaises(InvalidHello, lambda: HelloFrame.decode(sf(s)))
Esempio n. 6
0
	def test_encodeDecodeEquality(self):
		# Need to make some options explicit for equality to work
		hello = _makeHelloFrame(dict(
			httpFormat=FORMAT_XHR,
			# for equality in JS, need boolean instead of number.  Do the
			# same here for consistency.
			requestNewStream=True,
			streamingResponse=True,
			needPaddingBytes=0,
			maxInactivity=1,
			sack=SACK(-1, ())))
		encodedDecodedHello = HelloFrame.decode(sf(hello.encode()))
		self.assertEqual(hello, encodedDecodedHello)
Esempio n. 7
0
	def test_decode(self):
		s = _makeHelloFrame().encode()
		self.assertEqual(
			HelloFrame(dict(
				transportNumber=0,
				requestNewStream=True,
				protocolVersion=2,
				streamId='x'*26,
				streamingResponse=True,
				maxReceiveBytes=2**30,
				maxOpenTime=2**30,
				maxInactivity=0,
				needPaddingBytes=0,
				httpFormat=None,
				sack=None,
				lastSackSeenByClient=SACK(-1, ()))),
			HelloFrame.decode(sf(s)))