Skip to content

Commit

Permalink
fix #375 -all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Lvov committed Jul 14, 2016
1 parent 88ce8f8 commit a512a8e
Showing 1 changed file with 68 additions and 48 deletions.
116 changes: 68 additions & 48 deletions tempesta_fw/t/functional/tests/test_frang.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@
from os.path import dirname, realpath, sep
import time
import types
#sys.path.append('./tests/helpers')
sys.path.append(dirname(realpath(__file__))+ sep + sep + "helpers")


import conf
import tfw
from socket import *
import select
import binascii
import struct

global tcount

tcount = 0

class Test:
def __init__(self):
self.vs_get = b"GET / HTTP/1.0\r\nhost: loc\r\n"
self.vs_get = b"GET / HTTP/1.0\r\nhost: loc\r\n\r\n"
self.s = socket(AF_INET, SOCK_STREAM)

self.cfg = conf.Config('etc/tempesta_fw.conf')
self.cfg.add_option('cache', '0')
self.cfg.add_option('listen', '8081')
self.cfg.add_option('server', '127.0.0.1:80')

def uri_len(self):
global tcount

self.res = False
print("uri\n")
self.__init__()
Expand All @@ -44,18 +45,20 @@ def uri_len(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1
except OSError as e:
print(e)
print("res:", self.res)
time.sleep(5)
tfw.stop()
print("res:", self.res)

def request_rate(self):
global tcount

self.res = False
print("req_rate\n")
self.__init__()
self.cfg.add_section('frang_limits')
# self.cfg.add_option('request_rate', '5')
self.cfg.add_option('request_burst', '1')

self.cfg.add_end_of_section()
Expand All @@ -69,17 +72,18 @@ def request_rate(self):
try:
for x in range(0, 15):
self.s.sendall(self.vs_get)
# data = self.s.recv(1024)

except OSError as e:
self.res = True
tcount += 1

self.s.close()
print("res:", self.res)
time.sleep(5)
tfw.stop()

def request_burst(self):
global tcount
self.res = False
print("req_burst\n")
self.__init__()
Expand All @@ -91,32 +95,31 @@ def request_burst(self):
print("tfw start\n")
self.s.connect(("127.0.0.1",8081))


self.vs_get = b"GET / HTTP/1.0\r\nhost: loc\r\n" +\
b"Connection: Keep-Alive\r\n\r\n"
try:
for x in range(0, 15):
self.s.sendall(self.vs_get)
# data = self.s.recv(1024)

except OSError as e:
self.res = True
tcount += 1

self.s.close()
print("res:", self.res)
time.sleep(5)
tfw.stop()

def conn_max(self):
global tcount
self.res = False
print("conn_max\n")
self.__init__()
self.cfg.add_section('frang_limits')
self.cfg.add_option('ip_block', 'on')
self.cfg.add_option('concurrent_connections', '5')


self.cfg.add_end_of_section()
self.cfg.add_option('keepalive_timeout', '3')
tfw.start_with_frang()
print("tfw start\n")
self.vs_get = b"GET / HTTP/1.0\r\nhost: loc\r\n" +\
Expand All @@ -126,39 +129,33 @@ def conn_max(self):
socks = []
conncount = 0
port = 8095
for x in range(0,3):
for x in range(0,7):
s = socket(AF_INET, SOCK_STREAM)
s.settimeout(2)
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
s.bind(('127.0.0.6', port))
s.connect(("127.0.0.1", 8081))
s.send(self.vs_get)
socks.append(s)
print(len(socks))
conncount += 1
port += conncount
# time.sleep(0.55555)
except OSError as e:
print("max except:", e)
self.res = True
tcount += 1

print("res:", self.res)
# self.s.shutdown(SHUT_RDWR)
# self.s.close()
for s in socks:
s.shutdown(SHUT_RDWR)
s.close()
# socks.remove(s)
del s
# time.sleep(0.2)

del socks
print("sks:", "after del")

# time.sleep(5)
# tfw.stop()
# tfw.del_db()
print("res:", self.res)
time.sleep(5)
tfw.stop()
tfw.del_db()

def conn_rate(self):
global tcount
self.res = False
print("conn_rate\n")
self.__init__()
Expand Down Expand Up @@ -186,6 +183,7 @@ def conn_rate(self):

except OSError as e:
self.res = True
tcount += 1

print("res:", self.res)
self.s.shutdown(SHUT_RDWR)
Expand All @@ -194,6 +192,8 @@ def conn_rate(self):
tfw.stop()
tfw.del_db()
def ct_required(self):
global tcount

print("ct_required")
self.res = False
self.__init__()
Expand All @@ -210,13 +210,16 @@ def ct_required(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1

print("res:", self.res)
self.s.close()
time.sleep(5)
tfw.stop()

def conn_burst(self):
global tcount

self.res = False
print("conn_burst\n")
self.__init__()
Expand Down Expand Up @@ -244,6 +247,7 @@ def conn_burst(self):

except OSError as e:
self.res = True
tcount += 1

print("res:", self.res)
self.s.shutdown(SHUT_RDWR)
Expand All @@ -253,6 +257,8 @@ def conn_burst(self):
tfw.del_db()

def host_required(self):
global tcount

print("host_required")
self.res = False
self.__init__()
Expand All @@ -269,13 +275,16 @@ def host_required(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1

print("res:", self.res)
self.s.close()
time.sleep(5)
tfw.stop()

def body_len(self):
global tcount

print("body_len")
self.res = False
self.__init__()
Expand All @@ -295,13 +304,16 @@ def body_len(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1

print("res:", self.res)
self.s.close()
time.sleep(5)
tfw.stop()

def field_len(self):
global tcount

print("field_len")
self.res = False
self.__init__()
Expand All @@ -321,6 +333,7 @@ def field_len(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1

print("res:", self.res)
self.s.close()
Expand All @@ -329,6 +342,8 @@ def field_len(self):


def ct_vals(self):
global tcount

print("ct_vals")
self.res = False
self.__init__()
Expand All @@ -345,13 +360,16 @@ def ct_vals(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1

print("res:", self.res)
self.s.close()
time.sleep(5)
tfw.stop()

def req_method(self):
global tcount

print("req_method")
self.res = False
self.__init__()
Expand All @@ -368,19 +386,16 @@ def req_method(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1

print("res:", self.res)
self.s.close()
time.sleep(5)
tfw.stop()
def header_chunks(self):
print("header_chunks\n")
# self.vs_get = b'GET / HTTP/1.0\r\nhost: local\r\n\r\n'
global tcount

# self.vs_get = b"GET / HTTP/1.0\r\nHost: loc\r\n" +\
# b"Content-Type: application/xml\r\n" +\
# b"Content-Length: 20\r\n\r\n" +\
# b"<html>content</html>\r\n\r\n"
print("header_chunks\n")

part1 = b'GET / HTTP/1.0\r\n'
part2 = b'host: loc\r\n'
Expand All @@ -396,17 +411,18 @@ def header_chunks(self):
self.s.send(part1)
self.s.send(part2)
self.s.send(part3)
# self.s.send(self.vs_get)
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1
self.s.close()
time.sleep(5)
tfw.stop()
print("res:", self.res)


def header_timeout(self):
global tcount
part1 = b'GET / HTTP/1.0\r\n'
part2 = b'host: loc\r\n\r\n'
self.__init__()
Expand All @@ -421,9 +437,16 @@ def header_timeout(self):
time.sleep(1)
self.s.send(part2)
data = self.s.recv(1024)
print(data)
if len(data) == 0:
tcount += 1
self.res = True
print( "res:", self.res)
self.s.close()
time.sleep(5)
tfw.stop()

def body_timeout(self):
global tcount
print("body_timeout")
part1 = b"POST /a.html HTTP/1.0\r\nHost: loc\r\n" +\
b"Content-Type: text/html\r\n" +\
Expand All @@ -445,11 +468,13 @@ def body_timeout(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1
print("res:", self.res)
time.sleep(5)
tfw.stop()

def body_chunks(self):
global tcount
print("body_chunks")
part1 = b"POST /a.html HTTP/1.0\r\nHost: loc\r\n" +\
b"Content-Type: text/html\r\n" +\
Expand All @@ -473,6 +498,7 @@ def body_chunks(self):
data = self.s.recv(1024)
if len(data) == 0:
self.res = True
tcount += 1
print("res:", self.res)
time.sleep(5)
tfw.stop()
Expand All @@ -482,25 +508,19 @@ def body_chunks(self):
def get_name(self):
return 'test Frang'
def run(self):
# tests = [self.body_chunks()]
tests = [self.body_chunks(), self.header_chunks(),\
self.conn_burst(),\
self.request_burst(),\
self.body_timeout(),\
self.field_len(),\
self.body_len(),\
self.host_required(), \
self.ct_required(), self.req_method(), self.ct_vals(), self.uri_len(),\
self.request_rate(),\
self.conn_rate()]

tcount = 0
self.conn_burst(), self.request_burst(),\
self.body_timeout(), self.field_len(), self.body_len(),\
self.host_required(), self.ct_required(), self.req_method(),\
self.ct_vals(), self.uri_len(), self.request_rate(), self.conn_rate(),\
self.conn_max()]

for f in tests:
tcount += 1
if hasattr(f, '__call__'):
f()

print("tests:{}".format(tcount))

print("tests:{}/15".format(tcount))

t = Test()
t.run()
Expand Down

0 comments on commit a512a8e

Please sign in to comment.