コード例 #1
0
 /**
  * "associate" mode request
  *
  * @param $server to make association with (usually obtained from OpenIdCredentials)
  * @param $manager - dao-like association manager
  * @return OpenIdConsumerAssociation
  **/
 public function associate(HttpUrl $server, OpenIdConsumerAssociationManager $manager)
 {
     Assert::isTrue($server->isValid());
     if ($association = $manager->findByServer($server)) {
         return $association;
     }
     $dhParameters = new DiffieHellmanParameters($this->numberFactory->makeNumber(self::DIFFIE_HELLMAN_G), $this->numberFactory->makeNumber(self::DIFFIE_HELLMAN_P));
     $keyPair = DiffieHellmanKeyPair::generate($dhParameters, $this->randomSource);
     $request = HttpRequest::create()->setMethod(HttpMethod::post())->setUrl($server)->setPostVar('openid.ns', self::NAMESPACE_2_0)->setPostVar('openid.mode', 'associate')->setPostVar('openid.assoc_type', self::ASSOCIATION_TYPE)->setPostVar('openid.session_type', 'DH-SHA1')->setPostVar('openid.dh_modulus', base64_encode($dhParameters->getModulus()->toBinary()))->setPostVar('openid.dh_gen', base64_encode($dhParameters->getGen()->toBinary()))->setPostVar('openid.dh_consumer_public', base64_encode($keyPair->getPublic()->toBinary()));
     $response = $this->httpClient->setFollowLocation(true)->send($request);
     if ($response->getStatus()->getId() != HttpStatus::CODE_200) {
         throw new OpenIdException('bad response code from server');
     }
     $result = $this->parseKeyValueFormat($response->getBody());
     if (empty($result['assoc_handle'])) {
         throw new OpenIdException('can\\t live without handle');
     }
     if (!isset($result['assoc_type']) || $result['assoc_type'] !== self::ASSOCIATION_TYPE) {
         throw new OpenIdException('bad association type');
     }
     if (!isset($result['expires_in']) || !is_numeric($result['expires_in'])) {
         throw new OpenIdException('bad expires');
     }
     if (isset($result['session_type']) && $result['session_type'] == 'DH-SHA1' && isset($result['dh_server_public'])) {
         $secret = sha1($keyPair->makeSharedKey($this->numberFactory->makeFromBinary(base64_decode($result['dh_server_public'])))->toBinary(), true) ^ base64_decode($result['enc_mac_key']);
     } elseif (empty($result['session_type']) && isset($result['mac_key'])) {
         $secret = base64_decode($result['mac_key']);
     } else {
         throw new OpenIdException('no secret in answer');
     }
     return $manager->makeAndSave($result['assoc_handle'], $result['assoc_type'], $secret, Timestamp::makeNow()->modify('+ ' . $result['expires_in'] . ' seconds'), $server);
 }
コード例 #2
0
 public function testDayDifference()
 {
     $today = Date::makeToday();
     $this->dayDifferenceTest($today, $today, 0);
     $timestamp = Timestamp::makeNow();
     $this->dayDifferenceTest($timestamp, $timestamp, 0);
     $left = Date::create('2008-01-12');
     $right = Date::create('2008-01-13');
     $this->dayDifferenceTest($left, $right, 1);
     $left = Date::create('2008-01-12');
     $right = Date::create('2009-01-13');
     $this->dayDifferenceTest($left, $right, 367);
     $left = Date::create('2008-01-12');
     $right = Date::create('2008-01-11');
     $this->dayDifferenceTest($left, $right, -1);
     $left = Timestamp::create('2008-01-12 01:23:00');
     $right = Timestamp::create('2008-01-13 13:01:17');
     $this->dayDifferenceTest($left, $right, 1);
     // change time from winter to summer
     $left = Timestamp::create('2008-03-29 02:00:00');
     $right = Timestamp::create('2008-03-30 02:00:00');
     $this->dayDifferenceTest($left, $right, 1);
     $left = Timestamp::create('2008-03-29 03:00:00');
     $right = Timestamp::create('2008-03-30 03:00:00');
     $this->dayDifferenceTest($left, $right, 1);
     // unsolved giv's case
     // $left = Timestamp::create('2008-10-25 03:00:00');
     // $right = Timestamp::create('2008-10-26 02:59:00');
     // $this->dayDifferenceTest($left, $right, 0);
     return $this;
 }
コード例 #3
0
 public function testSleeping()
 {
     $stamp = Timestamp::makeNow();
     $serializedStamp = serialize($stamp);
     $unserializedStamp = unserialize($serializedStamp);
     $this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
     $this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
     $this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
     $this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
     $this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
 }
コード例 #4
0
 public function testIpAddressProperty()
 {
     foreach (DBTestPool::me()->getPool() as $db) {
         DBPool::me()->setDefault($db);
         $city = TestCity::create()->setName('Khimki');
         TestCity::dao()->add($city);
         $userWithIp = TestUser::create()->setCredentials(Credentials::create()->setNickName('postgreser')->setPassword(sha1('postgreser')))->setLastLogin(Timestamp::makeNow())->setRegistered(Timestamp::makeNow())->setCity($city)->setIp(IpAddress::create('127.0.0.1'));
         TestUser::dao()->add($userWithIp);
         $this->assertTrue($userWithIp->getId() >= 1);
         $this->assertTrue($userWithIp->getIp() instanceof IpAddress);
         $plainIp = DBPool::me()->getByDao(TestUser::dao())->queryColumn(OSQL::select()->get('ip')->from(TestUser::dao()->getTable())->where(Expression::eq('id', $userWithIp->getId())));
         $this->assertEquals($plainIp[0], $userWithIp->getIp()->toString());
         $count = Criteria::create(TestUser::dao())->add(Expression::eq('ip', IpAddress::create('127.0.0.1')))->addProjection(Projection::count('*', 'count'))->getCustom('count');
         $this->assertEquals($count, 1);
     }
 }
コード例 #5
0
 public function testQueueConsumer()
 {
     $c = new AMQPPecl(AMQPCredentials::createDefault());
     $channel = $c->createChannel(1);
     $channel->exchangeDeclare(self::EXCHANGE_NAME, AMQPExchangeConfig::create()->setType(new AMQPExchangeType(AMQPExchangeType::DIRECT))->setDurable(true));
     $inQueueCount = $channel->queueDeclare(self::QUEUE_NAME, AMQPQueueConfig::create()->setDurable(true));
     $this->assertSame(0, $inQueueCount);
     $channel->queueBind(self::QUEUE_NAME, self::EXCHANGE_NAME, self::ROUTING_KEY);
     //cleanup
     $channel->queuePurge(self::QUEUE_NAME);
     for ($i = 1; $i <= self::COUNT_OF_PUBLISH; $i++) {
         $channel->basicPublish(self::EXCHANGE_NAME, self::ROUTING_KEY, AMQPOutgoingMessage::create()->setBody("message {$i}")->setTimestamp(Timestamp::makeNow())->setAppId(__CLASS__)->setMessageId($i)->setContentEncoding('utf-8'));
     }
     $consumer = new AMQPTestCaseQueueConsumer($channel);
     $channel->basicConsume(self::QUEUE_NAME, false, $consumer);
     $i = 0;
     while (true) {
         $message = $consumer->getNextDelivery();
         //send acknowledge to RabbitMQ
         $channel->basicAck($message->getDeliveryTag(), false);
         $i++;
         $this->assertSame($consumer->getConsumerTag(), $message->getConsumerTag());
         $this->assertEquals($i, $message->getMessageId());
         $this->assertEquals(__CLASS__, $message->getAppId());
         $this->assertEquals("message {$i}", $message->getBody());
         if ($i == self::COUNT_OF_PUBLISH) {
             break;
         }
     }
     $channel->basicCancel($consumer->getConsumerTag());
     //observer logic test
     $this->assertSame('ABBBBBC', $consumer->getCheckString());
     //drop channels and close connection
     $c->disconnect();
     $c = new AMQPPecl(AMQPCredentials::createDefault());
     $channel = $c->createChannel(1);
     $channel->exchangeDeclare(self::EXCHANGE_NAME, AMQPExchangeConfig::create()->setType(new AMQPExchangeType(AMQPExchangeType::DIRECT))->setDurable(true));
     //queue must be empty, because we sent acknowledge
     $inQueueCount = $channel->queueDeclare(self::QUEUE_NAME, AMQPQueueConfig::create()->setDurable(true));
     $this->assertSame(0, $inQueueCount);
     //cleanup
     $channel->queuePurge(self::QUEUE_NAME);
 }
コード例 #6
0
 /**
  * @param AMQPChannelInterface $channel
  * @param bool $check
  * @param string $key
  * @param string $queueName
  */
 protected function publishMessages(AMQPChannelInterface $channel, $check = true, $label = 'basic')
 {
     for ($i = 1; $i <= self::COUNT_OF_PUBLISH; $i++) {
         $channelInterface = $channel->basicPublish(self::$queueList[$label]['exchange'], self::$queueList[$label]['key'], AMQPOutgoingMessage::create()->setBody("message {$i}")->setTimestamp(Timestamp::makeNow())->setAppId(__CLASS__)->setMessageId($i)->setContentEncoding('utf-8'));
         if ($check) {
             $this->assertInstanceOf('AMQPChannelInterface', $channelInterface);
         }
     }
     if ($check) {
         $this->checkMessageCount($channel, $label);
     }
 }
コード例 #7
0
 public function __construct()
 {
     $this->date = Timestamp::makeNow();
 }
コード例 #8
0
 public function testSleeping()
 {
     $stamp = Timestamp::makeNow();
     $serializedStamp = serialize($stamp);
     $unserializedStamp = unserialize($serializedStamp);
     $this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
     $this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
     $this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
     $this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
     $this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
     $stamp = Timestamp::create('2039-01-05 12:14:05 Europe/Moscow');
     $serializedStamp = serialize($stamp);
     $unserializedStamp = unserialize($serializedStamp);
     $this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
     $this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
     $this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
     $this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
     $this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
     $stamp = Timestamp::create('1899-12-31 16:07:45 Europe/London');
     $serializedStamp = serialize($stamp);
     $unserializedStamp = unserialize($serializedStamp);
     $this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
     $this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
     $this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
     $this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
     $this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
 }
コード例 #9
0
 public function __construct(Timestamp $timestamp = null)
 {
     $this->timestamp = $timestamp ?: Timestamp::makeNow();
 }