示例#1
0
 def test_g_agrega_ip_a_red_existente(self):
     data = {"dns1": "5.5.5.5", "dns2": "5.5.5.5", "nombre": "test"}
     data2 = {
         "dns1": "10.10.10.10",
         "dns2": "10.10.10.10",
         "nombre": "test"
     }
     self.assertEqual(IPContainer.addIPtoNetwork("test_user1", "dns",
                                                 data), True,
                      "IP agregada 1 a la red existente correctamente")
     self.assertEqual(
         IPContainer.addIPtoNetwork("test_user1", "dns", data2), True,
         "IP agregada 2 a la red existente correctamente")
示例#2
0
def addAPIUser(current_user):
    if current_user._admin:
        data = request.get_json()
        done = IPContainer.addAPIUser(data['username'], data['password'])
        return jsonify(success=done)

    return jsonify(message="You're not an admin.")
示例#3
0
def login():
    auth = request.authorization

    if not auth or not auth.username or not auth.password:
        return make_response(
            'Could not verify.', 401,
            {'WWW-Authenticate': 'Basic realm="Login required."'})

    return IPContainer.login(auth.username, auth.password)
示例#4
0
 def test_m_vaciar_tablas(self):
     IPContainer._dropUsers()
     self.assertEqual(IPContainer.getNumberOfUsers(), 0,
                      "Tabla usuarios vaciada.")
     IPContainer._dropData()
     self.assertEqual(IPContainer.getNumberOfUsers(), 0,
                      "Tabla datos vaciada.")
示例#5
0
 def test_b_agrega_usuarios(self):
     IPContainer.addUser("test_user1")
     self.assertEqual(IPContainer.existUser("test_user1"), True,
                      "Usuario 1 agregado correctamente.")
     IPContainer.addUser("test_user2")
     self.assertEqual(IPContainer.existUser("test_user2"), True,
                      "Usuario 2 agregado correctamente.")
示例#6
0
    def decorated(*args, **kwargs):
        token = None

        if 'x-access-token' in request.headers:
            token = request.headers['x-access-token']

        if not token:
            return jsonify(message="Token is missing."), 401

        current_user = IPContainer.tokenAccess(str(token))

        if not current_user:
            return jsonify(message="Token is invalid."), 401

        return f(current_user, *args, **kwargs)
示例#7
0
 def test_c_elimina_usuario(self):
     IPContainer.removeUser("test_user2")
     self.assertEqual(IPContainer.existUser("test_user2"), False,
                      "Usuario eliminado correctamente.")
     self.assertEqual(IPContainer.getNumberOfUsers(), 1,
                      "Usuario test_user2 borrado.")
示例#8
0
def getAPIUser(current_user, public_id):
    return IPContainer.getAPIUser(public_id)
示例#9
0
 def test_l_comprobar_numero_redes(self):
     self.assertEqual(IPContainer.getNumberOfNetworks(), 1,
                      "1 - Numero de redes correcto. (1)")
     IPContainer.createNetwork("test_user3", "wlan")
     self.assertEqual(IPContainer.getNumberOfNetworks(), 2,
                      "2 - Numero de redes correcto. (2)")
示例#10
0
 def test_j_elimina_ip_de_red_no_existente(self):
     self.assertEqual(
         IPContainer.removeIPfromNetwork("test_user1", "pan", "5.5.5.5"),
         False, "IP borrada de la red no existente")
示例#11
0
 def test_h_comprueba_tamanio_red(self):
     self.assertEqual(IPContainer.getNetworkSize("test_user1", "dns"), 2,
                      "Tamanio de red correcto.")
示例#12
0
 def test_f_crea_red_que_ya_existe(self):
     self.assertEqual(IPContainer.createNetwork("test_user1", "dns"), False,
                      "Red existente no creada")
示例#13
0
def existUser(current_user, user):
    return jsonify(exists=IPContainer.existUser(str(user)))
示例#14
0
def getNumberOfUsers(current_user):
    return jsonify(users=IPContainer.getNumberOfUsers())
示例#15
0
def removeUser(current_user, user):
    return jsonify(success=IPContainer.removeUser(str(user)))
示例#16
0
def addUser(current_user, user):
    return jsonify(success=IPContainer.addUser(str(user)))
示例#17
0
def status():
    return IPContainer.getStatus()
示例#18
0
def addAPIUser(current_user):
    data = request.get_json()
    done = IPContainer.addAPIUser(data['username'], data['password'])
    return jsonify(success=done)
示例#19
0
def deleteAPIUser(current_user, public_id):
    return IPContainer.deleteAPIUser(public_id)
示例#20
0
 def test_d_elimina_usuario_que_no_existe(self):
     self.assertEqual(IPContainer.removeUser("test_user5"), False,
                      "No elimina usuario que no existe.")
示例#21
0
 def test_e_crea_red(self):
     IPContainer.createNetwork("test_user1", "dns")
     self.assertEqual(IPContainer.existNetwork("test_user1", "dns"), True,
                      "Nueva red creada correctamente")
示例#22
0
def getNumberOfNetworks(current_user):
    return jsonify(networks=IPContainer.getNumberOfNetworks())
示例#23
0
def _dropData(current_user):
    IPContainer._dropData()
    return jsonify(success=True)
示例#24
0
def existNetwork(current_user, user, _type):
    return jsonify(exists=IPContainer.existNetwork(str(user), str(_type)))
示例#25
0
 def test_i_elimina_ip_de_red_existente(self):
     self.assertEqual(
         IPContainer.removeIPfromNetwork("test_user1", "dns", "5.5.5.5"),
         True, "IP borrada de la red existente")
示例#26
0
def addIPtoNetwork(current_user, user, _type):
    js = request.get_json()
    return jsonify(
        success=IPContainer.addIPtoNetwork(str(user), str(_type), js['data']))
示例#27
0
 def test_k_comprobar_numero_usuarios(self):
     self.assertEqual(IPContainer.getNumberOfUsers(), 1,
                      "Numero de usuarios correcto. (1)")
     IPContainer.addUser("test_user3")
     self.assertEqual(IPContainer.getNumberOfUsers(), 2,
                      "Numero de usuarios correcto. (2)")
示例#28
0
def removeIPfromNetwork(current_user, user, _type):
    js = request.get_json()
    return jsonify(success=IPContainer.removeIPfromNetwork(
        str(user), str(_type), js['ip']))
示例#29
0
def removeNetwork(current_user, user, _type):
    return jsonify(success=IPContainer.removeNetwork(str(user), str(_type)))
示例#30
0
def getAllAPIUsers(current_user):
    return IPContainer.getAllAPIUsers()