コード例 #1
0
ファイル: auth_tests.py プロジェクト: WangWinson/RackHD
class AuthTests(object):

    def __init__(self):
        self.__client = config.api_client
        self.__auth = Auth()
        self.__nodeApi = Nodes()

    @before_class()
    def setup(self):
        """setup test environment"""
        self.__auth.enable()

    @after_class(always_run=True)
    def teardown(self):
        """ restore test environment """
        self.__auth.disable()

    # @test(groups=['enable-auth'])
    # def enable_auth(self):
    #     """ Testing enable auth """
    #     self.__auth.enable()

    @test(groups=['test-nodes-withauth'])
    def test_nodes(self):
        """ Testing GET:/nodes """
        self.__nodeApi.api1_1_nodes_get()
        nodes = loads(self.__client.last_response.data)
        LOG.debug(nodes, json=True)
        assert_not_equal(0, len(nodes), message='Node list was empty!')
コード例 #2
0
 def handle(self):
     try:
         while True:
             auth_info = self.request.recv(1024).decode()
             auth_type, user, pwd = auth_info.split(':')
             auth_user = Auth(user, pwd)
             if auth_type == 'register':
                 status_code = auth_user.register()
                 self.request.sendall(status_code.encode())
             elif auth_type == 'login':
                 user_dict = auth_user.login()
                 if user_dict:
                     self.request.sendall(b'200')
                     self.user_current_path = user_dict['home_path']
                     self.user_home_path = user_dict['home_path']
                     self.user_limit_size = user_dict['limit_size']
                     while True:
                         command = self.request.recv(1024).decode()
                         if not command: continue
                         command_str = command.split()[0]
                         if hasattr(self, command_str):
                             func = getattr(self, command_str)
                             func(command)
                 else:
                     self.request.sendall(b'400')
     except ConnectionResetError as e:
         print('Error:', e)
コード例 #3
0
ファイル: socket_server.py プロジェクト: hukeyy/learn_python
 def handle(self):
     while True:
         try:
             user_info = self.request.recv(1024).decode()
             if not user_info: continue
             Logger.info('[%s:%s] 连接成功.' % self.client_address)
             auth_type = user_info.split(':')[-1]
             auth = Auth(user_info)
             if auth_type == 'register':
                 auth_code = auth.register()
                 self.request.sendall(auth_code.encode())
                 # if auth_code != '201':
                 #     continue
             elif auth_type == 'login':
                 auth_code, user_dict = auth.login()
                 self.user_home_path = user_dict['home_path']
                 self.user_current_path = user_dict['home_path']
                 self.limit_size = user_dict['limit_size']
                 self.request.sendall(auth_code.encode())
                 print('auth_code:', auth_code)
                 if auth_code != '200':
                     continue
                 while True:
                     command = self.request.recv(1024).decode()
                     print(command)
                     if not command: continue
                     command_str = command.split()[0]
                     if hasattr(self, command_str):
                         func = getattr(self, command_str)
                         func(command)
             # cmd = self.request.recv(1024).decode()
         # cmd = input('>>>')
         except ConnectionResetError as e:
             print('Error:', e)
             Logger.info('[%s:%s] 断开连接.' % self.client_address)
             break
コード例 #4
0
from modules.auth import Auth
from apps.models import User
from apps.forms import RegisterUserForm, LoginUserForm

app = Blueprint('users',
                __name__,
                template_folder='templates',
                static_folder='statics')

######################################################
###
### SetUps
###
######################################################

auth = Auth()

######################################################
###
### Routes
###
######################################################


@app.route('/register/', methods=['GET', 'POST'])
def user_register():
    """
        Register an user
    """
    if 'user' in session:
        return redirect('/dashboard/')
コード例 #5
0
ファイル: auth_tests.py プロジェクト: BillyAbildgaard/RackHD
 def teardown(self):
     """ restore test environment """
     Auth.disable()
コード例 #6
0
ファイル: auth_tests.py プロジェクト: BillyAbildgaard/RackHD
 def setup(self):
     """setup test environment"""
     Auth.enable()
コード例 #7
0
ファイル: auth_tests.py プロジェクト: zhaog918/RackHD
 def teardown(self):
     """ restore test environment """
     Auth.disable()
コード例 #8
0
ファイル: auth_tests.py プロジェクト: zhaog918/RackHD
 def setup(self):
     """setup test environment"""
     Auth.enable()
コード例 #9
0
 def handle(self):
     try:
         while True:
             auth_info = self.request.recv(1024).decode()
             # auth_type, user, pwd, email
             n = auth_info.count(':')
             if n == 2:
                 auth_type, user, pwd = auth_info.split(':')
                 auth_user = Auth(user, pwd)
             else:
                 auth_type, user, pwd, email = auth_info.split(':')
                 auth_user = Auth(user, pwd, email)
             if auth_type == 'register':
                 status_code = auth_user.register()
                 self.request.sendall(status_code.encode())
             elif auth_type == 'login':
                 user_dict = auth_user.login()
                 if user_dict:
                     self.request.sendall(b'200')
                     self.user_name = user_dict[0]
                     self.user_current_path = user_dict[2]
                     self.user_home_path = user_dict[2]
                     self.user_limit_size = int(user_dict[3])
                     while True:
                         opt = self.request.recv(1024).decode()
                         if opt == '1':
                             self.chat()
                         elif opt == '2':
                             email = self.getmail(self.user_name)
                             self.request.sendall(email.encode())
                         elif opt == '3':
                             email = self.getmail(self.user_name)
                             print(self.user_name)
                             print(email)
                             self.request.sendall(email.encode())
                         elif opt == '4':
                             receiver = self.request.recv(1024).decode()
                             file = self.request.recv(1024).decode()
                             self.recvfile(receiver, file)
                         elif opt == '5':
                             self.user_current_path = Shared_PATH
                             self.user_home_path = Shared_PATH
                             self.user_limit_size = LIMIT_SIZE
                             while True:
                                 command = self.request.recv(1024).decode()
                                 print(command)
                                 command_str = command.split()[0]
                                 if hasattr(self, command_str):
                                     func = getattr(self, command_str)
                                     func(command)
                         elif opt == '6':
                             while True:
                                 command = self.request.recv(1024).decode()
                                 print(command)
                                 command_str = command.split()[0]
                                 if hasattr(self, command_str):
                                     func = getattr(self, command_str)
                                     func(command)
                         else:
                             pass
                 else:
                     self.request.sendall(b'400')
     except ConnectionResetError as e:
         print('Error:', e)
コード例 #10
0
from modules.contactLog import ContactLog
from modules.mc_server_adapter import start_server, stop_server
from modules.mc_server_observer import State, MCServerObserver
from modules.observer_scheduler import MCServerObserverScheduler

logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
logger.debug(f"Using telebot version {__version__}")

apihelper.ENABLE_MIDDLEWARE = True
apihelper.SESSION_TIME_TO_LIVE = 5 * 60
bot = telebot.TeleBot(config.TOKEN)

my_state = bot.get_me()

auth = Auth(config.USERS)
observer = MCServerObserver(config.LOCAL_ADDRESS)
userLog = ContactLog()

INGORE_MSG_AFTER_S = 60


def forbidden_access(m: Message, rank: Rank):
    if auth.allowed(m.from_user.id, rank):
        return False

    bot.reply_to(
        m,
        f"Sorry {m.from_user.first_name}, but your rank {auth.get_rank(m.from_user.id).name} "
        f"is not high enough")
    return True
コード例 #11
0
ファイル: auth_tests.py プロジェクト: WangWinson/RackHD
 def __init__(self):
     self.__client = config.api_client
     self.__auth = Auth()
     self.__nodeApi = Nodes()