Exemplo n.º 1
0
 def test_login_or_logout(self, client, service, user_data):
     from cookielib import Cookie
     args = [
         None, None, '', None, None, '/', None, None, 86400, None, None,
         None, None
     ]
     gaema_user_key = GAEMA_USER_KEY_FORMAT % service
     if hasattr(settings, "GAEMA_STORAGE") and \
           settings.GAEMA_STORAGE == "cookie":
         client.cookie_jar.set_cookie(
             Cookie(1, gaema_user_key, user_data, *args))
     else:
         session_store = import_string(settings.SESSION_STORE)()
         data = None
         for cookie in client.cookie_jar:
             if cookie.name == settings.COOKIE_NAME:
                 data = cookie.value
         if data is None:
             session = session_store.new()
         else:
             session = session_store.get(data)
         session[gaema_user_key] = user_data
         session_store.save(session)
         data = "\"%s\"" % session_store.get_data(session)
         client.cookie_jar.set_cookie(
             Cookie(1, settings.COOKIE_NAME, data, *args))
Exemplo n.º 2
0
def get_auth(username, password, cookie=None, *args, **kwargs):
    api = UfcgApi(username, password)
    if cookie is not None:
        cookie = loads(cookie)
        cookie = Cookie(value=cookie.get('value'),
                        domain=cookie.get('domain'),
                        name=cookie.get('name'),
                        port_specified=cookie.get('port_specified'),
                        comment=cookie.get('comment'),
                        domain_initial_dot=cookie.get('domain_initial_dot'),
                        expires=cookie.get('expires'),
                        domain_specified=cookie.get('domain_specified'),
                        version=cookie.get('version'),
                        rfc2109=cookie.get('rfc2109'),
                        discard=cookie.get('discard'),
                        path_specified=cookie.get('path_specified'),
                        path=cookie.get('path'),
                        port=cookie.get('port'),
                        rest=cookie.get('rest'),
                        comment_url=cookie.get('comment_url'),
                        secure=cookie.get('secure'))
        api.br.cookiejar.set_cookie(cookie)
    else:
        api.authenticate()
    return api
Exemplo n.º 3
0
    def set_session_cookie(self, username, password):
        """
        Sets a session with Django test client and logs Ghost in by creating
        a session cookie for it.

        Args:
            username (str): The username to login with.
            password (str): The password to login with.
        """
        client = Client(enforce_csrf_checks=False)
        self.assertEqual(client.login(username=username, password=password),
                         True)
        sessionid = client.cookies['sessionid']
        django_cookie = Cookie(version=0,
                               name='sessionid',
                               value=sessionid.value,
                               port=None,
                               port_specified=False,
                               domain='localhost',
                               domain_specified=True,
                               domain_initial_dot=False,
                               path='/',
                               path_specified=True,
                               secure=False,
                               expires=None,
                               discard=True,
                               comment=None,
                               comment_url=None,
                               rest=None,
                               rfc2109=False)

        cj = CookieJar()
        cj.set_cookie(django_cookie)
        self.ghost.load_cookies(cj)
Exemplo n.º 4
0
 def add_cookies(self, cookie_handler, cookies, url=None):
     """
     Add cookies to the specified cookie jar.
     Domain for the cookie can be specified via url.
     """
     domain = urlsplit(url or self.login_url)
     domain = ".%s.%s" % (domain.netloc.split(".")[-2],
                          domain.netloc.split(".")[-1])
     for _ in parse_qsl(cookies, 1):
         cookie = Cookie(version=0,
                         name=_[0],
                         value=_[1],
                         port=None,
                         port_specified=False,
                         domain=domain,
                         domain_specified=True,
                         domain_initial_dot=True,
                         path='/',
                         path_specified=True,
                         secure=True,
                         expires=None,
                         discard=True,
                         comment=None,
                         comment_url=None,
                         rest={},
                         rfc2109=False)
         cookie_handler.set_cookie(cookie)
Exemplo n.º 5
0
 def phdx(no):
     if str(no).startswith('08', 0) == True:
         no = no.replace('08', '8')
         headers = {
             'User-Agent':
             'Mozilla/5.0 (Linux; Android 6.0.1; SM-G532G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Mobile Safari/537.36',
             'Referer':
             'https://www.phd.co.id/en/users/createnewuser'
         }
         r = requests.Session()
         r.cookies = Cookie('.cookieslog')
         r.headers = headers
         data = {
             'requests_id': '',
             'first_name': 'Subscribe YT',
             'last_name': 'Jejak Cyber',
             'gender': 'male',
             'phone_number': no,
             'birthday': '0000-00-00',
             'username': '******',
             'password': '******',
             'agreeterms': '1'
         }
         send = r.post(
             'http://www.phd.co.id/en/users/createNewUser',
             data=data,
             allow_redirects=True)
         r.cookies.save()
         if 'kontol' in send.text:
             print p + '{' + h + '\xe2\x9c\x93' + p + '} ' + h + 'Spam Sms ' + k + '0' + str(
                 no) + p + ' { ' + h + 'Success ' + p + '}'
Exemplo n.º 6
0
def start(args):
    """Login and session handler
    """
    # create cookiejar
    args._cj = LWPCookieJar()

    # lets urllib handle cookies
    opener = build_opener(HTTPCookieProcessor(args._cj))
    opener.addheaders = [(
        "User-Agent",
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36"
    ), ("Accept-Encoding", "identity"), ("Accept-Charset", "utf-8"),
                         ("DNT", "1")]
    install_opener(opener)

    # load cookies
    try:
        args._cj.load(getCookiePath(args), ignore_discard=True)
    except IOError:
        # cookie file does not exist
        pass

    args._cj.set_cookie(
        Cookie(0, "timezoneoffset", str(timezone // 60), None, False,
               "www.wakanim.tv", False, False, "/", True, False, None, False,
               None, None, {"HttpOnly": None}, False))
Exemplo n.º 7
0
	def Phd(Phone, Amount):
	
		if str(Phone).startswith('08', 0) == True:
			Phone = Phone.replace('08', '8')

		for _ in range(Amount):

			sleep(5)
			headers = {
			'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9',
			'Referer' : 'https://www.phd.co.id/en/users/createnewuser'
			}

			data = {
			'requests_id' : '',
			'first_name' : 'Follow IG',
			'last_name' : 'sad.boyz01',
			'gender' : 'male',
			'phone_number' : Phone,
			'birthday' : '0000-00-00',
			'username' : '*****@*****.**',
			'password' : 'Follow 1000x Ya Anying',
			'agreeterms' : '1'
			}

			Sess = requests.Session()
			Sess.cookies = Cookie('.cookieslog')
			Sess.headers = headers

			postData = Sess.post('http://www.phd.co.id/en/users/createNewUser', data = data , allow_redirects = True)
			Sess.cookies.save()
		
			print(W+'['+C+'*'+W+'] KIRIM SPAM KE NOMOR '+C+str(Phone)+W+' BERHASIL'+H+' \xE2\x9C\x94')
Exemplo n.º 8
0
	def Hooq(Phone, Amount):
		for _ in range(Amount):

			sleep(5)
			bro = mechanize.Browser()
			Cookies = Cookie('.cookieslog')

			bro.set_handle_robots(False)
			bro.set_cookiejar(Cookies)

			bro.addheaders = [
			('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9'),
			('Referer', 'https://authenticate.hooq.tv/signupmobile?return?Url=https://www.hooq.tv/auth//verify/ev%2F%257Cid')
			]

			bro.open('https://authenticate.hooq.tv/signupmobile?returnUrl=https://www.hooq.tv%2Fauth%2Fverify%2Fev%2F%257Cid&serialNo=0&deviceType=webClient&modelNo=webclient-aurora&deviceName=webclient-aurora/production-8.4.1&deviceSignature=0')
			bro.select_form(nr=0)		
			bro.form ['mobile'] = str(Phone)
			submit = bro.submit()

			if 'Your+number+has+been+blocked.' in submit.geturl():
				print(W+'NOMOR TARGET UDAH DI BLOKIR\n'+C+'SAMA PIHAK HOOQ. '+W+'COBA NOMOR LAIN ^_^')
				sys.exit() 
			
			elif 'buCode' in submit.geturl():
				print(W+'['+C+'*'+W+'] KIRIM SPAM KE NOMOR '+C+str(Phone)+W+' BERHASIL'+H+' \xE2\x9C\x94')
			
			else:
				print(W+'['+C+'*'+W+'] KIRIM SPAM KE NOMOR '+C+str(Phone)+W+' GAGAL'+M+' \xE2\x9C\x96')
Exemplo n.º 9
0
 def py_cookies(self):
     for c in self.cookie_jar.allCookies():
         name, value = map(bytes, (c.name(), c.value()))
         domain = bytes(c.domain())
         initial_dot = domain_specified = domain.startswith(b'.')
         secure = bool(c.isSecure())
         path = unicode(c.path()).strip().encode('utf-8')
         expires = c.expirationDate()
         is_session_cookie = False
         if expires.isValid():
             expires = expires.toTime_t()
         else:
             expires = None
             is_session_cookie = True
         path_specified = True
         if not path:
             path = b'/'
             path_specified = False
         c = Cookie(0,  # version
                 name, value,
                 None,  # port
                 False,  # port specified
                 domain, domain_specified, initial_dot, path,
                 path_specified,
                 secure, expires, is_session_cookie,
                 None,  # Comment
                 None,  # Comment URL
                 {}  # rest
         )
         yield c
Exemplo n.º 10
0
	def AlfaMart(Phone, Amount):
		for _ in range(Amount):
		
			sleep(5)
			headers = {
			'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',
			'Referer' : 'https://www.alfacart.com/login?tab=daftar&return='
			}
		
			data = {
			'fullName' : 'IG sad.boyz01',
			'red' : 'customer%2Faccount',
			'email' : '*****@*****.**',
			'password' : 'Follow IG Gua Yak',
			'isNewsletter' : 'on'
			}
		
			Sess = requests.Session()
			Sess.cookies = Cookie('.cookieslog')
			Sess.headers = headers

			postData = Sess.post('https://www.alfacart.com/getMemberInfo', data = {'email' : '*****@*****.**'})
			postData_2 = Sess.post('https://www.alfacart.com/otp/checkActiveNumber', data = {'phoneNumber' : Phone, 'email' : '*****@*****.**'})
			postData_3 = Sess.post('https://www.alfacart.com/otp/phoneNumberRegistration', data = {'phoneNumber' : Phone})
			postData_4 = Sess.post('https://www.alfacart.com/doRegister', data = data)
		
			if 'responseMessage":"Nomor terverifikasi dan dapat diubah.","status":true' in postData_2.text:
				print(W+'['+C+'*'+W+'] KIRIM SPAM KE NOMOR '+C+str(Phone)+W+' BERHASIL'+H+' \xE2\x9C\x94')
				Sess.cookies.save()
			
			else:
				print(W+'['+C+'*'+W+'] KIRIM SPAM KE NOMOR '+C+str(Phone)+W+' GAGAL'+M+' \xE2\x9C\x96')
Exemplo n.º 11
0
    def HarVest(Phone, Amount):
        for _ in range(Amount):

            sleep(5)
            headers = {
                'User-Agent':
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9',
                'Referer': 'https://harvestcakes.com/register'
            }

            data = {'phone': Phone, 'url': ''}

            Sess = requests.Session()
            Sess.cookies = Cookie('.cookieslog')
            Sess.headers = headers

            postData = Sess.post('https://harvestcakes.com/register',
                                 data=data,
                                 allow_redirects=True)

            if 'Enter OTP code we sent via SMS on phone number' in postData.text:
                print(W + '[' + C + '*' + W + '] KIRIM SPAM KE NOMOR ' + C +
                      str(Phone) + W + ' BERHASIL' + H + ' \xE2\x9C\x94')
                Sess.cookies.save()

            else:
                print(W + '[' + C + '*' + W + '] KIRIM SPAM KE NOMOR ' + C +
                      str(Phone) + W + ' GAGAL' + M + ' \xE2\x9C\x96')
Exemplo n.º 12
0
def create_cookie(name, value, **kwargs):
    """Creates `cookielib.Cookie` instance.
    """

    config = dict(
        name=name,
        value=value,
        version=0,
        port=None,
        domain='',
        path='/',
        secure=False,
        expires=None,
        discard=True,
        comment=None,
        comment_url=None,
        rfc2109=False,
        rest={'HttpOnly': None},  # wtf?
    )

    bad_args = set(kwargs) - set(config.keys())
    if bad_args:
        raise TypeError('Unexpected arguments: %s' % tuple(bad_args))

    config.update(**kwargs)

    config['port_specified'] = bool(config['port'])
    config['domain_specified'] = bool(config['domain'])
    config['domain_initial_dot'] = config['domain'].startswith('.')
    config['path_specified'] = bool(config['path'])

    return Cookie(**config)
Exemplo n.º 13
0
    def Olx(Phone, Amount):
        for _ in range(Amount):

            sleep(5)
            headers = {
                'user-agent':
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9',
                'referer': 'https://www.olx.co.id/'
            }

            data = {'grantType': 'phone', 'phone': Phone, 'language': ''}

            Sess = requests.Session()
            Sess.cookies = Cookie('.cookieslog')
            Sess.headers = headers

            postData = Sess.post('https://www.olx.co.id/api/auth/authenticate',
                                 json=data,
                                 allow_redirects=True)

            if 'PIN' and 'token' in postData.text:
                print(W + '[' + C + '*' + W + '] KIRIM SPAM KE NOMOR ' + C +
                      str(Phone) + W + ' BERHASIL' + H + ' \xE2\x9C\x94')
                Sess.cookies.save()

            else:
                print(W + '[' + C + '*' + W + '] KIRIM SPAM KE NOMOR ' + C +
                      str(Phone) + W + ' GAGAL' + M + ' \xE2\x9C\x96')
Exemplo n.º 14
0
 def set_cookie(self,
                name,
                value,
                domain=None,
                path=None,
                session=True,
                expires=None,
                port=None,
                request=None):
     """
     :param expires: Seconds from epoch
     :param port: must match request port
     :param domain: the fqn of your server hostname
     """
     # Cookie(version, name, value, port, port_specified,
     # domain, domain_specified, domain_initial_dot,
     # path, path_specified, secure, expires,
     # discard, comment, comment_url, rest,
     # rfc2109=False):
     cookie = Cookie(0, name, value, port, bool(port), domain or '',
                     bool(domain),
                     (domain and domain.startswith('.')), path or '',
                     bool(path), False, expires, session, None, None, {},
                     False)
     self._cookie_jar.set_cookie(cookie)
Exemplo n.º 15
0
    def download_gazette(self, relpath, search_url, postdata, metainfo,
                         cookiejar):
        relurl = self.get_relurl(relpath, metainfo)
        if not relurl:
            self.logger.warn('Not able to form relurl for %s', metainfo)
            return None

        newpost = []
        for d in postdata:
            if d[0] == 'ctl00$ContentPlaceHolder2$btnShow':
                continue

            newpost.append(d)

        gzid = self.post_for_gzid(newpost)

        if not gzid:
            self.logger.warn('Unable to get gazette id in the cookie for %s',
                             relurl)
            return None

        fileurl = self.file_url % gzid
        metainfo.pop('download')
        cookie = Cookie(0, self.filenum_cookie, gzid, None, False, \
                       self.hostname, True, False, '/', True, False, \
                       None, False, None, None, None)

        cookiejar.set_cookie(cookie)
        if self.save_gazette(relurl, fileurl, metainfo, cookiefile=cookiejar,\
                             validurl = False):
            return relurl
        return None
Exemplo n.º 16
0
    def _read_cookies(self, url=''):
        cookies_path = os.path.join(PATH_TEMP, 'burst')
        if not os.path.exists(cookies_path):
            try:
                os.makedirs(cookies_path)
            except Exception as e:
                log.debug("Error creating cookies directory: %s" % repr(e))
        self._cookies_filename = os.path.join(cookies_path, urlparse(url).netloc + '_cookies.jar')
        if os.path.exists(self._cookies_filename):
            try:
                self._cookies.load(self._cookies_filename)
            except Exception as e:
                log.debug("Reading cookies error: %s" % repr(e))

        # Check for cf_clearance cookie
        # https://github.com/scakemyer/cloudhole-api
        if self.clearance and not any(cookie.name == 'cf_clearance' for cookie in self._cookies):
            c = Cookie(version=None,
                       name='cf_clearance',
                       value=self.clearance[13:],
                       port=None,
                       port_specified=False,
                       domain='.{uri.netloc}'.format(uri=urlparse(url)),
                       domain_specified=True,
                       domain_initial_dot=True,
                       path='/',
                       path_specified=True,
                       secure=False,
                       expires=None,
                       discard=False,
                       comment=None,
                       comment_url=None,
                       rest=None,
                       rfc2109=False)
            self._cookies.set_cookie(c)
Exemplo n.º 17
0
 def toPyCookie(QtCookie):
     port = None
     port_specified = False
     secure = QtCookie.isSecure()
     name = str(QtCookie.name())
     value = str(QtCookie.value())
     v = str(QtCookie.path())
     path_specified = bool(v != "")
     path = v if path_specified else None
     v = str(QtCookie.domain())
     domain_specified = bool(v != "")
     domain = v
     if domain_specified:
         domain_initial_dot = v.startswith('.')
     else:
         domain_initial_dot = None
     v = long(QtCookie.expirationDate().toTime_t())
     # Long type boundary on 32bit platfroms; avoid ValueError
     expires = 2147483647 if v > 2147483647 else v
     rest = {}
     discard = False
     return Cookie(0, name, value, port, port_specified, domain,
                   domain_specified, domain_initial_dot, path,
                   path_specified, secure, expires, discard, None, None,
                   rest)
Exemplo n.º 18
0
    def _authenticate(self, username, password):
        '''
        Authenticate to Google:
        1 - make a GET request to the Login webpage so we can get the login form
        2 - make a POST request with email, password and login form input values
        '''
        # Make sure we get CSV results in English
        ck1 = Cookie(version=0, name='I4SUserLocale', value='en_US', port=None, port_specified=False, domain='.google.com', domain_specified=False,domain_initial_dot=False, path='', path_specified=False, secure=False, expires=None, discard=False, comment=None, comment_url=None, rest=None)
        # This cookie is now mandatory
        ck2 = Cookie(version=0, name='PREF', value='', port=None, port_specified=False, domain='.google.com', domain_specified=False,domain_initial_dot=False, path='', path_specified=False, secure=False, expires=None, discard=False, comment=None, comment_url=None, rest=None)

        self.cj = CookieJar()
        self.cj.set_cookie(ck1)
        self.cj.set_cookie(ck2)

        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
        self.opener.addheaders = self.headers

        # Get all of the login form input values
        find_inputs = etree.XPath("//form[@id='gaia_loginform']//input")
        resp = self.opener.open(self.url_login)
        data = self.read_gzipped_response(resp)

        try:
            xmlTree = etree.fromstring(data, parser=html.HTMLParser(recover=True, remove_comments=True))
            for input in find_inputs(xmlTree):
                name = input.get('name')
                if name:
                    name = name.encode('utf8')
                    value = input.get('value', '').encode('utf8')
                    self.login_params[name] = value
        except:
            print("Exception while parsing: %s\n" % traceback.format_exc())

        self.login_params["Email"] = username
        self.login_params["Passwd"] = password

        params = urllib.urlencode(self.login_params)
        auth_resp = self.opener.open(self.url_authenticate, params)

        # Testing whether Authentication was a success
        # I noticed that a correct auth sets a few cookies
        if not self.is_authentication_successfull(auth_resp):
            print 'Warning: Authentication failed for user %s' % username
        else:
            print 'Authentication successfull for user %s' % username
    def _authenticate(self, username, password):
        '''
        Authenticate to Google:
        1 - make a GET request to the Login webpage so we can get the login form
        2 - make a POST request with email, password and login form input values
        '''
        
        # Make sure we get CSV results in English
        ck = Cookie(version=0, name='I4SUserLocale', value='en_US', port=None, port_specified=False, domain='www.google.com', domain_specified=False,domain_initial_dot=False, path='/trends', path_specified=True, secure=False, expires=None, discard=False, comment=None, comment_url=None, rest=None)
        ck_pref = Cookie(version=0, name='PREF', value='', port=None, port_specified=False, domain='www.google.com', domain_specified=False,domain_initial_dot=False, path='/trends', path_specified=True, secure=False, expires=None, discard=False, comment=None, comment_url=None, rest=None) 

        self.cj = CookieJar()                            
        self.cj.set_cookie(ck)
        self.cj.set_cookie(ck_pref)
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
        self.opener.addheaders = self.headers
        
        # Get all of the login form input values
        find_inputs = etree.XPath("//form[@id='gaia_loginform']//input")
        try:
            #
            resp = self.opener.open(self.url_login)
            
            if resp.info().get('Content-Encoding') == 'gzip':
                buf = StringIO( resp.read())
                f = gzip.GzipFile(fileobj=buf)
                data = f.read()
            else:
                data = resp.read()
            
            xmlTree = etree.fromstring(data, parser=html.HTMLParser(recover=True, remove_comments=True))
            
            for input in find_inputs(xmlTree):
                name = input.get('name')
                if name:
                    name = name.encode('utf8')
                    value = input.get('value', '').encode('utf8')
                    self.login_params[name] = value
        except:
            print("Exception while parsing: %s\n" % traceback.format_exc())    
        
        self.login_params["Email"] = username
        self.login_params["Passwd"] = password
        
        params = urllib.urlencode(self.login_params)
        self.opener.open(self.url_authenticate, params)
Exemplo n.º 20
0
    def _really_load(self, f, filename, ignore_discard, ignore_expires):
        now = time.time()

        magic = f.readline()
        if not re.search(self.magic_re, magic):
            f.close()
            raise LoadError(
                "%r does not look like a Netscape format cookies file" %
                filename)

        try:
            while True:
                line = f.readline()
                if line == "": break

                # last field may be absent, so keep any trailing tab
                if line.endswith("\n"): line = line[:-1]

                # skip comments and blank lines XXX what is $ for?
                if (line.strip().startswith(("#", "$")) or line.strip() == ""):
                    continue

                domain, domain_specified, path, secure, expires, name, value = \
                        line.split("\t")
                secure = (secure == "TRUE")
                domain_specified = (domain_specified == "TRUE")
                if name == "":
                    # cookies.txt regards 'Set-Cookie: foo' as a cookie
                    # with no name, whereas cookielib regards it as a
                    # cookie with no value.
                    name = value
                    value = None

                initial_dot = domain.startswith(".")
                assert domain_specified == initial_dot

                discard = False
                if expires == "":
                    expires = None
                    discard = True

                # assume path_specified is false
                c = Cookie(0, name, value, None, False, domain,
                           domain_specified, initial_dot, path, False, secure,
                           expires, discard, None, None, {})
                if not ignore_discard and c.discard:
                    continue
                if not ignore_expires and c.is_expired(now):
                    continue
                self.set_cookie(c)

        except IOError:
            raise
        except Exception:
            _warn_unhandled_exception()
            raise LoadError("invalid Netscape format cookies file %r: %r" %
                            (filename, line))
Exemplo n.º 21
0
def test_request_loader_does_not_fail_with_invalid_token(client):
    c = Cookie(version=0, name='remember_token', value='None', port=None,
               port_specified=False, domain='www.example.com',
               domain_specified=False, domain_initial_dot=False, path='/',
               path_specified=True, secure=False, expires=None,
               discard=True, comment=None, comment_url=None,
               rest={'HttpOnly': None}, rfc2109=False)

    client.cookie_jar.set_cookie(c)
    response = client.get('/')
    assert b'BadSignature' not in response.data
Exemplo n.º 22
0
    def set_cookie(version=0, name='', value='',
                   port=None,
                   # Not used: port_specified=False,
                   domain='',
                   # Not used: domain_specified=True,
                   domain_initial_dot=False,
                   path='/',
                   # Not used: path_specified=True,
                   secure=False,
                   expires=4102444555,
                   # Not used:
                   # discard=False,
                   # comment=None,
                   # comment_url=None,
                   # rest=None,
                   # rfc2109=False
                   ):
        """ Sets a cookie in the UriHandler cookie jar

        :param int version:             The cookie version
        :param str name:                The name of the cookie
        :param str value:               The value of the cookie
        :param int|None port:           String representing a port or a set of
                                        ports (eg. '80', or '80,8080'), or None
        :param str domain:              The domain for which the cookie should be valid
        :param bool domain_initial_dot: If the domain explicitly specified by the server began with a dot ('.').
        :param str path:                The path the cookie is valid for
        :param bool secure:             If cookie should only be returned over a secure connection
        :param int expires:             Integer expiry date in seconds since epoch, or None.

        :return: The new cookie.
        :rtype: cookielib.Cookie
        """

        Logger.debug("Setting a cookie with this data:\n"
                     "name:   '%s'\n"
                     "value:  '%s'\n"
                     "domain: '%s'\n"
                     "path:   '%s'",
                     name, value, domain, path)
        c = Cookie(version=version, name=name, value=value,
                   port=port, port_specified=port is not None,
                   domain=domain, domain_specified=domain is not None,
                   domain_initial_dot=domain_initial_dot,
                   path=path, path_specified=path is not None,
                   secure=secure,
                   expires=expires,
                   discard=False,
                   comment=None,
                   comment_url=None,
                   rest={'HttpOnly': None})  # rfc2109=False)
        # the rfc2109 parameters is not valid in Python 2.4 (Xbox), so we ommit it.
        UriHandler.instance().cookieJar.set_cookie(c)
        return c
Exemplo n.º 23
0
def auth_cookies(login):
    environ = dict(HTTP_HOST='example.com')
    cookies = [c for _, c in remember(DummyRequest(environ=environ), login)]
    for data in parse_ns_headers(cookies):
        name, value = data.pop(0)
        rest = dict(port='80', port_specified=True, domain_specified=True,
            path_specified=True, secure=False, expires=None, discard=False,
            comment='', comment_url=None, rest=None, domain='')
        rest.update(dict(data))
        rest['domain_initial_dot'] = rest['domain'].startswith('.')
        yield Cookie(name=name, value=value, **rest)
Exemplo n.º 24
0
    def test_token_loader_does_not_fail_with_invalid_token(self):
        c = Cookie(version=0, name='remember_token', value='None', port=None,
                   port_specified=False, domain='www.example.com',
                   domain_specified=False, domain_initial_dot=False, path='/',
                   path_specified=True, secure=False, expires=None,
                   discard=True, comment=None, comment_url=None,
                   rest={'HttpOnly': None}, rfc2109=False)

        self.client.cookie_jar.set_cookie(c)
        r = self._get('/')
        self.assertNotIn(b'BadSignature', r.data)
Exemplo n.º 25
0
 def _cookies_from_cursor(self, cursor):
     cookies = []
     for row in cursor:
         domain = row[0]
         name = row[1]
         value = row[2]
         path = row[3]
         expires = row[4]
         secure = row[5]
         cookies.append(Cookie(None, name, value, None, None, domain, True, bool(domain.startswith(".")),
                               path, True, secure, expires, False, None, None, None))
     return cookies
Exemplo n.º 26
0
def make_cookie(name, value, version=0,
        port=None, port_specified=False,
        domain=u'bbs.nju.edu.cn', domain_specified=False, domain_initial_dot=False,
        path=u'', path_specified=False,
        secure=False, expires=None, discard=True,
        comment=None, comment_url=None,
        rest={}, rfc2109=False):
    from cookielib import Cookie
    return Cookie(version, name, str(value),
            port, port_specified,
            domain, domain_specified, domain_initial_dot,
            path, path_specified,
            secure, expires, discard, comment, comment_url,
            rest, rfc2109)
Exemplo n.º 27
0
def get_cookie_jar():
		try:
			from cookielib import Cookie, CookieJar         # Python 2
		except ImportError:
			from http.cookiejar import Cookie, CookieJar    # Python 3.
			from http.cookies import SimpleCookie
		cj = CookieJar()
		# Cookie(version, name, value, port, port_specified, domain, 
		# domain_specified, domain_initial_dot, path, path_specified, 
		# secure, discard, comment, comment_url, rest)
		c = Cookie(version=0, name=COOKIE_NAME, value=COOKIE_VALUE, port=None, port_specified=False, domain='scplanner.net', 
			   domain_specified=True, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest=None, rfc2109=True)
		cj.set_cookie(c)
		return cj
Exemplo n.º 28
0
    def set_cookie(self, name, value, domain=None, path=None,
                   session=True, expires=None, port=None):
#        Cookie(version, name, value, port, port_specified,
#                 domain, domain_specified, domain_initial_dot,
#                 path, path_specified, secure, expires,
#                 discard, comment, comment_url, rest,
#                 rfc2109=False):

        cookie = Cookie(0, name, value, port, bool(port),
                        domain or '', bool(domain),
                        (domain and domain.startswith('.')),
                        path or '', bool(path), False, expires,
                        session, None, None, {}, False)
        self._cookie_jar.set_cookie(cookie)
Exemplo n.º 29
0
 def test_convert_cookie_to_dict(self):
     cook1 = {
         'name': 'cook1',
         'value': 'value1',
         'path': '/',
         'secure': False,
         'expiry': 1453912471
     }
     cookie = Cookie(0, cook1['name'], cook1['value'], None, False,
                     '.github.com', True, True, cook1['path'], True,
                     cook1['secure'], cook1['expiry'], False, None, None,
                     None, False)
     dict1 = convert_cookie_to_dict(cookie)
     eq_(cook1, dict1)
Exemplo n.º 30
0
    def _parse_cookie(self, lst):
        for item in lst:
            domain, domain_specified, path, path_specified, expires,\
             name, value = item.split("\t")

            cookie = Cookie(0, name, value, None, False, domain,
                            domain_specified.lower() == "true",
                            domain.startswith("."), path,
                            path_specified.lower() == "true", False, expires,
                            False, None, None, {})

            self._cookie.update({domain: {path: {name: cookie}}})

        return self._cookie