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 54 55 56 57 58 59 60 61 62 63
|
import requests
import socket
import re
import os
import time
import json
import mmap
from test_helper import ApiTestCase
class TestTrackalert(ApiTestCase):
def test_auth_stats(self):
r = self.session.get(self.ta_url("/?command=stats"))
self.assertEqual(r.status_code, requests.codes.ok)
def test_wforceToTrackalert(self):
self.writeCmdToConsole("addWebHook(ta_events, tack)")
r = self.reportFunc('wforce2trackalert', '1.4.3.2', '1234', False);
j = r.json()
self.assertEqual(j['status'], 'ok')
time.sleep(5)
logfile = open('/tmp/trackalert.log', 'r')
s = mmap.mmap(logfile.fileno(), 0, access=mmap.ACCESS_READ)
search_str = s.read(s.size()).decode()
for mystring in [ 'login=wforce2trackalert', 'remote=1.4.3.2' ]:
regex = re.escape(mystring)
result = re.search(regex, search_str);
self.assertNotEqual(result, None)
s.close()
logfile.close()
def test_trackalertReport(self):
attrs = dict()
attrs['accountStatus'] = "normal"
r = self.taReportFuncAttrs('tareportuser', '127.0.0.1', 'foo', True, attrs)
j = r.json()
time.sleep(5)
logfile = open('/tmp/trackalert.log', 'r')
s = mmap.mmap(logfile.fileno(), 0, access=mmap.ACCESS_READ)
search_str = s.read(s.size()).decode()
for mystring in [ 'login=tareportuser', 'remote=127.0.0.1' ]:
regex = re.escape(mystring)
result = re.search(regex, search_str);
self.assertNotEqual(result, None)
s.close()
logfile.close()
def test_trackalertBackgroundFuncs(self):
time.sleep(61)
logfile = open('/tmp/trackalert.log', 'r')
s = mmap.mmap(logfile.fileno(), 0, access=mmap.ACCESS_READ)
search_str = s.read(s.size()).decode()
for mystring in [ 'background1', 'background2' ]:
regex = re.escape(mystring)
result = re.search(regex, search_str);
self.assertNotEqual(result, None)
s.close()
logfile.close()
def test_trackalertCustomFunc(self):
r = self.trackalertCustomFunc("custom1")
j = r.json()
self.assertEqual(j['r_attrs']['login'], 'custom1')
|