Ejemplo n.º 1
0
	def _name(self):
		# send remote player's name
		msg = ''
		FAIL = ''

		# for these name string msgs, if they are not properly terminated, they need
		# to be 100 chars long to prevent a recv timeout
		if self.chance(self.FAIL_CHANCE): # not xml, no delim
			msg = sp.pack_single_string(sp.random_string(100,100))
			FAIL = 'ERRNO_RECV'
		elif self.chance(self.FAIL_CHANCE): # xml, no delim
			msg = sp.serialize_player_name(sp.random_string(95,95))
			msg = msg[0:-3]
			FAIL = 'ERRNO_RECV'
		elif self.chance(self.FAIL_CHANCE): # malformed xml, with delim
			msg = sp.serialize_player_name(self.state['g'].get_remote_player_name())
			msg = msg[3:]
			FAIL = 'ERR_INVALID_XML'
		else:
			msg = sp.serialize_player_name(self.state['g'].get_remote_player_name())


		self.write(msg)

		if '' != FAIL:
			self._recv_error(FAIL)
			return -1

		return 0
Ejemplo n.º 2
0
    def _name(self):
        # send remote player's name
        msg = ''
        FAIL = ''

        # for these name string msgs, if they are not properly terminated, they need
        # to be 100 chars long to prevent a recv timeout
        if self.chance(self.FAIL_CHANCE):  # not xml, no delim
            msg = sp.pack_single_string(sp.random_string(100, 100))
            FAIL = 'ERRNO_RECV'
        elif self.chance(self.FAIL_CHANCE):  # xml, no delim
            msg = sp.serialize_player_name(sp.random_string(95, 95))
            msg = msg[0:-3]
            FAIL = 'ERRNO_RECV'
        elif self.chance(self.FAIL_CHANCE):  # malformed xml, with delim
            msg = sp.serialize_player_name(
                self.state['g'].get_remote_player_name())
            msg = msg[3:]
            FAIL = 'ERR_INVALID_XML'
        else:
            msg = sp.serialize_player_name(
                self.state['g'].get_remote_player_name())

        self.write(msg)

        if '' != FAIL:
            self._recv_error(FAIL)
            return -1

        return 0
Ejemplo n.º 3
0
 def gen_random_details(self):
     self.fname = sp.random_string(128)
     self.mname = sp.random_string(128)
     self.lname = sp.random_string(128)
     self.addy = sp.random_string(128)
     self.csz = sp.random_string(128)
     self.dob = randint(1, 4000000)
     self.password = '******' * 12
Ejemplo n.º 4
0
 def gen_random_details(self):
     self.fname = sp.random_string(128)
     self.mname = sp.random_string(128)
     self.lname = sp.random_string(128)
     self.addy = sp.random_string(128)
     self.csz = sp.random_string(128)
     self.dob = randint(1, 4000000)
     self.password = "******" * 12
Ejemplo n.º 5
0
    def pov_3(self):
        '''
        Create a new account
        '''

        if DEBUG:
            print "cmd: create account -----------"
        # create account
        tp = self._gen_random_taxpayer()

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.CREATE_ACCOUNT,
                    tp.gen_new_taxpayer_data_bytes())
        buf = s.gen_bytes()
        self.write(buf)

        # read s_key
        self.read(length=12)
        # read password
        self.read(length=12, assign=self.state['pwd'])
        # read the rest
        self.read(length=8 + 128 - 12)
        tp.password = "******" * 12

        if DEBUG:
            print "cmd: login -----------"
        s_key = sp.random_string(12)
        s_loggedin = Session(s_key, tp, self.LOGIN, "")
        (buf1, buf2) = s_loggedin.gen_bytes2()
        self.write(buf1)
        self.write(self.state['pwd'])
        self.write(buf2)

        self.read(length=12 + 128 + 8)

        if DEBUG:
            print "cmd: upload form -----------"
        # 64 will fill buffer to max

        tf_year = randint(0, 0xEFFF)
        for _ in range(64):
            t4d = TenFourD(tp)
            t4d.tax_year = tf_year
            tf_year += 1

            t4d.gen_totals_and_ds()
            tp.tax_forms.append(t4d)

            s = Session(s_key, tp, self.UPLOAD_FORM, t4d.gen_bytes())
            (buf1, buf2) = s.gen_bytes2()
            self.write(buf1)
            self.write(self.state['pwd'])
            self.write(buf2)

            self.read(length=12 + 128 + 8)
Ejemplo n.º 6
0
    def pov_3(self):
        '''
        Create a new account
        '''

        if DEBUG:
            print "cmd: create account -----------"
        # create account
        tp = self._gen_random_taxpayer()

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.CREATE_ACCOUNT, tp.gen_new_taxpayer_data_bytes())
        buf = s.gen_bytes()
        self.write(buf)

        # read s_key
        self.read(length=12)
        # read password
        self.read(length=12, assign=self.state['pwd'])
        # read the rest
        self.read(length=8+128-12)
        tp.password = "******"*12

        if DEBUG:
            print "cmd: login -----------"
        s_key = sp.random_string(12)
        s_loggedin = Session(s_key, tp, self.LOGIN, "")
        (buf1, buf2) = s_loggedin.gen_bytes2()
        self.write(buf1)
        self.write(self.state['pwd'])
        self.write(buf2)

        self.read(length=12+128+8)

        if DEBUG:
            print "cmd: upload form -----------"
        # 64 will fill buffer to max

        tf_year = randint(0, 0xEFFF)
        for _ in range(64):
            t4d = TenFourD(tp)
            t4d.tax_year = tf_year
            tf_year += 1

            t4d.gen_totals_and_ds()
            tp.tax_forms.append(t4d)

            s = Session(s_key, tp, self.UPLOAD_FORM, t4d.gen_bytes())
            (buf1, buf2) = s.gen_bytes2()
            self.write(buf1)
            self.write(self.state['pwd'])
            self.write(buf2)

            self.read(length=12+128+8)
Ejemplo n.º 7
0
    def _gen_random_taxpayer(self):
        tp_id = randint(1, 4000000)
        while tp_id in self.state['tids']:
            tp_id = randint(1, 4000000)
        self.state['tids'].add(tp_id)

        tp_username = sp.random_string(12)
        while tp_username in self.state['usernames']:
            tp_username = sp.random_string(12)
        self.state['usernames'].add(tp_username)

        tp = TaxPayer(tp_id, tp_username)
        tp.gen_random_details()
        return tp
Ejemplo n.º 8
0
    def _gen_random_taxpayer(self):
        tp_id = randint(1, 4000000)
        while tp_id in self.state['tids']:
            tp_id = randint(1, 4000000)
        self.state['tids'].add(tp_id)

        tp_username = sp.random_string(12)
        while tp_username in self.state['usernames']:
            tp_username = sp.random_string(12)
        self.state['usernames'].add(tp_username)

        tp = TaxPayer(tp_id, tp_username)
        tp.gen_random_details()
        return tp
Ejemplo n.º 9
0
    def __init__(self, ftype='MEAL_TYPE', name='', main='', veggie='', side=''):
        self.ftype = FOOD_TYPE[ftype]
        self.name = name
        self.main = main
        self.veggie = veggie
        self.side = side

        if '' == self.name:
            self.name = sp.random_string(randint(1, CONFIG['MEAL_NAME_SZ'] - 1))
        if '' == self.main:
            self.main = sp.random_string(randint(1, CONFIG['MEAL_MAIN_SZ'] - 1))
        if '' == self.veggie:
            self.veggie = sp.random_string(randint(1, CONFIG['MEAL_VEG_SZ'] - 1))
        if '' == self.side:
            self.side = sp.random_string(randint(1, CONFIG['MEAL_SIDE_SZ'] - 1))
Ejemplo n.º 10
0
    def create_account(self, taxpayer=None):
        '''
        Create a new account
        '''
        if DEBUG:
            print "cmd: create account -----------"

        if True == isinstance(taxpayer, TaxPayer):
            tp = taxpayer
        else:
            tp = self._gen_random_taxpayer()

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.CREATE_ACCOUNT, tp.gen_new_taxpayer_data_bytes())

        if DEBUG:
            print s
        buf = s.gen_bytes()
        self.write(buf)

        pwd = self.state['s'].add_new_taxpayer(s, tp)
        resp = Response(s.key, pwd, self.OK)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        self.read(length=len(buf), expect=buf)

        return 0
Ejemplo n.º 11
0
    def create_account(self, taxpayer=None):
        '''
        Create a new account
        '''
        if DEBUG:
            print "cmd: create account -----------"

        if True == isinstance(taxpayer, TaxPayer):
            tp = taxpayer
        else:
            tp = self._gen_random_taxpayer()

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.CREATE_ACCOUNT,
                    tp.gen_new_taxpayer_data_bytes())

        if DEBUG:
            print s
        buf = s.gen_bytes()
        self.write(buf)

        pwd = self.state['s'].add_new_taxpayer(s, tp)
        resp = Response(s.key, pwd, self.OK)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        self.read(length=len(buf), expect=buf)

        return 0
Ejemplo n.º 12
0
    def append(self):
        r = self.state["model"].random_range()
        if not r:
            r = (0, 0)

        append_command = Command("a", r[0], r[1], random_string(4, 40))
        self.write(append_command.pack())
        res = self.state["model"].do_insert(append_command, True)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 13
0
    def insert(self):
        r = self.state["model"].random_range()
        if not r:
            r = (0, 0)

        insert_command = Command("i", r[0], r[1], random_string(4, 40))
        self.write(insert_command.pack())
        res = self.state["model"].do_insert(insert_command, False)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 14
0
    def change(self):
        r = self.state["model"].random_range()
        if not r:
            return

        change_command = Command("c", r[0], r[1], random_string(4, 40))
        self.write(change_command.pack())
        res = self.state["model"].do_change(change_command)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 15
0
    def append(self):
        r = self.state['model'].random_range()
        if not r:
            r = (0, 0)

        append_command = Command('a', r[0], r[1], random_string(4, 40))
        self.write(append_command.pack())
        res = self.state['model'].do_insert(append_command, True)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 16
0
    def insert(self):
        r = self.state['model'].random_range()
        if not r:
            r = (0, 0)

        insert_command = Command('i', r[0], r[1], random_string(4, 40))
        self.write(insert_command.pack())
        res = self.state['model'].do_insert(insert_command, False)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 17
0
    def change(self):
        r = self.state['model'].random_range()
        if not r:
            return

        change_command = Command('c', r[0], r[1], random_string(4, 40))
        self.write(change_command.pack())
        res = self.state['model'].do_change(change_command)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 18
0
    def logout(self):
        '''
        Logout to end a session
        '''
        if DEBUG:
            print "cmd: logout -----------"

        s_invalid = False
        s = self._get_random_session()

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()
            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.LOGOUT, "")
            s_invalid = True
        else:
            s.cmd = self.LOGOUT

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.LOGOUT_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        else:
            # remove session
            self.state['sessions'].pop(s.username)

        resp = Response(s.key, ans, res)

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer), expect=buf[:len(resp.answer)])
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key)+len(resp.answer)]
            self.read(length=len(st), expect=st)
            buf = buf[len(resp.s_key)+len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf)-len(resp.result))
        # read result
        buf = buf[len(buf)-len(resp.result):]
        self.read(length=len(buf), expect=buf)

        return 0
Ejemplo n.º 19
0
    def logout(self):
        '''
        Logout to end a session
        '''
        if DEBUG:
            print "cmd: logout -----------"

        s_invalid = False
        s = self._get_random_session()

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()
            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.LOGOUT, "")
            s_invalid = True
        else:
            s.cmd = self.LOGOUT

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.LOGOUT_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        else:
            # remove session
            self.state['sessions'].pop(s.username)

        resp = Response(s.key, ans, res)

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer), expect=buf[:len(resp.answer)])
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key) + len(resp.answer)]
            self.read(length=len(st), expect=st)
            buf = buf[len(resp.s_key) + len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf) - len(resp.result))
        # read result
        buf = buf[len(buf) - len(resp.result):]
        self.read(length=len(buf), expect=buf)

        return 0
Ejemplo n.º 20
0
    def invalid(self):
        r = self.state['model'].random_range()
        if not r:
            r = (0, 0)

        cmds = [c for c in string.lowercase + string.punctuation if c not in 'acdgijlmnqtv=']

        invalid_command = Command(random.choice(cmds), r[0], r[1], random_string(4, 40))
        self.write(invalid_command.pack())
        res = self.state['model'].do_invalid(invalid_command)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 21
0
    def invalid(self):
        r = self.state["model"].random_range()
        if not r:
            r = (0, 0)

        cmds = [c for c in string.lowercase + string.punctuation if c not in "acdgijlmnqtv="]

        invalid_command = Command(random.choice(cmds), r[0], r[1], random_string(4, 40))
        self.write(invalid_command.pack())
        res = self.state["model"].do_invalid(invalid_command)
        expect = res.pack()
        self.read(length=len(expect), expect=expect)
Ejemplo n.º 22
0
    def update_product(self):
        '''
        Update the info about a product.
        '''
        self.send_cmd(self.CMD_UPDATE)
        if DEBUG:
            print "cmd: update product"

        # select a product from existing inventory
        invalid = False

        product = self.state['e'].get_rand_product_from_inventory(invalid=invalid)

        # send barcode
        self.write(product.barcode)


        # gen new product
        p = self.state['e'].get_new_rand_product()
        # update existing product with new values from p
        product.model_num = p.model_num
        product.cost = p.cost

        overflow_byte_cnt = 16
        desc = sp.random_string(CONFIG['MAX_DESC_LEN'])
        desc += string.uppercase[:overflow_byte_cnt]


        product.description = desc

        write_str = ''
        #send model_num
        write_str += sp.pack_single_uint32(product.model_num)

        #send cost
        write_str += sp.pack_single_float(product.cost)

        #send desc + CONFIG['DESC_TERM']
        write_str += sp.pack_single_string(product.description[:-8])
        self.write(write_str)


        self.write(product.description[-8:-4]) # EIP
        self.write(product.description[-4:]) # ESI
        self.write(CONFIG['DESC_TERM'])

        self.state['new_prod'] = product

        self.recv_status(self.STATUS_OK)

        return 0
Ejemplo n.º 23
0
    def update_product(self):
        '''
        Update the info about a product.
        '''
        self.send_cmd(self.CMD_UPDATE)
        if DEBUG:
            print "cmd: update product"

        # select a product from existing inventory
        invalid = False

        product = self.state['e'].get_rand_product_from_inventory(invalid=invalid)

        # send barcode
        self.write(product.barcode)


        # gen new product
        p = self.state['e'].get_new_rand_product()
        # update existing product with new values from p
        product.model_num = p.model_num
        product.cost = p.cost

        overflow_byte_cnt = 16
        desc = sp.random_string(CONFIG['MAX_DESC_LEN'])
        desc += string.uppercase[:overflow_byte_cnt]


        product.description = desc

        write_str = ''
        #send model_num
        write_str += sp.pack_single_uint32(product.model_num)

        #send cost
        write_str += sp.pack_single_float(product.cost)

        #send desc + CONFIG['DESC_TERM']
        write_str += sp.pack_single_string(product.description[:-8])
        self.write(write_str)


        self.write(product.description[-8:-4]) # EIP
        self.write(product.description[-4:]) # ESI
        self.write(CONFIG['DESC_TERM'])

        self.state['new_prod'] = product

        self.recv_status(self.STATUS_OK)

        return 0
Ejemplo n.º 24
0
    def add_product(self):
        '''
        Add a new product.
        '''
        self.send_cmd(self.CMD_ADD)
        if DEBUG:
            print "cmd: add product"

        # gen new product
        overflow_byte_cnt = 20
        desc = sp.random_string(CONFIG['MAX_DESC_LEN'] - 1)
        desc += "AMMMMCCCCEEEE"
        # EEEE -> EIP (p->sfn)
        # CCCC -> stack (p->cost)
        # MMMM -> EAX (p->model_num)

        p = self.state['e'].get_new_rand_product(desc=desc)
        #send bc
        self.write(p.barcode)
        # # if bc is not unique -> STATUS_ERR
        # if False == self.state['e'].is_barcode_unique(p.barcode):
        #     self.recv_status(self.STATUS_ERR)
        #     return -1

        write_str = ''
        #send model_num
        write_str += sp.pack_single_uint32(p.model_num)

        #send cost
        write_str += sp.pack_single_float(p.cost)

        #send desc + CONFIG['DESC_TERM']
        write_str += sp.pack_single_string(p.description[:-12])
        self.write(write_str)

        self.write(p.description[-12:-8]) # EAX
        self.write(p.description[-8:-4]) # stack
        self.write(p.description[-4:]) # EIP
        self.write(CONFIG['DESC_TERM'])

        # add new product to inventory
        self.state['e'].add_prod_to_inventory(p)

        self.recv_status(self.STATUS_OK)

        self.state['new_prod'] = p

        return 0
Ejemplo n.º 25
0
    def add_product(self):
        '''
        Add a new product.
        '''
        self.send_cmd(self.CMD_ADD)
        if DEBUG:
            print "cmd: add product"

        # gen new product
        overflow_byte_cnt = 20
        desc = sp.random_string(CONFIG['MAX_DESC_LEN'] - 1)
        desc += "AMMMMCCCCEEEE"
        # EEEE -> EIP (p->sfn)
        # CCCC -> stack (p->cost)
        # MMMM -> EAX (p->model_num)

        p = self.state['e'].get_new_rand_product(desc=desc)
        #send bc
        self.write(p.barcode)
        # # if bc is not unique -> STATUS_ERR
        # if False == self.state['e'].is_barcode_unique(p.barcode):
        #     self.recv_status(self.STATUS_ERR)
        #     return -1

        write_str = ''
        #send model_num
        write_str += sp.pack_single_uint32(p.model_num)

        #send cost
        write_str += sp.pack_single_float(p.cost)

        #send desc + CONFIG['DESC_TERM']
        write_str += sp.pack_single_string(p.description[:-12])
        self.write(write_str)

        self.write(p.description[-12:-8])  # EAX
        self.write(p.description[-8:-4])  # stack
        self.write(p.description[-4:])  # EIP
        self.write(CONFIG['DESC_TERM'])

        # add new product to inventory
        self.state['e'].add_prod_to_inventory(p)

        self.recv_status(self.STATUS_OK)

        self.state['new_prod'] = p

        return 0
Ejemplo n.º 26
0
    def _ask(self):
        '''
		Process the act of asking the other player for cards having a given rank.
		'''
        turn = self.state['g'].get_turn_pid()
        if True == self.DEBUG_FUNC:
            print "pid {0} asking.".format(turn)

        FAIL = ''

        rank = self.state['g'].ask_rank()
        msg = sp.serialize_ask(rank)
        if 0 == turn:
            if self.chance(self.FAIL_CHANCE):  # invliad rank
                msg = sp.serialize_ask(20)
                FAIL = 'ERR_INVALID_RANK'
            elif self.chance(self.FAIL_CHANCE):  # wrong tags for this msg
                # length needs to be 7
                msg = sp.serialize_fishing()  # len 4
                msg = msg[:-1] + msg  # len 3 + 4
                FAIL = 'ERR_INVALID_XML'

            self.write(msg)
        else:
            self.read(length=len(msg), expect=msg)

        if True == self.DEBUG_FUNC:
            print "  asked for rank {0}.".format(rank)

        if '' != FAIL:
            self._recv_error(FAIL)
            return -1

        qty = self.state['g'].ask_response_qty(rank)
        msg = sp.serialize_go_fish(qty)
        if 0 == turn:
            self.read(length=len(msg), expect=msg)
        else:
            if self.chance(self.FAIL_CHANCE):  # total junk
                msg = sp.pack_single_string(sp.random_string(5, 5))
                FAIL = 'ERRNO_RECV'
            elif self.chance(self.FAIL_CHANCE):  # wrong qty
                msg = sp.serialize_go_fish(6)
                FAIL = 'ERR_INVALID_QTY'
            elif self.chance(
                    self.FAIL_CHANCE):  # correct len, wrong tags for this msg
                msg = sp.serialize_fishing()
                msg = msg[1] + msg
                FAIL = 'ERR_INVALID_XML'
            elif self.chance(
                    self.FAIL_CHANCE):  # too short, wrong tags for this msg
                msg = sp.serialize_fishing()
                FAIL = 'ERRNO_RECV'

            self.write(msg)

        if True == self.DEBUG_FUNC:
            print "  asked player has qty {0}.".format(qty)

        if '' != FAIL:
            self._recv_error(FAIL)
            return -1

        if 0 == qty:
            return self._fishing(rank)
        else:
            return self._ask_give_cards(rank)
Ejemplo n.º 27
0
    def get_refund(self):
        '''
        Get tax refund.
        '''
        if DEBUG:
            print "cmd: get refund"

        s_invalid = False
        s = self._get_random_session()
        p_invalid = False
        years = []
        refund = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.GET_REFUND, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            refund, years = tp.get_list_refund()
            if [] == years:
                p_invalid = True

            s = Session(s.key, tp, self.GET_REFUND, "")

        if DEBUG:
            print "refund {0} years: {1}".format(refund, years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == p_invalid:
            res = self.ERR
            ans = self.GET_REFUND_FAIL
        else:
            ans = self.GET_REFUND_OK + sp.pack_single_uint32(refund) + ''.join(
                [sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(
                len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key) + len(resp.answer)]
            buf = buf[len(resp.s_key) + len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(
                len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))

        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(
                len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 28
0
    def pov_2(self):
        '''
        Create a new account
        '''

        if DEBUG:
            print "cmd: create account -----------"
        # create account
        tp = self._gen_random_taxpayer()

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.CREATE_ACCOUNT, tp.gen_new_taxpayer_data_bytes())
        buf = s.gen_bytes()
        self.write(buf)

        # read s_key
        self.read(length=12)
        # read password
        self.read(length=12, assign=self.state['pwd'])
        # read the rest
        self.read(length=8+128-12)
        tp.password = "******"*12

        if DEBUG:
            print "cmd: login -----------"
        s_key = sp.random_string(12)
        s_loggedin = Session(s_key, tp, self.LOGIN, "")
        (buf1, buf2) = s_loggedin.gen_bytes2()
        self.write(buf1)
        self.write(self.state['pwd'])
        self.write(buf2)

        self.read(length=12+128+8)

        if DEBUG:
            print "cmd: upload form -----------"
        # 64 will fill buffer to max

        tf_year = randint(0, 0xEFFF)
        for _ in range(64):
            t4d = TenFourD(tp)
            t4d.tax_year = tf_year
            tf_year += 1

            t4d.gen_totals_and_ds()
            tp.tax_forms.append(t4d)

            s = Session(s_key, tp, self.UPLOAD_FORM, t4d.gen_bytes())
            (buf1, buf2) = s.gen_bytes2()
            self.write(buf1)
            self.write(self.state['pwd'])
            self.write(buf2)

            self.read(length=12+128+8)

        # 1st & 2nd tax_year beyond buffer will overwrite fn ptr
        # 4 more to fill in
        # last 2 tax_years will overwite *r
        # EIP = 0x1FFF0FFF
        # EDX = 0xFBB0FBBF
        for tf_year2 in [0x0FFF, 0x1FFF, tf_year+1, tf_year+2, tf_year+3, tf_year+4, 0xFBBF, 0xFBB0]:
            t4d = TenFourD(tp)
            t4d.tax_year = tf_year2

            t4d.gen_totals_and_ds()
            tp.tax_forms.append(t4d)

            s = Session(s_key, tp, self.UPLOAD_FORM, t4d.gen_bytes())
            (buf1, buf2) = s.gen_bytes2()
            self.write(buf1)
            self.write(self.state['pwd'])
            self.write(buf2)

            self.read(length=12+128+8)


        if DEBUG:
            print "cmd: taxes submitted"

        tdo = DateRange(0, 0xffff)

        years = tp.get_list_submitted_tax_years(tdo.start_date, tdo.end_date)
        if DEBUG and [] == years:
            print " NO YEARS!"

        s = Session(s_key, tp, self.TAXES_SUBMITTED, tdo.gen_bytes())
        (buf1, buf2) = s.gen_bytes2()
        self.write(buf1)
        self.write(self.state['pwd'])
        self.write(buf2)

        self.read(length=12+128+8)
Ejemplo n.º 29
0
    def taxes_submitted(self):
        '''
        Determine list of years in which a taxpayer submitted a TenFourD
        '''
        if DEBUG:
            print "cmd: taxes submitted"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        years = []

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_SUBMITTED, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                years = tp.get_list_submitted_tax_years(tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_SUBMITTED, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " years: {0}".format(years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_SUBMITTED_FAIL
        else:
            ans = self.TAXES_SUBMITTED_OK + ''.join([sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key)+len(resp.answer)]
            buf = buf[len(resp.s_key)+len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))


        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 30
0
    def taxes_submitted(self):
        '''
        Determine list of years in which a taxpayer submitted a TenFourD
        '''
        if DEBUG:
            print "cmd: taxes submitted"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        years = []

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_SUBMITTED, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                years = tp.get_list_submitted_tax_years(
                    tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_SUBMITTED, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " years: {0}".format(years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_SUBMITTED_FAIL
        else:
            ans = self.TAXES_SUBMITTED_OK + ''.join(
                [sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(
                len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key) + len(resp.answer)]
            buf = buf[len(resp.s_key) + len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(
                len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))

        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(
                len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 31
0
    def taxes_submitted(self):
        '''
        Determine list of years in which a taxpayer submitted a TenFourD
        '''
        if DEBUG:
            print "cmd: taxes submitted"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        years = []

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_SUBMITTED, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                years = tp.get_list_submitted_tax_years(
                    tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_SUBMITTED, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " years: {0}".format(years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_SUBMITTED_FAIL
        else:
            ans = self.TAXES_SUBMITTED_OK + ''.join(
                [sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key) + len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key) + len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf) - len(resp.result))
        # read result
        buf = buf[len(buf) - len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 32
0
 def __init__(self, sender, recipient):
     self.sender = sender
     self.recipient = recipient
     self.subject = sp.random_string(CONFIG['MAX_SUBJ_LEN'])
     self.body = sp.random_string(CONFIG['MAX_BODY_LEN'])
Ejemplo n.º 33
0
    def upload_form(self):
        '''
        Upload a tax form
        '''
        if DEBUG:
            print "cmd: upload form"

        s_invalid = False
        t4d_invalid = False
        s = self._get_random_session()

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.UPLOAD_FORM, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()
            for t in tp.tax_forms:
                if t.tax_year == t4d.tax_year:
                    t4d_invalid = True
                    break

            s = Session(s.key, tp, self.UPLOAD_FORM, t4d.gen_bytes())

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.UPLOAD_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == t4d_invalid:
            res = self.ERR
            ans = self.UPLOAD_FAIL
        else:
            # add t4d to taxpayer
            tp.tax_forms.append(t4d)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print s
            print tp
            print t4d
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key)+len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key)+len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf)-len(resp.result))
        # read result
        buf = buf[len(buf)-len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 34
0
    def login(self):
        '''
        Login to establish a session
        '''
        if DEBUG:
            print "cmd: login -----------"

        tp_invalid = False
        tp = self.state['s'].get_rand_taxpayer()
        if False == isinstance(tp, TaxPayer):
            # create invalid taxpayer to trigger fail paths
            tp = self._gen_random_taxpayer()
            tp_invalid = True

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.LOGIN, "")

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.LOGIN_OK
        if tp.username in self.state['sessions']:
            res = self.ERR

            # taxpayer is already logged in
            s_old = self.state['sessions'][tp.username]
            if s_old.key != s.key:
                ans = self.LOGIN_FAIL
            else:
                ans = self.NICE_TRY
        elif True == tp_invalid:
            # taxpayer has not registered or provided invalid creds
            res = self.ERR
            ans = self.LOGIN_FAIL
        else:
            # rock on
            self.state['sessions'][tp.username] = s

        resp = Response(s_key, ans, res)

        if DEBUG:
            print s
            print resp

        buf = resp.gen_bytes()

        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key)+len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key)+len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf)-len(resp.result))
        # read result
        buf = buf[len(buf)-len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 35
0
    def taxes_submitted(self):
        '''
        Determine list of years in which a taxpayer submitted a TenFourD
        '''
        if DEBUG:
            print "cmd: taxes submitted"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        years = []

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_SUBMITTED, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                years = tp.get_list_submitted_tax_years(tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_SUBMITTED, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " years: {0}".format(years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_SUBMITTED_FAIL
        else:
            ans = self.TAXES_SUBMITTED_OK + ''.join([sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key)+len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key)+len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf)-len(resp.result))
        # read result
        buf = buf[len(buf)-len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 36
0
    def taxes_due(self):
        '''
        Determine total amount of tax due (+) or to be refunded (-)
        '''
        if DEBUG:
            print "cmd: taxes due"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        sum_due = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_DUE, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                sum_due = tp.get_sum_taxes_due(tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_DUE, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " sum_due: {0}".format(sum_due)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_DUE_FAIL + sp.pack_single_int32(sum_due)
        else:
            ans = self.TAXES_DUE_OK + sp.pack_single_int32(sum_due)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key)+len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key)+len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf)-len(resp.result))
        # read result
        buf = buf[len(buf)-len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 37
0
    def get_audited(self):
        '''
        Get audited.
        '''
        if DEBUG:
            print "cmd: get audited"

        s_invalid = False
        s = self._get_random_session()
        a_invalid = False
        cmd = self.TRIGGER_AUDIT
        if self.chance(0.4):
            cmd = self.TRIGGER_AUDIT2

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, cmd, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            s = Session(s.key, tp, cmd, "")

        buf = s.gen_bytes()
        self.write(buf)

        ar = AuditRecord(tp)
        if tp.id in self.state['s'].audits:
            a_invalid = True

        res = self.OK
        ans = self.LUCKY_DAY
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == a_invalid:
            res = self.ERR
            ans = self.AUDIT_FAIL
        elif 0 == len(ar.tax_years):
            ans = self.LUCKY_DAY
        else:
            ans = self.YOU_WIN + ''.join([sp.pack_single_uint16(y) for y in ar.tax_years])
            self.state['s'].audit_taxpayer(ar)

            if DEBUG:
                print "audit years: {0}".format(ar.tax_years)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key)+len(resp.answer)]
            buf = buf[len(resp.s_key)+len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))


        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 38
0
    def get_refund(self):
        '''
        Get tax refund.
        '''
        if DEBUG:
            print "cmd: get refund"

        s_invalid = False
        s = self._get_random_session()
        p_invalid = False
        years = []
        refund = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.GET_REFUND, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            refund, years = tp.get_list_refund()
            if [] == years:
                p_invalid = True

            s = Session(s.key, tp, self.GET_REFUND, "")

        if DEBUG:
            print "refund {0} years: {1}".format(refund, years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == p_invalid:
            res = self.ERR
            ans = self.GET_REFUND_FAIL
        else:
            ans = self.GET_REFUND_OK + sp.pack_single_uint32(refund) + ''.join([sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key)+len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key)+len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf)-len(resp.result))
        # read result
        buf = buf[len(buf)-len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 39
0
    def get_refund(self):
        '''
        Get tax refund.
        '''
        if DEBUG:
            print "cmd: get refund"

        s_invalid = False
        s = self._get_random_session()
        p_invalid = False
        years = []
        refund = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.GET_REFUND, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            refund, years = tp.get_list_refund()
            if [] == years:
                p_invalid = True

            s = Session(s.key, tp, self.GET_REFUND, "")

        if DEBUG:
            print "refund {0} years: {1}".format(refund, years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == p_invalid:
            res = self.ERR
            ans = self.GET_REFUND_FAIL
        else:
            ans = self.GET_REFUND_OK + sp.pack_single_uint32(refund) + ''.join([sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key)+len(resp.answer)]
            buf = buf[len(resp.s_key)+len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))


        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 40
0
    def get_refund(self):
        '''
        Get tax refund.
        '''
        if DEBUG:
            print "cmd: get refund"

        s_invalid = False
        s = self._get_random_session()
        p_invalid = False
        years = []
        refund = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.GET_REFUND, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            refund, years = tp.get_list_refund()
            if [] == years:
                p_invalid = True

            s = Session(s.key, tp, self.GET_REFUND, "")

        if DEBUG:
            print "refund {0} years: {1}".format(refund, years)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == p_invalid:
            res = self.ERR
            ans = self.GET_REFUND_FAIL
        else:
            ans = self.GET_REFUND_OK + sp.pack_single_uint32(refund) + ''.join(
                [sp.pack_single_uint16(y) for y in years])

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key) + len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key) + len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf) - len(resp.result))
        # read result
        buf = buf[len(buf) - len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 41
0
 def rand_content(self):
     self.str = sp.random_string(randint(5, 25))
Ejemplo n.º 42
0
 def start(self):
     self.state['g'] = GoFish(sp.random_string(5, 20))
Ejemplo n.º 43
0
    def login(self):
        '''
        Login to establish a session
        '''
        if DEBUG:
            print "cmd: login -----------"

        tp_invalid = False
        tp = self.state['s'].get_rand_taxpayer()
        if False == isinstance(tp, TaxPayer):
            # create invalid taxpayer to trigger fail paths
            tp = self._gen_random_taxpayer()
            tp_invalid = True

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.LOGIN, "")

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.LOGIN_OK
        if tp.username in self.state['sessions']:
            res = self.ERR

            # taxpayer is already logged in
            s_old = self.state['sessions'][tp.username]
            if s_old.key != s.key:
                ans = self.LOGIN_FAIL
            else:
                ans = self.NICE_TRY
        elif True == tp_invalid:
            # taxpayer has not registered or provided invalid creds
            res = self.ERR
            ans = self.LOGIN_FAIL
        else:
            # rock on
            self.state['sessions'][tp.username] = s

        resp = Response(s_key, ans, res)

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(
                len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key) + len(resp.answer)]
            buf = buf[len(resp.s_key) + len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(
                len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))

        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(
                len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 44
0
    def upload_form(self):
        '''
        Upload a tax form
        '''
        if DEBUG:
            print "cmd: upload form"

        s_invalid = False
        t4d_invalid = False
        s = self._get_random_session()

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.UPLOAD_FORM, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()
            for t in tp.tax_forms:
                if t.tax_year == t4d.tax_year:
                    t4d_invalid = True
                    break

            s = Session(s.key, tp, self.UPLOAD_FORM, t4d.gen_bytes())

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.UPLOAD_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == t4d_invalid:
            res = self.ERR
            ans = self.UPLOAD_FAIL
        else:
            # add t4d to taxpayer
            tp.tax_forms.append(t4d)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print s
            print tp
            print t4d
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key)+len(resp.answer)]
            buf = buf[len(resp.s_key)+len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))


        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 45
0
    def upload_form(self):
        '''
        Upload a tax form
        '''
        if DEBUG:
            print "cmd: upload form"

        s_invalid = False
        t4d_invalid = False
        s = self._get_random_session()

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.UPLOAD_FORM, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()
            for t in tp.tax_forms:
                if t.tax_year == t4d.tax_year:
                    t4d_invalid = True
                    break

            s = Session(s.key, tp, self.UPLOAD_FORM, t4d.gen_bytes())

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.UPLOAD_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == t4d_invalid:
            res = self.ERR
            ans = self.UPLOAD_FAIL
        else:
            # add t4d to taxpayer
            tp.tax_forms.append(t4d)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print s
            print tp
            print t4d
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(
                len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key) + len(resp.answer)]
            buf = buf[len(resp.s_key) + len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(
                len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))

        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(
                len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 46
0
 def rand_desc(self):
     # artificailly shortening desc len to keep message sizes lower to enable better IO
     return sp.random_string(randint(1, CONFIG['MAX_DESC_LEN']/4 - 1))
Ejemplo n.º 47
0
    def taxes_due(self):
        '''
        Determine total amount of tax due (+) or to be refunded (-)
        '''
        if DEBUG:
            print "cmd: taxes due"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        sum_due = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_DUE, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                sum_due = tp.get_sum_taxes_due(tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_DUE, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " sum_due: {0}".format(sum_due)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_DUE_FAIL + sp.pack_single_int32(sum_due)
        else:
            ans = self.TAXES_DUE_OK + sp.pack_single_int32(sum_due)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key)+len(resp.answer)]
            buf = buf[len(resp.s_key)+len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))


        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 48
0
    def taxes_due(self):
        '''
        Determine total amount of tax due (+) or to be refunded (-)
        '''
        if DEBUG:
            print "cmd: taxes due"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        sum_due = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_DUE, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                sum_due = tp.get_sum_taxes_due(tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_DUE, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " sum_due: {0}".format(sum_due)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_DUE_FAIL + sp.pack_single_int32(sum_due)
        else:
            ans = self.TAXES_DUE_OK + sp.pack_single_int32(sum_due)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key) + len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key) + len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf) - len(resp.result))
        # read result
        buf = buf[len(buf) - len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 49
0
    def __init__(self, ftype='DES_TYPE', name=''):
        self.ftype = FOOD_TYPE[ftype]
        self.name = name

        if '' == self.name:
            self.name = sp.random_string(randint(1, CONFIG['DES_NAME_SZ'] - 1))
Ejemplo n.º 50
0
    def upload_form(self):
        '''
        Upload a tax form
        '''
        if DEBUG:
            print "cmd: upload form"

        s_invalid = False
        t4d_invalid = False
        s = self._get_random_session()

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.UPLOAD_FORM, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            t4d = TenFourD(tp)
            t4d.gen_totals_and_ds()
            for t in tp.tax_forms:
                if t.tax_year == t4d.tax_year:
                    t4d_invalid = True
                    break

            s = Session(s.key, tp, self.UPLOAD_FORM, t4d.gen_bytes())

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.UPLOAD_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == t4d_invalid:
            res = self.ERR
            ans = self.UPLOAD_FAIL
        else:
            # add t4d to taxpayer
            tp.tax_forms.append(t4d)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print s
            print tp
            print t4d
            print resp

        buf = resp.gen_bytes()
        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key) + len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key) + len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf) - len(resp.result))
        # read result
        buf = buf[len(buf) - len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 51
0
	def _ask(self):
		'''
		Process the act of asking the other player for cards having a given rank.
		'''
		turn = self.state['g'].get_turn_pid()
		if True == self.DEBUG_FUNC:
			print "pid {0} asking.".format(turn)

		FAIL = ''

		rank = self.state['g'].ask_rank()
		msg = sp.serialize_ask(rank)
		if 0 == turn:
			if self.chance(self.FAIL_CHANCE): # invliad rank
				msg = sp.serialize_ask(20)
				FAIL = 'ERR_INVALID_RANK'
			elif self.chance(self.FAIL_CHANCE): # wrong tags for this msg
				# length needs to be 7
				msg = sp.serialize_fishing() # len 4
				msg = msg[:-1] + msg # len 3 + 4
				FAIL = 'ERR_INVALID_XML'

			self.write(msg)
		else:
			self.read(length=len(msg), expect=msg)

		if True == self.DEBUG_FUNC:
			print "  asked for rank {0}.".format(rank)

		if '' != FAIL:
			self._recv_error(FAIL)
			return -1


		qty = self.state['g'].ask_response_qty(rank)
		msg = sp.serialize_go_fish(qty)
		if 0 == turn:
			self.read(length=len(msg), expect=msg)
		else:
			if self.chance(self.FAIL_CHANCE): # total junk
				msg = sp.pack_single_string(sp.random_string(5,5))
				FAIL = 'ERRNO_RECV'
			elif self.chance(self.FAIL_CHANCE): # wrong qty
				msg = sp.serialize_go_fish(6)
				FAIL = 'ERR_INVALID_QTY'
			elif self.chance(self.FAIL_CHANCE): # correct len, wrong tags for this msg
				msg = sp.serialize_fishing()
				msg = msg[1] + msg
				FAIL = 'ERR_INVALID_XML'
			elif self.chance(self.FAIL_CHANCE): # too short, wrong tags for this msg
				msg = sp.serialize_fishing()
				FAIL = 'ERRNO_RECV'


			self.write(msg)

		if True == self.DEBUG_FUNC:
			print "  asked player has qty {0}.".format(qty)

		if '' != FAIL:
			self._recv_error(FAIL)
			return -1


		if 0 == qty:
			return self._fishing(rank)
		else:
			return self._ask_give_cards(rank)
Ejemplo n.º 52
0
    def taxes_due(self):
        '''
        Determine total amount of tax due (+) or to be refunded (-)
        '''
        if DEBUG:
            print "cmd: taxes due"

        s_invalid = False
        s = self._get_random_session()
        tdo = DateRange(randint(0, 0xfff), randint(0, 0xffff))
        tdo_invalid = False
        sum_due = 0

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, self.TAXES_DUE, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            if False == tdo.is_valid():
                tdo_invalid = True
            else:
                sum_due = tp.get_sum_taxes_due(tdo.start_date, tdo.end_date)

            s = Session(s.key, tp, self.TAXES_DUE, tdo.gen_bytes())

        if DEBUG:
            print tdo
            print " sum_due: {0}".format(sum_due)

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.TAXES_DUE_OK
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == tdo_invalid:
            res = self.ERR
            ans = self.TAXES_DUE_FAIL + sp.pack_single_int32(sum_due)
        else:
            ans = self.TAXES_DUE_OK + sp.pack_single_int32(sum_due)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(
                len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key) + len(resp.answer)]
            buf = buf[len(resp.s_key) + len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(
                len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))

        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(
                len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 53
0
    def pov_2(self):
        '''
        Create a new account
        '''

        if DEBUG:
            print "cmd: create account -----------"
        # create account
        tp = self._gen_random_taxpayer()

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.CREATE_ACCOUNT,
                    tp.gen_new_taxpayer_data_bytes())
        buf = s.gen_bytes()
        self.write(buf)

        # read s_key
        self.read(length=12)
        # read password
        self.read(length=12, assign=self.state['pwd'])
        # read the rest
        self.read(length=8 + 128 - 12)
        tp.password = "******" * 12

        if DEBUG:
            print "cmd: login -----------"
        s_key = sp.random_string(12)
        s_loggedin = Session(s_key, tp, self.LOGIN, "")
        (buf1, buf2) = s_loggedin.gen_bytes2()
        self.write(buf1)
        self.write(self.state['pwd'])
        self.write(buf2)

        self.read(length=12 + 128 + 8)

        if DEBUG:
            print "cmd: upload form -----------"
        # 64 will fill buffer to max

        tf_year = randint(0, 0xEFFF)
        for _ in range(64):
            t4d = TenFourD(tp)
            t4d.tax_year = tf_year
            tf_year += 1

            t4d.gen_totals_and_ds()
            tp.tax_forms.append(t4d)

            s = Session(s_key, tp, self.UPLOAD_FORM, t4d.gen_bytes())
            (buf1, buf2) = s.gen_bytes2()
            self.write(buf1)
            self.write(self.state['pwd'])
            self.write(buf2)

            self.read(length=12 + 128 + 8)

        # 1st & 2nd tax_year beyond buffer will overwrite fn ptr
        # 4 more to fill in
        # last 2 tax_years will overwite *r
        # EIP = 0x1FFF0FFF
        # EDX = 0xFBB0FBBF
        for tf_year2 in [
                0x0FFF, 0x1FFF, tf_year + 1, tf_year + 2, tf_year + 3,
                tf_year + 4, 0xFBBF, 0xFBB0
        ]:
            t4d = TenFourD(tp)
            t4d.tax_year = tf_year2

            t4d.gen_totals_and_ds()
            tp.tax_forms.append(t4d)

            s = Session(s_key, tp, self.UPLOAD_FORM, t4d.gen_bytes())
            (buf1, buf2) = s.gen_bytes2()
            self.write(buf1)
            self.write(self.state['pwd'])
            self.write(buf2)

            self.read(length=12 + 128 + 8)

        if DEBUG:
            print "cmd: taxes submitted"

        tdo = DateRange(0, 0xffff)

        years = tp.get_list_submitted_tax_years(tdo.start_date, tdo.end_date)
        if DEBUG and [] == years:
            print " NO YEARS!"

        s = Session(s_key, tp, self.TAXES_SUBMITTED, tdo.gen_bytes())
        (buf1, buf2) = s.gen_bytes2()
        self.write(buf1)
        self.write(self.state['pwd'])
        self.write(buf2)

        self.read(length=12 + 128 + 8)
Ejemplo n.º 54
0
    def login(self):
        '''
        Login to establish a session
        '''
        if DEBUG:
            print "cmd: login -----------"

        tp_invalid = False
        tp = self.state['s'].get_rand_taxpayer()
        if False == isinstance(tp, TaxPayer):
            # create invalid taxpayer to trigger fail paths
            tp = self._gen_random_taxpayer()
            tp_invalid = True

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.LOGIN, "")

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.LOGIN_OK
        if tp.username in self.state['sessions']:
            res = self.ERR

            # taxpayer is already logged in
            s_old = self.state['sessions'][tp.username]
            if s_old.key != s.key:
                ans = self.LOGIN_FAIL
            else:
                ans = self.NICE_TRY
        elif True == tp_invalid:
            # taxpayer has not registered or provided invalid creds
            res = self.ERR
            ans = self.LOGIN_FAIL
        else:
            # rock on
            self.state['sessions'][tp.username] = s

        resp = Response(s_key, ans, res)

        if DEBUG:
            print s
            print resp

        buf = resp.gen_bytes()

        if res == self.ERR:
            # cannot match key on ERR conditions, so trim
            # it and assign it to regex
            self.read(length=len(resp.s_key), assign=self.state['randkey'])
            buf = buf[len(resp.s_key):]
            self.read(length=len(resp.answer))
            buf = buf[len(resp.answer):]
        else:
            st = buf[:len(resp.s_key) + len(resp.answer)]
            self.read(length=len(st))
            buf = buf[len(resp.s_key) + len(resp.answer):]

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so ignore them.
        self.read(length=len(buf) - len(resp.result))
        # read result
        buf = buf[len(buf) - len(resp.result):]
        self.read(length=len(buf))

        return 0
Ejemplo n.º 55
0
	def start(self):
		self.state['g'] = GoFish(sp.random_string(5, 20))
Ejemplo n.º 56
0
    def get_audited(self):
        '''
        Get audited.
        '''
        if DEBUG:
            print "cmd: get audited"

        s_invalid = False
        s = self._get_random_session()
        a_invalid = False
        cmd = self.TRIGGER_AUDIT
        if self.chance(0.4):
            cmd = self.TRIGGER_AUDIT2

        if None == s:
            # create invalid session to trigger fail paths
            tp = self._gen_random_taxpayer()

            s_key = sp.random_string(12)
            s = Session(s_key, tp, cmd, "")
            s_invalid = True
        else:
            tp = self.state['s'].get_taxpayer_by_username(s.username)
            s = Session(s.key, tp, cmd, "")

        buf = s.gen_bytes()
        self.write(buf)

        ar = AuditRecord(tp)
        if tp.id in self.state['s'].audits:
            a_invalid = True

        res = self.OK
        ans = self.LUCKY_DAY
        if True == s_invalid:
            res = self.ERR
            ans = self.NICE_TRY
        elif True == a_invalid:
            res = self.ERR
            ans = self.AUDIT_FAIL
        elif 0 == len(ar.tax_years):
            ans = self.LUCKY_DAY
        else:
            ans = self.YOU_WIN + ''.join(
                [sp.pack_single_uint16(y) for y in ar.tax_years])
            self.state['s'].audit_taxpayer(ar)

            if DEBUG:
                print "audit years: {0}".format(ar.tax_years)

        resp = Response(s.key, ans, res)
        if DEBUG:
            print resp

        buf = resp.gen_bytes()

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(
                len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key) + len(resp.answer)]
            buf = buf[len(resp.s_key) + len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(
                    len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(
                len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))

        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(
                len(buf), sp.hexify(buf))

        return 0
Ejemplo n.º 57
0
    def login(self):
        '''
        Login to establish a session
        '''
        if DEBUG:
            print "cmd: login -----------"

        tp_invalid = False
        tp = self.state['s'].get_rand_taxpayer()
        if False == isinstance(tp, TaxPayer):
            # create invalid taxpayer to trigger fail paths
            tp = self._gen_random_taxpayer()
            tp_invalid = True

        s_key = sp.random_string(12)
        s = Session(s_key, tp, self.LOGIN, "")

        buf = s.gen_bytes()
        self.write(buf)

        res = self.OK
        ans = self.LOGIN_OK
        if tp.username in self.state['sessions']:
            res = self.ERR

            # taxpayer is already logged in
            s_old = self.state['sessions'][tp.username]
            if s_old.key != s.key:
                ans = self.LOGIN_FAIL
            else:
                ans = self.NICE_TRY
        elif True == tp_invalid:
            # taxpayer has not registered or provided invalid creds
            res = self.ERR
            ans = self.LOGIN_FAIL
        else:
            # rock on
            self.state['sessions'][tp.username] = s

        resp = Response(s_key, ans, res)

        if DEBUG:
            print " Username: {0}".format(tp.username)
            print " Response: K:{0}, A:{1}, R:{2} {3}".format(len(resp.s_key), len(resp.answer), len(resp.result), resp)

        buf = resp.gen_bytes()

        if DEBUG:
            print " resp buf: ({0}) {1}".format(len(buf), sp.hexify(buf))
            print "         as text {0}".format(buf)

        if res == self.ERR:
            # cannot match key on ERR conditions, so just read len
            e = buf[:len(resp.s_key)]
            buf = buf[len(resp.s_key):]
            self.read(length=len(e))
            if DEBUG:
                print " read resp.s_key = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

            e = buf[:len(resp.answer)]
            buf = buf[len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        else:
            e = buf[:len(resp.s_key)+len(resp.answer)]
            buf = buf[len(resp.s_key)+len(resp.answer):]
            self.read(length=len(e), expect=e)
            if DEBUG:
                print " read resp.s_key + resp.answer = ({0}) {1}".format(len(e), sp.hexify(e))
                print "  new buf {0}".format(sp.hexify(buf))

        # we've read the key and answer, the rest of the answer bytes are
        # junk, so just read len
        e = buf[:-len(resp.result)]
        buf = buf[-len(resp.result):]
        self.read(length=len(e))
        if DEBUG:
            print " read -len(resp.result) = ({0}) {1}".format(len(e), sp.hexify(e))
            print "  new buf {0}".format(sp.hexify(buf))


        self.read(length=len(buf), expect=buf)
        if DEBUG:
            print " read final len(buf) = ({0}) {1}".format(len(buf), sp.hexify(buf))

        return 0