addition: Added start and terminate script + added test_geo script that

test important function in the geo helper
pull/29/head
Sami Mokaddem 2017-12-06 16:23:13 +01:00
parent 968757f81b
commit c714d88977
4 changed files with 171 additions and 0 deletions

19
tests/start_framework.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
GREEN="\\033[1;32m"
DEFAULT="\\033[0;39m"
RED="\\033[1;31m"
[ -z "$DASH_HOME" ] && echo "Needs the env var DASHENV. Run the script from the virtual environment." && exit 1;
conf_dir="${DASH_HOME}/config/"
redis_dir="${DASH_HOME}/../redis/src/"
test_dir="${DASH_HOME}/tests/"
screenName="Misp-Dashboard-test"
screen -dmS "$screenName"
sleep 0.1
echo -e $GREEN"\t* Launching Redis servers"$DEFAULT
screen -S "$screenName" -X screen -t "redis-server" bash -c $redis_dir'redis-server --port 6260; read x'

19
tests/terminate_framework.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
GREEN="\\033[1;32m"
DEFAULT="\\033[0;39m"
RED="\\033[1;31m"
[ -z "$DASH_HOME" ] && echo "Needs the env var DASHENV. Run the script from the virtual environment." && exit 1;
conf_dir="${DASH_HOME}/config/"
redis_dir="${DASH_HOME}/../redis/src/"
redis_dir="../../redis/src/"
test_dir="${DASH_HOME}/tests/"
screenName="Misp-Dashboard-test"
bash -c $redis_dir'redis-cli -p 6260 shutdown'
screen -S $screenName -X quit

58
tests/test_config.cfg Normal file
View File

@ -0,0 +1,58 @@
[Dashboard]
#hours
graph_log_refresh_rate = 1
#sec
rotation_wait_time = 30
max_img_rotation = 10
hours_spanned = 48
zoomlevel = 15
# [1->12]
size_dashboard_left_width = 5
size_openStreet_pannel_perc = 55
size_world_pannel_perc = 35
item_to_plot = Attribute.category
fieldname_order=["Event.id", "Attribute.Tag", "Attribute.category", "Attribute.type", ["Attribute.value", "Attribute.comment"]]
char_separator=||
[GEO]
#min
updateFrequency = 60
zoomlevel = 11
# ~meter
clusteringDistance = 10
[CONTRIB]
max_number_of_last_contributor = 10
min_between_reload = 5
additional_help_text = ["Sightings multiplies earned points by 2", "Editing an attribute earns you the same as creating one"]
[Log]
directory=logs
filename=logs.log
[RedisGlobal]
host=localhost
port=6250
#misp_web_url = http://192.168.56.50
misp_web_url = https://misppriv.circl.lu
#zmq_url=tcp://192.168.56.50:50000
zmq_url=tcp://localhost:9990
[RedisLIST]
db=3
listName=bufferList
[RedisLog]
db=0
channel=1
channelLastContributor = lastContributor
channelLastAwards = lastAwards
[RedisMap]
db=1
channelDisp=PicToDisplay
pathMaxMindDB=../data/GeoIP2-City_20171017/GeoIP2-City.mmdb
path_countrycode_to_coord_JSON=../data/country_code_lat_long.json
[RedisDB]
db=2

75
tests/test_geo.py Executable file
View File

@ -0,0 +1,75 @@
#!/usr/bin/env python3.5
import configparser
import redis
import sys,os
import datetime
sys.path.append('..')
configfile = 'test_config.cfg'
cfg = configparser.ConfigParser()
cfg.read(configfile)
serv_redis_db = redis.StrictRedis(
host='localhost',
port=6260,
db=1)
from helpers import geo_helper
geo_helper = geo_helper.Geo_helper(serv_redis_db, cfg)
categ = 'Network Activity'
def wipeRedis():
serv_redis_db.flushall()
def errorExit():
wipeRedis()
sys.exit(1)
def test():
today = datetime.datetime.now()
# IP -> Coord
supposed_ip = '8.8.8.8'
geo_helper.getCoordFromIpAndPublish(supposed_ip, categ)
rep = geo_helper.getTopCoord(today)
excpected_result = [['{"lat": 37.751, "lon": -97.822}', 1.0]]
if rep != excpected_result:
print('ip to coord result not matching')
errorExit()
# gethitmap
rep = geo_helper.getHitMap(today)
excpected_result = [['US', 1.0]]
if rep != excpected_result:
print('getHitMap result not matching')
errorExit()
# getCoordsByRadius
rep = geo_helper.getCoordsByRadius(today, today, 0.000, 0.000, '1')
excpected_result = []
if rep != excpected_result:
print('getCoordsByRadius result not matching')
errorExit()
rep = geo_helper.getCoordsByRadius(today, today, 37.750, -97.821, '10')
excpected_result = [[['{"categ": "Network Activity", "value": "8.8.8.8"}'], [-97.82200008630753, 37.75100012475438]]]
if rep != excpected_result:
print('getCoordsByRadius result not matching')
errorExit()
wipeRedis()
# Phone -> Coord
phoneNumber = '(+352) 247-82000'
geo_helper.getCoordFromPhoneAndPublish(phoneNumber, categ)
rep = geo_helper.getTopCoord(datetime.datetime.now())[0]
excpected_result = ['{"lat": "49.7500", "lon": "6.1667"}', 1.0]
if rep != excpected_result:
print('Phone to coord result not matching')
errorExit()
test()
wipeRedis()
print('Tests succeeded')