/** * @param GuzzleResponseInterface $response * @return bool * @throws InvalidTimestampException * @throws UnknownResponseException */ public function assert(GuzzleResponseInterface $response) { $data = json_decode($response->getBody(), true); if (!is_array($data)) { throw new UnknownResponseException($response, "Could not decode the body"); } foreach ($this->requiredFields as $field) { if (!array_key_exists($field, $data)) { throw new UnknownResponseException($response, "Missing required field: '{$field}'"); } } if (array_key_exists('UID', $data) && array_key_exists('UIDSignature', $data) && array_key_exists('signatureTimestamp', $data)) { $this->signatureValidator->assertUid($data['UID'], $data['signatureTimestamp'], $this->secret, $data['UIDSignature']); } return true; }
public function testAssertUidWillThrowExceptionForTimestampOutOfRange() { $time = time() - 181; list($uid, $secret, $expected) = $this->getUidSignature($time); static::setExpectedException('Graze\\Gigya\\Exceptions\\InvalidTimestampException', sprintf("The supplied timestamp: %d is more than 180 seconds different to now: %d", $time, time())); $this->validator->assertUid($uid, $time, $secret, $expected); }