Esempio n. 1
0
 /**
  * @runInSeparateProcess
  * @expectedException \RuntimeException
  */
 public function testRandomWithFailure()
 {
     $this->php = FunctionMocker::start($this, 'Chromabits\\Nucleus\\Support')->mockFunction('function_exists')->mockFunction('openssl_random_pseudo_bytes')->getMock();
     $this->php->expects($this->once())->method('function_exists')->will($this->returnValue(true));
     $this->php->expects($this->once())->method('openssl_random_pseudo_bytes')->will($this->returnValue(false));
     Str::random();
 }
Esempio n. 2
0
 public function testMakeWithHugeJson()
 {
     $factory = new JobFactory();
     $huge = Str::random(2 ** 16);
     $this->setExpectedException(InvalidArgumentException::class);
     $factory->make('test.test', ['huge' => $huge], 7);
 }
Esempio n. 3
0
 /**
  * Construct an instance of a DropdownFactory.
  */
 public function __construct()
 {
     parent::__construct();
     $this->hash = Str::random();
     $this->options = [];
     $this->right = false;
 }
 /**
  * Generate an HMAC key pair.
  *
  * @param int $generatePublicLength
  * @param int $generateSecretLength
  * @param string $algorithm
  *
  * @return KeyPair
  */
 public function generateHmac($generatePublicLength = 256, $generateSecretLength = 512, $algorithm = 'sha512')
 {
     $pair = new KeyPair();
     $pair->public_id = hash($algorithm, Str::random($generatePublicLength));
     $pair->secret_key = hash($algorithm, Str::random($generateSecretLength));
     $pair->type = KeyPairTypes::TYPE_HMAC;
     $pair->data = [];
     return $pair;
 }
Esempio n. 5
0
 public function testVerify()
 {
     $hasher = new HmacHasher();
     $private = Str::random(256);
     $private2 = Str::random(256);
     $hash1 = $hasher->hash('this is a test', $private);
     $hash2 = $hasher->hash('another test', $private2);
     $this->assertEqualsMatrix([[true, $hasher->verify($hash1, 'this is a test', $private)], [false, $hasher->verify($hash1, 'this is a test', $private2)], [false, $hasher->verify($hash2, 'this is a test', $private)], [false, $hasher->verify($hash1, 'th1s 1s 4 t3st', $private)], [false, $hasher->verify($hash2, 'another test', $private)], [true, $hasher->verify($hash2, 'another test', $private2)]]);
 }