Beispiel #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)))
Beispiel #2
0
	def test_decode(self):
		for applicationLevel in (True, False):
			for reasonString in ('the reason', 'the | | reason', '', '|', '||'):
				s = reasonString + '|' + str(int(applicationLevel)) + '!'
				self.assertEqual(
					ResetFrame(reasonString, applicationLevel),
					ResetFrame.decode(sf(s)))
Beispiel #3
0
	def test_decodeFailedTooMuchNestingArray(self):
		"""
		If the L{HelloFrame} has too much nesting of arrays,
		L{InvalidHello} is raised.
		"""
		level = 20000
		s = '[' * level + '1' + ']' * level
		self.assertRaises(InvalidHello, lambda: HelloFrame.decode(sf(s)))
Beispiel #4
0
	def test_decodeFailedTooMuchNestingObject(self):
		"""
		If the L{HelloFrame} has too much nesting of objects,
		L{InvalidHello} is raised.
		"""
		level = 20000
		s = '{"":' * level + '1' + '}' * level
		self.assertRaises(InvalidHello, lambda: HelloFrame.decode(sf(s)))
Beispiel #5
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)))
Beispiel #6
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,)
Beispiel #7
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)))
Beispiel #8
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)
Beispiel #9
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)))
Beispiel #10
0
	def test_encode(self):
		s = '\x00unchecked\xfftext'
		self.assertEqual(s + '^', CommentFrame(sf(s)).encode())
Beispiel #11
0
	def test_decode(self):
		s = 'Y'
		self.assertEqual(
			YouCloseItFrame(),
			YouCloseItFrame.decode(sf(s)))
Beispiel #12
0
	def test_decodeFailed(self):
		s = 'extra stuff' + 'Y'
		self.assertRaises(
			InvalidFrame,
			lambda: YouCloseItFrame.decode(sf(s)))
Beispiel #13
0
	def test_decode(self):
		s = 'C'
		self.assertEqual(
			StreamCreatedFrame(),
			StreamCreatedFrame.decode(sf(s)))
Beispiel #14
0
	def test_decodeFailed(self):
		s = 'extra stuff' + 'C'
		self.assertRaises(
			InvalidFrame,
			lambda: StreamCreatedFrame.decode(sf(s)))
Beispiel #15
0
	def test_decodeFailedAtSplit(self):
		for s in ('||4A', '', ' ', '|'):
			self.assertRaises(
				InvalidFrame,
				lambda: SackFrame.decode(sf(s)))
Beispiel #16
0
	def test_decode(self):
		for ackNum in (-1, 0, 1, 2**53):
			s = '1,4|%sT' % (ackNum,)
			self.assertEqual(
				StreamStatusFrame(SACK(ackNum, (1, 4))),
				StreamStatusFrame.decode(sf(s)))
Beispiel #17
0
	def test_decodeNoSackNumbers(self):
		s = '|%sA' % (2**53,)
		self.assertEqual(
			SackFrame(SACK(2**53, ())),
			SackFrame.decode(sf(s)))
Beispiel #18
0
	def test_decodeFailedOneSackNumberInvalid(self):
		for badNum in (2**53+1, -1, 0.5, 1.5):
			s = '1,%s|4A' % (badNum,)
			self.assertRaises(
				InvalidFrame,
				lambda: SackFrame.decode(sf(s)))
Beispiel #19
0
	def test_decode(self):
		s = '\x00unchecked\xfftext' + ' '
		self.assertEqual(
			StringFrame(StringFragment(s, 0, len(s) - 1)),
			StringFrame.decode(sf(s)))
Beispiel #20
0
	def test_decode(self):
		for reason in tk.allReasons:
			s = reason + 'K'
			self.assertEqual(
				TransportKillFrame(reason),
				TransportKillFrame.decode(sf(s)))
Beispiel #21
0
	def test_decodeFailedBadReason(self):
		s = '\x7freason|0!'
		self.assertRaises(
			InvalidFrame,
			lambda: ResetFrame.decode(sf(s)))
Beispiel #22
0
	def test_decode(self):
		s = '\x00unchecked\xfftext' + '^'
		self.assertEqual(
			CommentFrame(s[:-1]),
			CommentFrame.decode(sf(s)))
Beispiel #23
0
	def test_encode(self):
		s = '\x00unchecked\xfftext'
		self.assertEqual(s + ' ', StringFrame(sf(s)).encode())
Beispiel #24
0
	def test_decodeFailedBadBoolean(self):
		s = 'reason|2!'
		self.assertRaises(
			InvalidFrame,
			lambda: ResetFrame.decode(sf(s)))
Beispiel #25
0
	def test_decode(self):
		for seqNum in (0, 1, 2**32, 2**53):
			s = str(seqNum) + 'N'
			self.assertEqual(
				SeqNumFrame(seqNum),
				SeqNumFrame.decode(sf(s)))
Beispiel #26
0
	def test_decodeFailed(self):
		s = 'not_a_reasonK'
		self.assertRaises(
			InvalidFrame,
			lambda: TransportKillFrame.decode(sf(s)))
Beispiel #27
0
	def test_decodeFailed(self):
		for s in (str(-1) + 'N', str(-2**53) + 'N', str(2**53 + 1) + 'N', ' ', '00' + 'N', '0' * 1024):
			self.assertRaises(
				InvalidFrame,
				lambda: SeqNumFrame.decode(sf(s)))