<commit_before>from __future__ import print_function
from ftw.ftw import ruleset, http, errors
import pytest
import sys

@pytest.mark.skip(reason='Integration failure, @chaimsanders for more info')
def test_cookies1():
    """Tests accessing a site that sets a cookie and then wants to resend the cookie"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    with pytest.raises(KeyError):
        print(http_ua.request_object.headers["cookie"])
    assert("set-cookie" in http_ua.response_object.headers.keys())
    cookie_data = http_ua.response_object.headers["set-cookie"]
    cookie_var = cookie_data.split("=")[0]
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    assert(http_ua.request_object.headers["cookie"].split('=')[0] == cookie_var)

def test_cookies2():
    """Test to make sure that we don't override user specified cookies"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa"})    
    http_ua.send_request(x)
    assert('TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa' in http_ua.request_object.headers["cookie"])

def test_cookies3():
    """Test to make sure we retain cookies when user specified values are provided"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa; XYZ=123"})
    http_ua.send_request(x)
    assert(set([chunk.split('=')[0].strip() for chunk in http_ua.request_object.headers["cookie"].split(';')]) == set(['XYZ', 'TS01293935']))

def test_cookies4():
    """Test to make sure cookies are saved when user-specified cookie is added"""
    http_ua = http.HttpUA()<commit_msg>Fix test (but keep it disabled)<commit_after>from __future__ import print_function
from ftw.ftw import ruleset, http, errors
import pytest
import sys

@pytest.mark.skip(reason='Integration failure, @chaimsanders for more info')
def test_cookies1():
    """Tests accessing a site that sets a cookie and then wants to resend the cookie"""
    http_ua = http.HttpUA()
    x = ruleset.Input(protocol="https",port=443,dest_addr="www.ieee.org",headers={"Host":"www.ieee.org"})
    http_ua.send_request(x)
    with pytest.raises(KeyError):
        print(http_ua.request_object.headers["cookie"])
    assert("set-cookie" in http_ua.response_object.headers.keys())
    cookie_data = http_ua.response_object.headers["set-cookie"]
    cookie_var = cookie_data.split("=")[0]
    x = ruleset.Input(protocol="https",port=443,dest_addr="www.ieee.org",headers={"Host":"www.ieee.org"})
    http_ua.send_request(x)
    assert(http_ua.request_object.headers["cookie"].split('=')[0] == cookie_var)

def test_cookies2():
    """Test to make sure that we don't override user specified cookies"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa"})    
    http_ua.send_request(x)
    assert('TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa' in http_ua.request_object.headers["cookie"])

def test_cookies3():
    """Test to make sure we retain cookies when user specified values are provided"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa; XYZ=123"})
    http_ua.send_request(x)
    assert(set([chunk.split('=')[0].strip() for chunk in http_ua.request_object.headers["cookie"].split(';')]) == set(['XYZ', 'TS01293935']))

def test_cookies4():
    """Test to make sure cookies are saved when user-specified cookie is added"""
    http_ua = http.HttpUA()
{'fraction_non_alphanumeric': 0.14826498422712933, 'fraction_numerical': 0.08652546191978369, 'mean_word_length': 5.871517027863777, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2242918', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1638, 'n_words': 260}