summaryrefslogtreecommitdiffstats
path: root/functest/utils/functest_vacation.py
blob: c2e40b07243f98162d97631168cdbea81811df95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from os import environ
from curses import initscr, curs_set, newwin, endwin
from curses import KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_UP
from random import randrange


def main():
    environ["TERM"] = 'Eterm'
    initscr()
    curs_set(0)
    try:
        win = newwin(16, 60, 0, 0)
        win.keypad(True)
        win.nodelay(True)
        win.border('|', '|', '-', '-', '+', '+', '+', '+')
        win.addch(4, 44, '@')
        win.addstr(0, 5, ' Eat all the OPNFV bugs by FunTest! ')
        win.addstr(15, 7, ' Left,Right,Up,Down: move; other keys: quit ')
        snake = [[20, 7], [19, 7], [18, 7], [17, 7],
                 [16, 7], [15, 7], [14, 7], [13, 7]]
        key = KEY_RIGHT
        body = '~FUNTEST'
        ind = 0
        while key != 27:
            win.addstr(0, 44, ' Score: ' + str(len(snake) - len(body)) + ' ')
            win.timeout(140 - 2 * len(snake))
            getkey = win.getch()
            key = key if getkey == -1 else getkey
            snake.insert(
                0, [snake[0][0] + (key == KEY_RIGHT and 1 or
                                   key == KEY_LEFT and -1),
                    snake[0][1] + (key == KEY_DOWN and 1 or
                                   key == KEY_UP and -1)])
            win.addch(snake[len(snake) - 1][1], snake[len(snake) - 1][0], ' ')
            if win.inch(snake[0][1], snake[0][0]) & 255 == 32:
                snake.pop()
            elif win.inch(snake[0][1], snake[0][0]) & 255 == ord('@'):
                c = [n for n in [[randrange(1, 58, 1), randrange(1, 14, 1)]
                     for x in range(len(snake))] if n not in snake]
                win.addch(c == [] and 4 or c[0][1],
                          c == [] and 44 or c[0][0], '@')
            else:
                break
            ind += 1
            win.addch(snake[0][1], snake[0][0], body[ind % len(body)])
    finally:
        endwin()

    print '\nSnake.PY-26lines by Kris Cieslak (defaultset.blogspot.com).'
    print 'OPNFV adaptation by Functest dream team.'
    score = str(len(snake) - len(body) - 1)
    print ('Thanks for playing, your score: %s.' % score)
    print 'Find and fix more bugs in your real OPNFV setup!\n'
raise exceptions.AuthzException("Cannot connect to Authz function") self.context.set_cache(CACHE) if req and len(self.container_chaining) == 1: self.result = pickle.loads(req.content) # def __exec_next_state(self, rule_found): # index = self.context.index # current_meta_rule = self.context.headers[index] # current_container = self.__get_container_from_meta_rule(current_meta_rule) # current_container_genre = current_container["genre"] # try: # next_meta_rule = self.context.headers[index + 1] # except IndexError: # next_meta_rule = None # if current_container_genre == "authz": # if rule_found: # return True # pass # if next_meta_rule: # # next will be session if current is deny and session is unset # if self.payload["authz_context"]['pdp_set'][next_meta_rule]['effect'] == "unset": # return notify( # request_id=self.payload["authz_context"]["request_id"], # container_id=self.__get_container_from_meta_rule(next_meta_rule)['container_id'], # payload=self.payload) # # next will be delegation if current is deny and session is passed or deny and delegation is unset # else: # LOG.error("Delegation is not developed!") # # else: # # else next will be None and the request is sent to router # return self.__return_to_router() # elif current_container_genre == "session": # pass # # next will be next container in headers if current is passed # if self.payload["authz_context"]['pdp_set'][current_meta_rule]['effect'] == "passed": # return notify( # request_id=self.payload["authz_context"]["request_id"], # container_id=self.__get_container_from_meta_rule(next_meta_rule)['container_id'], # payload=self.payload) # # next will be None if current is grant and the request is sent to router # else: # return self.__return_to_router() # elif current_container_genre == "delegation": # LOG.error("Delegation is not developed!") # # next will be authz if current is deny # # next will be None if current is grant and the request is sent to router def set_result(self, result): self.result = result def is_authz(self): if not self.result: return False authz_results = [] for key in self.result.pdp_set: if "effect" in self.result.pdp_set[key]: if self.result.pdp_set[key]["effect"] == "grant": # the pdp is a authorization PDP and grant the request authz_results.append(True) elif self.result.pdp_set[key]["effect"] == "passed": # the pdp is not a authorization PDP (session or delegation) and had run normally authz_results.append(True) elif self.result.pdp_set[key]["effect"] == "unset": # the pdp is not a authorization PDP (session or delegation) and had not yep run authz_results.append(True) else: # the pdp is (or not) a authorization PDP and had run badly authz_results.append(False) if list(itertools.accumulate(authz_results, lambda x, y: x & y))[-1]: self.result.pdp_set["effect"] = "grant" if self.result: if self.result.pdp_set["effect"] == "grant": self.final_result = "Grant" return True self.final_result = "Deny" return True