From 60f14da329387b8e440bf4b5665aaae5ffc64b7b Mon Sep 17 00:00:00 2001 From: kush789 Date: Tue, 9 Feb 2016 01:14:22 +0530 Subject: [PATCH] Added Test-reject-secure-cookies --- testenv/Makefile.am | 1 + testenv/Test-reject-secure-cookie.py | 73 ++++++++++++++++++++++++++++++++++++ testenv/conf/expected_files.py | 5 ++- 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 testenv/Test-reject-secure-cookie.py diff --git a/testenv/Makefile.am b/testenv/Makefile.am index 370c404..084d435 100644 --- a/testenv/Makefile.am +++ b/testenv/Makefile.am @@ -68,6 +68,7 @@ if HAVE_PYTHON3 Test--spider-r.py \ Test--rejected-log.py \ Test-redirect-crash.py \ + Test-reject-secure-cookie.py \ Test-reserved-chars.py \ Test-condget.py \ $(METALINK_TESTS) diff --git a/testenv/Test-reject-secure-cookie.py b/testenv/Test-reject-secure-cookie.py new file mode 100644 index 0000000..c629020 --- /dev/null +++ b/testenv/Test-reject-secure-cookie.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +from sys import exit +from test.http_test import HTTPTest +from test.base_test import HTTP +from misc.wget_file import WgetFile + +""" + This test ensures that a secure-only cookie is rejected over an insecure + connection +""" +TEST_NAME = "Reject Secure Cookie" +############# File Definitions ############################################### +File1 = """All happy families are alike; +Each unhappy family is unhappy in its own way""" +File2 = "" +# Expected cookie file should be empty + +File1_rules = { + "SendHeader" : { + "Set-Cookie" : "sess-id=0213; path=/; secure" + } +} + +A_File = WgetFile ("File1", File1, rules=File1_rules) +B_File = WgetFile ("mycookies.wget", File2) + +WGET_OPTIONS = "--save-cookies=mycookies.wget" +WGET_URLS = [["File1"]] + +Servers = [HTTP] + +Files = [[A_File]] + +ExpectedReturnCode = 0 + +def postfunc(): + cookie_file_content = [] + + with open("mycookies.wget", 'r') as fp: + cookie_file_content = fp.readlines() + print (cookie_file_content) + + cookie_file_content = cookie_file_content[4:] + # Removing first four lines (comments generated by wget) + + with open("mycookies.wget", 'w') as fp: + for line in cookie_file_content:cookie_file_content + fp.write(line) + + return [A_File, B_File] + +################ Pre and Post Test Hooks ##################################### +pre_test = { + "ServerFiles" : Files, +} +test_options = { + "WgetCommands" : WGET_OPTIONS, + "Urls" : WGET_URLS +} +post_test = { + "ExpectedFiles" : postfunc, + "ExpectedRetcode" : ExpectedReturnCode +} + +err = HTTPTest ( + name=TEST_NAME, + pre_hook=pre_test, + test_params=test_options, + post_hook=post_test, + protocols=Servers +).begin () + +exit (err) diff --git a/testenv/conf/expected_files.py b/testenv/conf/expected_files.py index 5362771..c9a333f 100644 --- a/testenv/conf/expected_files.py +++ b/testenv/conf/expected_files.py @@ -17,7 +17,10 @@ files are found, else returns gracefully. @hook() class ExpectedFiles: def __init__(self, expected_fs): - self.expected_fs = expected_fs + if callable(expected_fs): + self.expected_fs = expected_fs() + else: + self.expected_fs = expected_fs @staticmethod def gen_local_fs_snapshot(): -- 1.9.1