public function testAuthenticate()
 {
     $cookieJar = new CookieJar();
     $client = new Client(['cookies' => $cookieJar]);
     $authenticator = new CookieBasedAuthenticator(FSHARE_TEST_EMAIL, FSHARE_TEST_PASSWORD, new ReferralRequestDecorator());
     $authenticator->authenticate($client);
     static::assertTrue(is_string($cookieJar->getCookieValue('session_id')));
     static::assertTrue($cookieJar->getCookieValue('session_id') !== '');
 }
示例#2
0
 /**
  * @param RequestInterface $request
  */
 protected function extractCookiesArgument(RequestInterface $request)
 {
     $listeners = $request->getEmitter()->listeners('before');
     foreach ($listeners as $listener) {
         if ($listener[0] instanceof Cookie) {
             $values = [];
             $scheme = $request->getScheme();
             $host = $request->getHost();
             $path = $request->getPath();
             /** @var SetCookie $cookie */
             foreach ($listener[0]->getCookieJar() as $cookie) {
                 if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
                     $values[] = $cookie->getName() . '=' . CookieJar::getCookieValue($cookie->getValue());
                 }
             }
             if ($values) {
                 $this->addOption('b', escapeshellarg(implode('; ', $values)));
             }
         }
     }
 }
 public function testQuotesBadCookieValues()
 {
     $this->assertEquals('foo', CookieJar::getCookieValue('foo'));
     $this->assertEquals('"foo,bar"', CookieJar::getCookieValue('foo,bar'));
 }