public function testDigestAuthInt() { $this->auth->setQOP(Digest::QOP_AUTHINT | Digest::QOP_AUTH); list($nonce, $opaque) = $this->getServerTokens(Digest::QOP_AUTHINT | Digest::QOP_AUTH); $username = '******'; $password = 12345; $nc = '00003'; $cnonce = uniqid(); $digestHash = md5(md5($username . ':' . self::REALM . ':' . $password) . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':' . 'auth-int:' . md5('POST' . ':' . '/' . ':' . md5('body'))); $this->request->setMethod('POST'); $this->request->setHeader('Authorization', 'Digest username="******", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc=' . $nc . ',cnonce="' . $cnonce . '"'); $this->request->setBody('body'); $this->auth->init(); $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1'); }
protected function sendRequest($body, $path = '/jmap', $headers = []) { if (!is_string($body)) { $body = json_encode($body); } $request = new HTTP\Request('POST', $path, $headers, $body); $request->setHeader('Authorization', 'X-JMAP ' . $this->session->key); $this->server->httpRequest = $request; $this->server->process(); return $this->server->httpResponse; }
/** * Adding the If-None-Match should have 0 effect, but it threw an error. */ function testCollectionGetIfNoneMatch() { $request = new HTTP\Request('GET', '/dir'); $request->setHeader('If-None-Match', '"foo-bar"'); $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); $this->assertEquals(['X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Type' => ['text/html; charset=utf-8'], 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"]], $this->response->getHeaders()); $body = $this->response->getBodyAsString(); $this->assertTrue(strpos($body, '<title>dir') !== false, $body); $this->assertTrue(strpos($body, '<a href="/dir/child.txt">') !== false); }
/** * Proxy the given JMAP message to the connected JMAP server * * @param string $method The name of the method to be called on the server * @param array $args Object containing named arguments for that method or response * @return array List of response messages returned by the server */ protected function proxy($method, array $args = []) { if (!isset($this->proxyuri) && ($identity = $this->controller->getIdentity())) { $this->proxyuri = $identity->uri; } if (empty($this->proxyuri)) { throw new RuntimeException("JmapProxy Error: unauthenticated; missing session URI"); } $error = 'Not Implemented'; $tag = '#' . $this->reqid++; $request = new HTTP\Request('POST', $this->proxyuri); $request->setHeader('Content-Type', 'application/json'); $request->setBody(json_encode([[$method, $args, $tag]])); $this->logger->debug('proxy:request ' . $method, ['args' => $args, 'uri' => $this->proxyuri, 'tag' => $tag]); try { $client = new HttpClient(); $this->setCurlProxySettings($client); $response = $client->send($request); $this->logger->debug('proxy:response', ['dump' => strval($response)]); if ($response->getStatus() === 200) { $results = json_decode($response->getBodyAsString(), true); return array_filter($results, function ($res) use($tag) { return count($res) == 3 && $res[2] == $tag; }); } $error = 'Unexpected HTTP response: ' . $response->getStatus() . ' ' . $response->getStatusText(); } catch (HTTP\ClientHttpException $e) { $error = 'JmapProxy HTTP Error: ' . $e->getHttpStatus() . ' ' . $e->getMessage(); } catch (\Exception $e) { $error = 'JmapProxy HTTP Error: ' . $e->getMessage(); } $this->logger->err($error); // fail with a runtime error throw new RuntimeException($error); }