Exemple #1
0
	def type_five_bad(self):
		'''
		Send a malformed type 5 message.
		'''
		m5 = ais.MsgType5()
		s5 = ais.Sentence(m5)
		[s_p1, s_p2] = s5.get_sentences()
		eng = self.INVALID_SENTENCE

		if self.chance(self.FAIL_CHANCE): # invaild part 1
			# bad checksum
			if self.chance(self.FAIL_CHANCE):
				cs = s_p1[-2:]
				cs = int(cs, 16) + 1
				cs = '{0:0>2}'.format(hex(cs)[2:].upper())
				s_p1 = "{0}{1}".format(s_p1[:-2], cs)

			# invalid msg
			elif self.chance(self.FAIL_CHANCE):
				s_p1 = s_p1[15:]
			# invalid start chars
			else:
				rest = s_p1[6:]
				s_p1 = "{0}{1}".format(sp.random_alpha(3,5), rest)

			self.write("{0}\x07".format(s_p1))
			self.read(length=len(eng), expect=eng)

		else: # invalid part 2
			# bad checksum
			if self.chance(self.FAIL_CHANCE):
				cs = s_p2[-2:]
				cs = int(cs, 16) + 1
				cs = '{0:0>2}'.format(hex(cs)[2:].upper())
				s_p2 = "{0}{1}".format(s_p2[:-2], cs)
			# invalid msg
			elif self.chance(self.FAIL_CHANCE):
				s_p2 = s_p2[15:]
			# invalid start chars
			else:
				rest = s_p2[6:]
				s_p2 = "{0}{1}".format(sp.random_alpha(3,5), rest)

			self.write("{0}\x07".format(s_p1))
			self.read(length=len(self.PARTIAL_MSG), expect=self.PARTIAL_MSG)

			self.write("{0}\x07".format(s_p2))
			self.read(length=len(eng), expect=eng)
Exemple #2
0
	def type_four_bad(self):
		'''
		Send a malformed type 4 message.
		'''
		m4 = ais.MsgType4()
		s4 = ais.Sentence(m4)
		[s] = s4.get_sentences()
		eng = self.INVALID_SENTENCE

		# bad checksum
		if self.chance(self.FAIL_CHANCE):
			cs = s[-2:]
			cs = int(cs, 16) + 1
			cs = '{0:0>2}'.format(hex(cs)[2:].upper())
			s = "{0}{1}".format(s[:-2], cs)
		# invalid msg
		elif self.chance(self.FAIL_CHANCE):
			s = s[15:]
		# invalid start chars
		else:
			rest = s[6:]
			s = "{0}{1}".format(sp.random_alpha(3,6), rest)

		self.write("{0}\x07".format(s))
		self.read(length=len(eng), expect=eng)
    def _get_content(self):
        all_chars = [chr(x) for x in range(128)]
        all_chars.remove(self.TERM)

        result = ''
        b_len = randint(5, self.INBUFSZ - 1)  #TERM is added at the end.
        remaining = b_len
        while 0 < remaining:

            if self.chance(0.7):
                result += sp.random_alpha(0,
                                          10 if remaining > 10 else remaining)
            elif self.chance(0.3):
                result += sp.random_digits(0,
                                           10 if remaining > 10 else remaining)
            else:
                result += ''.join(
                    choice(all_chars)
                    for _ in range(0, 10 if remaining > 10 else remaining))

            if len(result) >= b_len:
                break

            if self.chance(0.7):
                result += ' '
            else:
                result += '.'

            if self.chance(0.1):
                result += '\n'

            remaining = b_len - len(result)

        if True == self.DEBUG_CONTENT:
            result = "Bob's discount randumb stor-E gener8r for only $12.99. Come on in.\nGet your storie today!\n"

        if True == DEBUG:
            r = '\\'.join(hex(ord(c)) for c in result)
            print "result hex: {0}".format(r)
            print "result: {0}".format(result)

        return result
Exemple #4
0
    def _get_content(self):
        all_chars = [chr(x) for x in range(128)]
        all_chars.remove(self.TERM)

        result = ""
        b_len = randint(5, self.INBUFSZ - 1)  # TERM is added at the end.
        remaining = b_len
        while 0 < remaining:

            if self.chance(0.7):
                result += sp.random_alpha(0, 10 if remaining > 10 else remaining)
            elif self.chance(0.3):
                result += sp.random_digits(0, 10 if remaining > 10 else remaining)
            else:
                result += "".join(choice(all_chars) for _ in range(0, 10 if remaining > 10 else remaining))

            if len(result) >= b_len:
                break

            if self.chance(0.7):
                result += " "
            else:
                result += "."

            if self.chance(0.1):
                result += "\n"

            remaining = b_len - len(result)

        if True == self.DEBUG_CONTENT:
            result = "Bob's discount randumb stor-E gener8r for only $12.99. Come on in.\nGet your storie today!\n"

        if True == DEBUG:
            r = "\\".join(hex(ord(c)) for c in result)
            print "result hex: {0}".format(r)
            print "result: {0}".format(result)

        return result