def setAuthCookie(self): if self.__auth_cookie_names: c = get_first_matching_cookie(self.__auth_cookie_names, self.path, self.headers) if c: self.__auth_cookie = c self.__auth_cookie_expiry = get_cookie_expiry(c)
def test_get_first_matching_cookie(self): assert get_first_matching_cookie(['a', 'b'], '/path', {}) is None headers = {'Set-Cookie': '''c_cookie=c_value b_cookie=b_value a_cookie=a_value'''} c = get_first_matching_cookie(['a_cookie', 'b_cookie'], '/path', headers) assert c.key == 'a_cookie' and c.value == 'a_value' c = get_first_matching_cookie(['b_cookie', 'a_cookie'], '/path', headers) assert c.key == 'b_cookie' and c.value == 'b_value' headers = {'Set-Cookie': '''c_cookie=c_value;Path=/ b_cookie=b_value;Path=/path a_cookie=a_value;Path=/'''} c = get_first_matching_cookie(['a_cookie', 'b_cookie'], '/path', headers) assert c.key == 'a_cookie' and c.value == 'a_value' c = get_first_matching_cookie(['b_cookie', 'a_cookie'], '/path', headers) assert c.key == 'b_cookie' and c.value == 'b_value' headers = {'Set-Cookie': '''c_cookie=c_value;Path=/ b_cookie=b_value;Path=/path a_cookie=a_value;Path=/path/path2'''} c = get_first_matching_cookie(['a_cookie', 'b_cookie'], '/path', headers) assert c.key == 'b_cookie' and c.value == 'b_value' c = get_first_matching_cookie(['b_cookie', 'a_cookie'], '/path', headers) assert c.key == 'b_cookie' and c.value == 'b_value' headers = {'Set-Cookie': '''c_cookie=c_value;Path=/ b_cookie=b_value;Path=/path a_cookie=a_value;Path=/path'''} c = get_first_matching_cookie(['a_cookie', 'b_cookie'], '/path/path1', headers) assert c.key == 'a_cookie' and c.value == 'a_value' c = get_first_matching_cookie(['b_cookie', 'a_cookie'], '/path/path1', headers) assert c.key == 'b_cookie' and c.value == 'b_value' headers = {'Set-Cookie': '''c_cookie=c_value;Path=/ b_cookie=b_value;Path=/path1 a_cookie=a_value;Path=/path2'''} c = get_first_matching_cookie(['a_cookie', 'b_cookie'], '/path', headers) assert c is None headers = {'Set-Cookie': '''c_cookie=c_value;Path=/ b_cookie=b_value;Path=/path1 a_cookie=a_value;Path=/path2'''} c = get_first_matching_cookie(['a_cookie', 'b_cookie', 'c_cookie'], '/path', headers) assert c.key == 'c_cookie' and c.value == 'c_value'