Пример #1
0
 public function testAccountSelector()
 {
     $value = $this->faker->word;
     $acc = new AccountSelector(AccountBy::ID(), $value);
     $this->assertTrue($acc->getBy()->is('id'));
     $acc->setBy(AccountBy::ADMIN_NAME());
     $this->assertTrue($acc->getBy()->is('adminName'));
     $xml = '<?xml version="1.0"?>' . "\n" . '<account by="' . AccountBy::ADMIN_NAME() . '">' . $value . '</account>';
     $this->assertXmlStringEqualsXmlString($xml, (string) $acc);
     $array = ['account' => ['by' => AccountBy::ADMIN_NAME()->value(), '_content' => $value]];
     $this->assertEquals($array, $acc->toArray());
 }
Пример #2
0
 /**
  * Compute preauth value
  *
  * @param  string|AccountSelector $account The user account.
  * @param  string $key Pre authentication key.
  * @return self.
  */
 public function computeValue($account, $key)
 {
     $timestamp = $this->getTimestamp() > 0 ? $this->getTimestamp() : time();
     $expire = $this->getExpiresTimestamp();
     if ($account instanceof AccountSelector) {
         $preauth = $account->getValue() . '|' . $account->getBy() . '|' . $expire . '|' . $timestamp;
     } else {
         $preauth = $account . '|name|' . $expire . '|' . $timestamp;
     }
     $this->setValue(hash_hmac('sha1', $preauth, $key));
     return $this;
 }