#!/usr/bin/env python
# coding: utf-8
'''
注:单个测试用例名的命名必须以Test开始
'''
import json
import unittest
import time
import shutil
import os,socket
import shutil
class Test_testcase001(unittest.TestCase):
#测试用例前期准备
def setUp(self):
pass
#测试用例
def test_testcase001(self):
#策略下发
policy = {'CommandID':"1111111112",'Type':0x0001,'Rule':[{'Rule_SubType':0x0002,'Rule_ValueStart':"http://news.sogou.com/?p=40030300&kw=",'Rule_ValueEnd':"",'Rule_keyWordRange':[]},{'Rule_SubType':0x0007,'Rule_ValueStart':"0080",'Rule_ValueEnd':"0080",'Rule_keyWordRange':[]},{'Rule_SubType':0x0001,'Rule_ValueStart':"news.sogou.com",'Rule_ValueEnd':"",'Rule_keyWordRange':[]},{'Rule_SubType':0x0004,'Rule_ValueStart':socket.inet_aton('10.100.23.2'),"Rule_ValueEnd":socket.inet_aton('10.100.23.2'),'Rule_keyWordRange':[]}]}
#policy1 ={'CommandID':"1111111112",'Type':0x0002,'Rule':[{'Rule_SubType':0x0004,'Rule_ValueStart':socket.inet_aton('10.100.23.2'),"Rule_ValueEnd":socket.inet_aton('10.100.23.2'),'Rule_keyWordRange':[]}]}
self.cu.SetUp_Info_security_management(1,policy,0x0001)
#self.cu.SetUp_Info_security_management(2,policy1,0x0011)
self.cu.SetUp_Flow_results(1)#下发日志上报策略
self.cu.SetUp_information_policy(2)#信安上报策略
self.cu.SetUp_Access_Log(1)#访问日志上报开关
#策略检查
command = ['2','show ctrl-plcy commandid 31313131313131313132']
self.ssh.dpi_policy_check(command)
#command1 = ['show ctrl-plcy commandid 31313131313131313132']
#self.ssh.dpi_policy_check(command1)
#cmp配置
#打流
pcap_name = '0003.pcap'
self.pcap.sendPcaps(pcap_name)
#接收日志
time.sleep(20)
#查看计数
command = ['exit','1','debug','show statistics summary']
self.ssh.Ssh_Show(command)
Information_log = self.server.Information_log_check()#信安日志检测
print Information_log
acess_result = self.sftp.acess_log_check()#访问日志检测
print acess_result
log_expect = [['31313131313131313132', 'telecom-idc', '10.100.23.2', '123.125.125.114', 60573, 80, 'news.sogou.com', '', '', 'http://news.sogou.com/?p=40030300&kw=']]#日志的预期结果
#日志检测
access_expect =[['telecom-idc', '10.100.23.2', '123.125.125.114', '1', '60573', '80', 'news.sogou.com', 'aHR0cDovL25ld3Muc29nb3UuY29tLz9wPTQwMDMwMzAwJmt3PQ==']]
self.assertListEqual(log_expect,Information_log,msg=None)
self.assertListEqual(access_expect,acess_result,msg=None)
#测试用例清除
def tearDown(self):
pass
if __name__ == '__main__':
unittest.main()