Example #1
0
    def test_http_check_post_a2(self):

        # 下发配置
        fun.send(rbmExc, message.addhttp['AddAgent'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        add_res1 = fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        assert add_res1 == 1
        # 检查配置下发是否成功
        for key in self.case2_step1:
            re = fun.wait_data(self.case2_step1[key][0], 'gw', self.case2_step1[key][1], '配置', 100)
            print(re)
            assert self.case2_step1[key][1] in re

        fun.send(rbmExc, message.httpcheck2['SetHttpCheck'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        add_res2 = fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        assert add_res2 == 1
        for key in self.case2_step2:
            re = fun.wait_data(self.case2_step2[key][0], 'gw', self.case2_step2[key][1], '配置', 100)
            print(re)
            assert self.case2_step2[key][1] in re

        # 发送post请求,不包含黑名单内容的普通请求
        content = http_check.http_post(url)
        print('多个黑名单时post普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 发送post请求,请求内容不包含黑名单内容
        content = http_check.http_post(url, self.data)
        print('多个黑名单时post请求内容不包含黑名单的请求应返回的内容为:{}'.format(content))
        assert content == http_content

        # 发送post请求,请求内容包含第一个黑名单
        status_code = http_check.http_post(url, self.case2_data1)
        print('多个黑名单时post请求内容包含第一个黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 发送post请求,请求内容包含第二个黑名单
        status_code = http_check.http_post(url, self.case2_data2)
        print('多个黑名单时post请求内容包含第二个黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 移除策略,还原环境
        fun.send(rbmExc, message.delhttp['DelAgent'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        del_res1 = fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        assert del_res1 == 1
        # 检查代理是否成功移除
        for key in self.case2_step1:
            re = fun.wait_data(self.case2_step1[key][0], 'gw', self.case2_step1[key][1], '配置', 100, flag='不存在')
            assert self.case2_step1[key][1] not in re
        # 检查网页访问策略是否清空
        fun.send(rbmExc, message.delhttpcheck['DropHttpCheck'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        del_res2 = fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        assert del_res2 == 1
        for key in self.delcheck:
            re = fun.wait_data(self.delcheck[key][0], 'gw', self.delcheck[key][1], '配置', 100, flag='不存在')
            assert self.delcheck[key][1] not in re
	def test_http_check_uri_a2(self):

		# 下发配置
		fun.send(rbmExc, message.addhttp['AddAgent'], rbmDomain, base_path)
		fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
		fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
		# 检查配置下发是否成功
		for key in self.case2_step1:
			re = fun.wait_data(self.case2_step1[key][0], 'gw', self.case2_step1[key][1], '配置', 100)
			print(re)
			assert self.case2_step1[key][1] in re

		fun.send(rbmExc, message.httpcheck2['SetHttpCheck'], rbmDomain, base_path)
		fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
		fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
		for key in self.case2_step2:
			re = fun.wait_data(self.case2_step2[key][0], 'gw', self.case2_step2[key][1], '配置', 100)
			print(re)
			assert self.case2_step2[key][1] in re

		# 发送get请求,不包含黑名单内容的普通请求
		content = http_check.http_get(url)
		print('多个黑名单时get普通请求的请求内容为:{}'.format(content))
		assert content == http_content

		# 发送post请求,不包含黑名单内容的普通请求
		content = http_check.http_post(url)
		print('多个黑名单时get普通请求的请求内容为:{}'.format(content))
		assert content == http_content

		# 发送get请求,请求内容包含第一个黑名单
		status_code = http_check.http_get(self.case2_uri1,self.data)
		print('多个黑名单时get请求内容包含第一个黑名单返回的状态码为:{}'.format(status_code))
		assert status_code == 403

		# 发送post请求,请求内容包含第一个黑名单
		status_code = http_check.http_post(self.case2_uri1, self.data)
		print('多个黑名单时get请求内容包含第一个黑名单返回的状态码为:{}'.format(status_code))
		assert status_code == 403

		# 发送get请求,请求内容包含第二个黑名单
		status_code = http_check.http_get(self.case2_uri2, self.data)
		print('多个黑名单时get请求内容包含第二个黑名单返回的状态码为:{}'.format(status_code))
		assert status_code == 403

		# 发送post请求,请求内容包含第二个黑名单
		status_code = http_check.http_post(self.case2_uri2, self.data)
		print('多个黑名单时get请求内容包含第二个黑名单返回的状态码为:{}'.format(status_code))
		assert status_code == 403
Example #3
0
    def test_iso_http_basic_a3(self):

        # 下发配置
        fun.send(rbmExc, message.addhttp_front_post['AddCustomAppPolicy'],
                 FrontDomain, base_path)
        fun.send(rbmExc, message.addhttp_back_post['AddCustomAppPolicy'],
                 BackDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut',
                      'nginx: worker process')
        fun.nginx_worker('ps -ef |grep nginx', 'FrontDut',
                         'nginx: worker process')
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        fun.nginx_worker('ps -ef |grep nginx', 'BackDut',
                         'nginx: worker process')
        # 检查配置下发是否成功
        for key in self.case3_step1:
            re = fun.wait_data(self.case3_step1[key][0], 'FrontDut',
                               self.case3_step1[key][1], '配置', 100)
            print(re)
            assert self.case3_step1[key][1] in re

        for key in self.case3_step11:
            re = fun.wait_data(self.case3_step11[key][0], 'FrontDut',
                               self.case3_step11[key][1], '配置', 100)
            print(re)
            assert self.case3_step11[key][1] in re

        #服务器端开启post上传服务

        #发送post请求,验证post请求是否正常
        print('请求地址为{}'.format(self.http_url))
        content = http_check.http_post(self.http_url)
        print('post普通请求的请求内容为:{}'.format(content))

        # 发送post请求,验证隔离下的http策略上传一个10M大小的文件
        print('上传的服务器地址为{}'.format(self.upfile_url))
        result = http_check.http_upload(self.upfile_url, self.upfilename,
                                        self.uplocalPath, self.upMIME_type)
        assert result == 1
Example #4
0
    def test_http_check_get_post_uri_MIME_a1(self):

        # 下发配置
        fun.send(rbmExc, message.addhttp['AddAgent'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        add_res1 = fun.nginx_worker('ps -ef |grep nginx', 'gw',
                                    'nginx: worker process')
        assert add_res1 == 1
        # 检查配置下发是否成功
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0], 'gw',
                               self.case1_step1[key][1], '配置', 100)
            print(re)
            assert self.case1_step1[key][1] in re

        fun.send(rbmExc, message.httpcheck1['SetHttpCheck'], rbmDomain,
                 base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        add_res2 = fun.nginx_worker('ps -ef |grep nginx', 'gw',
                                    'nginx: worker process')
        assert add_res2 == 1
        for key in self.case1_step2:
            re = fun.wait_data(self.case1_step2[key][0], 'gw',
                               self.case1_step2[key][1], '配置', 100)
            print(re)
            assert self.case1_step2[key][1] in re

        # 1、发送get请求,不包含黑名单内容的普通请求
        content = http_check.http_get(url)
        print('1、get普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 2、发送post请求,不包含黑名单内容的普通请求
        content = http_check.http_post(url)
        print('2、post普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 3、发送get请求,请求内容包含第一个get黑名单
        status_code1 = http_check.http_get(url, self.case1_get_data1)
        print('3、get请求内容包含第一个get黑名单返回的状态码为:{}'.format(status_code1))
        assert status_code1 == 403

        # 4、发送get请求,请求内容包含第二个get黑名单
        status_code2 = http_check.http_get(url, self.case1_get_data2)
        print('4、get请求内容包含第二个get黑名单返回的状态码为:{}'.format(status_code2))
        assert status_code2 == 403

        # 5、发送get请求,请求内容包含第一个uri黑名单
        status_code3 = http_check.http_get(self.case1_uri1, self.data)
        print('5、get请求内容包含第一个uri黑名单返回的状态码为:{}'.format(status_code3))
        assert status_code3 == 403

        # 6、发送get请求,请求内容包含第二个uri黑名单
        status_code4 = http_check.http_get(self.case1_uri2, self.data)
        print('6、get请求内容包含第二个uri黑名单返回的状态码为:{}'.format(status_code4))
        assert status_code4 == 403

        # 7、发送get请求,请求内容包含第一个post黑名单
        content = http_check.http_get(url, self.case1_post_data1)
        print('7、get请求内容包含第一个post黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 8、发送get请求,请求内容包含第二个post黑名单
        content = http_check.http_get(url, self.case1_post_data2)
        print('8、get请求内容包含第二个post黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 9、发送post请求,请求内容包含第一个post黑名单
        status_code5 = http_check.http_post(url, self.case1_post_data1)
        print('9、post请求内容包含第一个post黑名单返回的状态码为:{}'.format(status_code5))
        assert status_code5 == 403

        # 10、发送post请求,请求内容包含第二个post黑名单
        status_code6 = http_check.http_post(url, self.case1_post_data2)
        print('10、post请求内容包含第二个post黑名单返回的状态码为:{}'.format(status_code6))
        assert status_code6 == 403

        # 11、发送post请求,请求内容包含第一个uri黑名单
        status_code7 = http_check.http_post(self.case1_uri1, self.data)
        print('11、post请求内容包含第一个uri黑名单返回的状态码为:{}'.format(status_code7))
        assert status_code7 == 403

        # 12、发送post请求,请求内容包含第二个uri黑名单
        status_code8 = http_check.http_post(self.case1_uri2, self.data)
        print('12、post请求内容包含第二个uri黑名单返回的状态码为:{}'.format(status_code8))
        assert status_code8 == 403

        # 13、发送post请求,请求内容包含第一个get黑名单
        content = http_check.http_post(url, self.case1_get_data1)
        print('13、post请求内容包含第一个get黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 14、发送post请求,请求内容包含第二个get黑名单
        content = http_check.http_post(url, self.case1_get_data2)
        print('14、post请求内容包含第二个get黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 15、发送get请求,请求内容包含第一个MIME白名单
        status_code9 = http_check.http_get(self.case1_MIME1, self.data, flag=1)
        print('15、get请求内容包含第一个MIME白名单返回的状态码为:{}'.format(status_code9))
        assert status_code9 == 200

        # 16、发送get请求,请求内容包含第二个MIME白名单
        status_code10 = http_check.http_get(self.case1_MIME2,
                                            self.data,
                                            flag=1)
        print('16、get请求内容包含第二个MIME白名单返回的状态码为:{}'.format(status_code10))
        assert status_code10 == 200

        # 17、发送get请求,请求内容包含MIME类型不在白名单
        status_code11 = http_check.http_get(self.base_uri, self.data, flag=1)
        print('17、get请求内容包含MIME类型不在白名单返回的状态码为:{}'.format(status_code11))
        assert status_code11 == 403

        # 18、发送get请求,请求内容包含MIME白名单和get黑名单
        status_code12 = http_check.http_get(self.case1_MIME1,
                                            self.case1_get_data2,
                                            flag=1)
        print('18、get请求内容包含MIME白名单和get黑名单返回的状态码为:{}'.format(status_code12))
        assert status_code12 == 403

        # 19、发送get请求,请求内容包含MIME白名单和post黑名单
        status_code13 = http_check.http_get(self.case1_MIME2,
                                            self.case1_post_data1,
                                            flag=1)
        print('19、get请求内容包含MIME白名单和post黑名单返回的状态码为:{}'.format(status_code13))
        assert status_code13 == 200

        # 移除策略,还原环境
        fun.send(rbmExc, message.delhttp['DelAgent'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        del_res1 = fun.nginx_worker('ps -ef |grep nginx', 'gw',
                                    'nginx: worker process')
        assert del_res1 == 1
        # 检查代理是否成功移除
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0],
                               'gw',
                               self.case1_step1[key][1],
                               '配置',
                               100,
                               flag='不存在')
            assert self.case1_step1[key][1] not in re
        # 检查网页访问策略是否清空
        fun.send(rbmExc, message.delhttpcheck['DropHttpCheck'], rbmDomain,
                 base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        del_res2 = fun.nginx_worker('ps -ef |grep nginx', 'gw',
                                    'nginx: worker process')
        assert del_res2 == 1
        for key in self.delcheck:
            re = fun.wait_data(self.delcheck[key][0],
                               'gw',
                               self.delcheck[key][1],
                               '配置',
                               100,
                               flag='不存在')
            assert self.delcheck[key][1] not in re
Example #5
0
    def test_iso_http_check_post_a2(self):

        # 下发配置
        print('1、下发http的隔离代理:代理ip为前置机安全卡的ip,port为2287,等待nginx的24个进程起来;预期netstat -anp |grep tcp应该可以查看到监听ip和端口')
        fun.send(rbmExc, message.addhttp_front['AddCustomAppPolicy'], FrontDomain, base_path)
        fun.send(rbmExc, message.addhttp_back['AddCustomAppPolicy'], BackDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process')
        front_res = fun.nginx_worker('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process', name='前置机nginx进程')
        assert front_res == 1
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        back_res = fun.nginx_worker('ps -ef |grep nginx', 'BackDut', 'nginx: worker process', name='后置机nginx进程')
        assert back_res == 1
        # 检查配置下发是否成功
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0], 'FrontDut', self.case1_step1[key][1], '配置', 100)
            print(re)
            assert self.case1_step1[key][1] in re

        for key in self.case1_step11:
            re = fun.wait_data(self.case1_step11[key][0], 'FrontDut', self.case1_step11[key][1], '配置', 100)
            print(re)
            assert self.case1_step11[key][1] in re

        # 数据检查
        print('2、下发多个http的post黑名单,参数1为:test,参数2为juson,等待nginx的24个进程起来;cat /etc/jsac/http.json文件应该包含:c_post_args和post黑名单参数:test和juson')
        fun.send(rbmExc, message.httpcheck2['SetHttpCheck'], FrontDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process')
        add_res2 = fun.nginx_worker('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process')
        assert add_res2 == 1
        for key in self.case2_step2:
            re = fun.wait_data(self.case2_step2[key][0], 'FrontDut', self.case2_step2[key][1], '配置', 100)
            print(re)
            assert self.case2_step2[key][1] in re

        # 发送post请求,不包含黑名单内容的普通请求
        print('3、控制台发送post请求,不包含请求内容;请求成功,请求到的内容为server的index.html文件内包含的内容')
        content = http_check.http_post(http_url)
        print('多个黑名单时post普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 发送post请求,请求内容不包含黑名单内容
        print('4、控制台发送post请求,请求内容不包含黑名单;请求成功,请求到的内容为server的index.html文件内包含的内容')
        content = http_check.http_post(http_url, self.data)
        print('多个黑名单时post请求内容不包含黑名单的请求应返回的内容为:{}'.format(content))
        assert content == http_content

        # 发送post请求,请求内容包含第一个黑名单
        print('5、控制台发送post请求,请求内容包含黑名单test;请求失败,状态码返回为403')
        status_code = http_check.http_post(http_url, self.case2_data1)
        print('多个黑名单时post请求内容包含第一个黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 发送post请求,请求内容包含第二个黑名单
        print('6、控制台发送post请求,请求内容包含黑名单juson;请求失败,状态码返回为403')
        status_code = http_check.http_post(http_url, self.case2_data2)
        print('多个黑名单时post请求内容包含第二个黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 移除策略,还原环境
        print('7、移除隔离策略,清空环境,等待nginx的24个进程起来;netstat -anp |grep tcp应该查看不到监听ip和端口')
        fun.send(rbmExc, message.delhttp_front['DelCustomAppPolicy'], FrontDomain, base_path)
        fun.send(rbmExc, message.delhttp_back['DelCustomAppPolicy'], BackDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process')
        fdel_res = fun.nginx_worker('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process', name='前置机nginx进程')
        assert fdel_res == 1
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        bdel_res = fun.nginx_worker('ps -ef |grep nginx', 'BackDut', 'nginx: worker process', name='后置机nginx进程')
        assert bdel_res == 1
        # 检查策略移除是否成功
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0], 'FrontDut', self.case1_step1[key][1], '配置', 100, flag='不存在')
            print(re)
            assert self.case1_step1[key][1] not in re

        # 检查网页访问策略是否清空
        print('8、移除网页访问策略,等待nginx的24个进程起来;cat /etc/jsac/http.json文件应该不包含:c_post_args和post黑名单参数:test、juson')
        fun.send(rbmExc, message.delhttpcheck['DropHttpCheck'], FrontDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process')
        del_res2 = fun.nginx_worker('ps -ef |grep nginx', 'FrontDut', 'nginx: worker process')
        assert del_res2 == 1
        for key in self.delcheck:
            re = fun.wait_data(self.delcheck[key][0], 'FrontDut', self.delcheck[key][1], '配置', 100, flag='不存在')
            assert self.delcheck[key][1] not in re
Example #6
0
    def test_iso_http_large_file_a2(self):

        # 下发配置
        fun.send(rbmExc, message.addhttp_front_post['AddCustomAppPolicy'],
                 FrontDomain, base_path)
        fun.send(rbmExc, message.addhttp_back_post['AddCustomAppPolicy'],
                 BackDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut',
                      'nginx: worker process')
        front_res = fun.nginx_worker('ps -ef |grep nginx',
                                     'FrontDut',
                                     'nginx: worker process',
                                     name='前置机nginx进程')
        assert front_res == 1
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        back_res = fun.nginx_worker('ps -ef |grep nginx',
                                    'BackDut',
                                    'nginx: worker process',
                                    name='后置机nginx进程')
        assert back_res == 1
        # 检查配置下发是否成功
        for key in self.case2_step1:
            re = fun.wait_data(self.case2_step1[key][0], 'FrontDut',
                               self.case2_step1[key][1], '配置', 100)
            print(re)
            assert self.case2_step1[key][1] in re

        for key in self.case2_step11:
            re = fun.wait_data(self.case2_step11[key][0], 'FrontDut',
                               self.case2_step11[key][1], '配置', 100)
            print(re)
            assert self.case2_step11[key][1] in re

        # 初始化,检查server端无post.txt文件
        post_file = fun.search('/home/lwq', 'txt', 'BG8010Server')
        print(post_file)
        if 'post.txt' in post_file:
            fun.cmd('rm -f /home/lwq/post.txt ', 'BG8010Server')

        # 服务器端开启post上传服务
        post_cmd = ['cd /home/lwq', 'python3 Server.py']
        fun.cmd(post_cmd, 'httpServer', thread=1, list_flag=True)

        # 发送post请求,验证post请求是否正常
        print('请求地址为{}'.format(self.up_url))
        content = http_check.http_post(self.up_url)
        print('post普通请求的请求内容为:{}'.format(content))

        # 发送post请求,验证隔离下的http策略上传一个10G大小的文件
        print('上传的服务器地址为{}'.format(self.upfile_url))
        result = http_check.http_upload(self.upfile_url, self.upfilename,
                                        self.uplocalPath, self.upMIME_type)
        assert result == 1

        # 检查文件是否生成
        post_file = fun.search('/home/lwq', 'txt', 'httpServer')
        print('检查/home/lwq/目录下所有以txt结尾的文件列表为:{}'.format(post_file))
        assert 'post.txt' in post_file

        # 移除策略,清空环境
        fun.send(rbmExc, message.delhttp_front_post['DelCustomAppPolicy'],
                 FrontDomain, base_path)
        fun.send(rbmExc, message.delhttp_back_post['DelCustomAppPolicy'],
                 BackDomain, base_path)
        fdel_res = fun.nginx_worker('ps -ef |grep nginx',
                                    'FrontDut',
                                    'nginx: worker process',
                                    name='前置机nginx进程')
        assert fdel_res == 1
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        bdel_res = fun.nginx_worker('ps -ef |grep nginx',
                                    'BackDut',
                                    'nginx: worker process',
                                    name='后置机nginx进程')
        assert bdel_res == 1
        # 检查策略移除是否成功
        for key in self.case2_step1:
            re = fun.wait_data(self.case2_step1[key][0],
                               'FrontDut',
                               self.case2_step1[key][1],
                               '配置',
                               100,
                               flag='不存在')
            print(re)
            assert self.case2_step1[key][1] not in re
Example #7
0
    def test_iso_http_check_get_post_uri_MIME_a2(self):

        # 下发配置
        print(
            '1、下发http的隔离代理:代理ip为前置机安全卡的ip,port为2287,等待nginx的24个进程起来;预期netstat -anp |grep tcp应该可以查看到监听ip和端口'
        )
        fun.send(rbmExc, message.addhttp_front['AddCustomAppPolicy'],
                 FrontDomain, base_path)
        fun.send(rbmExc, message.addhttp_back['AddCustomAppPolicy'],
                 BackDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut',
                      'nginx: worker process')
        front_res = fun.nginx_worker('ps -ef |grep nginx',
                                     'FrontDut',
                                     'nginx: worker process',
                                     name='前置机nginx进程')
        assert front_res == 1
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        back_res = fun.nginx_worker('ps -ef |grep nginx',
                                    'BackDut',
                                    'nginx: worker process',
                                    name='后置机nginx进程')
        assert back_res == 1
        # 检查配置下发是否成功
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0], 'FrontDut',
                               self.case1_step1[key][1], '配置', 100)
            print(re)
            assert self.case1_step1[key][1] in re

        for key in self.case1_step11:
            re = fun.wait_data(self.case1_step11[key][0], 'FrontDut',
                               self.case1_step11[key][1], '配置', 100)
            print(re)
            assert self.case1_step11[key][1] in re

        # 数据检查
        print(
            '2、下发http的get黑名单,参数为:hello、juson;post黑名单:123、456;uri黑名单:mzh、hkl;MIME黑名单:css、avi,等待nginx的24个进程起来;预期cat /etc/jsac/http.json文件应该包含:c_get_args和get黑名单参数:123'
        )
        fun.send(rbmExc, message.httpcheck2['SetHttpCheck'], FrontDomain,
                 base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut',
                      'nginx: worker process')
        add_res2 = fun.nginx_worker('ps -ef |grep nginx', 'FrontDut',
                                    'nginx: worker process')
        assert add_res2 == 1
        for key in self.case2_step2:
            re = fun.wait_data(self.case2_step2[key][0], 'FrontDut',
                               self.case2_step2[key][1], '配置', 100)
            assert self.case2_step2[key][1] in re

        # 1、发送get请求,不包含黑名单内容的普通请求
        print('3、控制台发送get请求,不包含请求内容;请求成功,请求到的内容为server的index.html文件内包含的内容')
        content = http_check.http_get(http_url)
        print('1、get普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 2、发送post请求,不包含黑名单内容的普通请求
        print('4、控制台发送post请求,不包含请求内容;请求成功,请求到的内容为server的index.html文件内包含的内容')
        content = http_check.http_post(http_url)
        print('2、post普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 3、发送get请求,请求内容包含第一个get黑名单
        print('5、控制台发送get请求,请求内容包含get黑名单hello;请求失败,状态码返回为403')
        status_code = http_check.http_get(http_url, self.case1_get_data1)
        print('3、get请求内容包含第一个get黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 4、发送get请求,请求内容包含第二个get黑名单
        print('6、控制台发送get请求,请求内容包含get黑名单juson;请求失败,状态码返回为403')
        status_code = http_check.http_get(http_url, self.case1_get_data2)
        print('4、get请求内容包含第二个get黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 5、发送get请求,请求内容包含第一个uri黑名单
        print('7、控制台发送get请求,请求内容包含uri黑名单mzh;请求失败,状态码返回为403')
        status_code = http_check.http_get(self.case1_uri1, self.data)
        print('5、get请求内容包含第一个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 6、发送get请求,请求内容包含第二个uri黑名单
        print('8、控制台发送get请求,请求内容包含uri黑名单hkl;请求失败,状态码返回为403')
        status_code = http_check.http_get(self.case1_uri2, self.data)
        print('6、get请求内容包含第二个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 7、发送get请求,请求内容包含第一个post黑名单
        print(
            '9、控制台发送get请求,请求内容包含post黑名单123;请求成功,请求到的内容为server的index.html文件内包含的内容'
        )
        content = http_check.http_get(http_url, self.case1_post_data1)
        print('7、get请求内容包含第一个post黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 8、发送get请求,请求内容包含第二个post黑名单
        print(
            '10、控制台发送get请求,请求内容包含post黑名单456;请求成功,请求到的内容为server的index.html文件内包含的内容'
        )
        content = http_check.http_get(http_url, self.case1_post_data2)
        print('8、get请求内容包含第二个post黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 9、发送post请求,请求内容包含第一个post黑名单
        print('11、控制台发送post请求,请求内容包含post黑名单123;请求失败,状态码返回为403')
        status_code = http_check.http_post(http_url, self.case1_post_data1)
        print('9、post请求内容包含第一个post黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 10、发送post请求,请求内容包含第二个post黑名单
        print('12、控制台发送post请求,请求内容包含post黑名单456;请求失败,状态码返回为403')
        status_code = http_check.http_post(http_url, self.case1_post_data2)
        print('10、post请求内容包含第二个post黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 11、发送post请求,请求内容包含第一个uri黑名单
        print('13、控制台发送post请求,请求内容包含uri黑名单mzh;请求失败,状态码返回为403')
        status_code = http_check.http_post(self.case1_uri1, self.data)
        print('11、post请求内容包含第一个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 12、发送post请求,请求内容包含第二个uri黑名单
        print('14、控制台发送post请求,请求内容包含uri黑名单hkl;请求失败,状态码返回为403')
        status_code = http_check.http_post(self.case1_uri2, self.data)
        print('12、post请求内容包含第二个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 13、发送post请求,请求内容包含第一个get黑名单
        print(
            '15、控制台发送post请求,请求内容包含get黑名单hello;请求成功,请求到的内容为server的index.html文件内包含的内容'
        )
        content = http_check.http_post(http_url, self.case1_get_data1)
        print('13、post请求内容包含第一个get黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 14、发送post请求,请求内容包含第二个get黑名单
        print(
            '16、控制台发送post请求,请求内容包含get黑名单juson;请求成功,请求到的内容为server的index.html文件内包含的内容'
        )
        content = http_check.http_post(http_url, self.case1_get_data2)
        print('14、post请求内容包含第二个get黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 15、发送get请求,请求内容包含第一个MIME黑名单
        print('17、控制台发送get请求,请求内容包含MIME黑名单css;请求失败,状态码返回为403')
        status_code = http_check.http_get(self.case1_MIME1, self.data, flag=1)
        print('15、get请求内容包含第一个MIME黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 16、发送get请求,请求内容包含第二个MIME黑名单
        print('18、控制台发送get请求,请求内容包含MIME黑名单avi;请求失败,状态码返回为403')
        status_code = http_check.http_get(self.case1_MIME2, self.data, flag=1)
        print('16、get请求内容包含第二个MIME黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 17、发送get请求,请求内容包含MIME类型不在黑名单
        print('19、控制台发送get请求,请求内容包含MIME类型但不在黑白名单:pdf;请求成功,状态码返回为200')
        status_code = http_check.http_get(self.base_uri, self.data, flag=1)
        print('17、get请求内容包含MIME类型不在白名单返回的状态码为:{}'.format(status_code))
        assert status_code == 200

        # 18、发送get请求,请求内容包含MIME黑名单和post黑名单
        print('20、控制台发送get请求,请求内容包含MIME黑名单:avi和post黑名单:123;请求失败,状态码返回为403')
        status_code = http_check.http_get(self.case1_MIME2,
                                          self.case1_post_data1,
                                          flag=1)
        print('18、get请求内容包含MIME黑名单和post黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 18、发送get请求,请求内容包含MIME类型不为黑名单和get黑名单
        print(
            '21、控制台发送get请求,请求内容包含MIME类型但不在黑名单:pdf和get黑名单:hello;请求失败,状态码返回为403')
        status_code = http_check.http_get(self.base_uri,
                                          self.case1_get_data1,
                                          flag=1)
        print('18、get请求内容包含MIME类型不为黑名单和get黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 移除策略,还原环境
        print(
            '22、移除代理策略,清空环境,等待nginx的24个进程起来;netstat -anp |grep tcp应该查看不到监听ip和端口;'
        )
        fun.send(rbmExc, message.delhttp_front['DelCustomAppPolicy'],
                 FrontDomain, base_path)
        fun.send(rbmExc, message.delhttp_back['DelCustomAppPolicy'],
                 BackDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut',
                      'nginx: worker process')
        fdel_res = fun.nginx_worker('ps -ef |grep nginx',
                                    'FrontDut',
                                    'nginx: worker process',
                                    name='前置机nginx进程')
        assert fdel_res == 1
        fun.wait_data('ps -ef |grep nginx', 'BackDut', 'nginx: worker process')
        bdel_res = fun.nginx_worker('ps -ef |grep nginx',
                                    'BackDut',
                                    'nginx: worker process',
                                    name='后置机nginx进程')
        assert bdel_res == 1
        # 检查策略移除是否成功
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0],
                               'FrontDut',
                               self.case1_step1[key][1],
                               '配置',
                               100,
                               flag='不存在')
            print(re)
            assert self.case1_step1[key][1] not in re

        # 检查网页访问策略是否清空
        print(
            '23、移除网页访问策略,等待nginx的24个进程起来;cat /etc/jsac/http.json文件应该不包含:http协议'
        )
        fun.send(rbmExc, message.delhttpcheck['DropHttpCheck'], FrontDomain,
                 base_path)
        fun.wait_data('ps -ef |grep nginx', 'FrontDut',
                      'nginx: worker process')
        del_res2 = fun.nginx_worker('ps -ef |grep nginx', 'FrontDut',
                                    'nginx: worker process')
        assert del_res2 == 1
        for key in self.delcheck:
            re = fun.wait_data(self.delcheck[key][0],
                               'FrontDut',
                               self.delcheck[key][1],
                               '配置',
                               100,
                               flag='不存在')
            assert self.delcheck[key][1] not in re
Example #8
0
    def test_http_check_get_post_uri_a1(self):

        # 下发配置
        fun.send(rbmExc, message.addhttp['AddAgent'], rbmDomain, base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        # 检查配置下发是否成功
        for key in self.case1_step1:
            re = fun.wait_data(self.case1_step1[key][0], 'gw',
                               self.case1_step1[key][1], '配置', 100)
            print(re)
            assert self.case1_step1[key][1] in re

        fun.send(rbmExc, message.httpcheck1['SetHttpCheck'], rbmDomain,
                 base_path)
        fun.wait_data('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        fun.nginx_worker('ps -ef |grep nginx', 'gw', 'nginx: worker process')
        for key in self.case1_step2:
            re = fun.wait_data(self.case1_step2[key][0], 'gw',
                               self.case1_step2[key][1], '配置', 100)
            print(re)
            assert self.case1_step2[key][1] in re

        # 1、发送get请求,不包含黑名单内容的普通请求
        content = http_check.http_get(url)
        print('1、get普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 2、发送post请求,不包含黑名单内容的普通请求
        content = http_check.http_post(url)
        print('2、post普通请求的请求内容为:{}'.format(content))
        assert content == http_content

        # 3、发送get请求,请求内容包含第一个get黑名单
        status_code = http_check.http_get(url, self.case1_get_data1)
        print('3、get请求内容包含第一个get黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 4、发送get请求,请求内容包含第二个get黑名单
        status_code = http_check.http_get(url, self.case1_get_data2)
        print('4、get请求内容包含第二个get黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 5、发送get请求,请求内容包含第一个uri黑名单
        status_code = http_check.http_get(self.case1_uri1, self.data)
        print('5、get请求内容包含第一个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 6、发送get请求,请求内容包含第二个uri黑名单
        status_code = http_check.http_get(self.case1_uri2, self.data)
        print('6、get请求内容包含第二个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 7、发送get请求,请求内容包含第一个post黑名单
        content = http_check.http_get(url, self.case1_post_data1)
        print('7、get请求内容包含第一个post黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 8、发送get请求,请求内容包含第二个post黑名单
        content = http_check.http_get(url, self.case1_post_data2)
        print('8、get请求内容包含第二个post黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 9、发送post请求,请求内容包含第一个post黑名单
        status_code = http_check.http_post(url, self.case1_post_data1)
        print('9、post请求内容包含第一个post黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 10、发送post请求,请求内容包含第二个post黑名单
        status_code = http_check.http_post(url, self.case1_post_data2)
        print('10、post请求内容包含第二个post黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 11、发送post请求,请求内容包含第一个uri黑名单
        status_code = http_check.http_post(self.case1_uri1, self.data)
        print('11、post请求内容包含第一个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 12、发送post请求,请求内容包含第二个uri黑名单
        status_code = http_check.http_post(self.case1_uri2, self.data)
        print('12、post请求内容包含第二个uri黑名单返回的状态码为:{}'.format(status_code))
        assert status_code == 403

        # 13、发送post请求,请求内容包含第一个get黑名单
        content = http_check.http_post(url, self.case1_get_data1)
        print('13、post请求内容包含第一个get黑名单的请求内容为:{}'.format(content))
        assert content == http_content

        # 14、发送post请求,请求内容包含第二个get黑名单
        content = http_check.http_post(url, self.case1_get_data2)
        print('14、post请求内容包含第二个get黑名单的请求内容为:{}'.format(content))
        assert content == http_content