|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\OpenIDBundle\Tests\Storage; |
|
12
|
|
|
|
|
13
|
|
|
use Gaufrette\Exception\FileNotFound; |
|
14
|
|
|
use Gaufrette\File; |
|
15
|
|
|
use Gaufrette\Filesystem; |
|
16
|
|
|
use LoginCidadao\OpenIDBundle\Storage\PublicKey; |
|
17
|
|
|
|
|
18
|
|
|
class PublicKeyTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testPublicKey() |
|
21
|
|
|
{ |
|
22
|
|
|
$filename = 'key.pem'; |
|
23
|
|
|
|
|
24
|
|
|
$file = null; |
|
25
|
|
|
|
|
26
|
|
|
/** @var Filesystem|\PHPUnit_Framework_MockObject_MockObject $filesystem */ |
|
27
|
|
|
$filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock(); |
|
28
|
|
|
$filesystem->expects($this->atLeastOnce()) |
|
29
|
|
|
->method('get')->with($filename, $this->isType('bool')) |
|
30
|
|
|
->willReturnCallback(function ($key, $create = false) use ($filename, $filesystem, &$file) { |
|
31
|
|
|
$this->assertSame($filename, $key); |
|
32
|
|
|
if ($file !== null) { |
|
33
|
|
|
return $file; |
|
34
|
|
|
} elseif ($create === false) { |
|
35
|
|
|
throw new FileNotFound($filename); |
|
36
|
|
|
} else { |
|
37
|
|
|
$file = new File($key, $filesystem); |
|
38
|
|
|
|
|
39
|
|
|
return $file; |
|
40
|
|
|
} |
|
41
|
|
|
}); |
|
42
|
|
|
|
|
43
|
|
|
$publicKey = new PublicKey(); |
|
44
|
|
|
$publicKey->setFilesystem($filesystem, $filename); |
|
45
|
|
|
$pubKey = $publicKey->getPublicKey('clientId'); |
|
46
|
|
|
$privKey = $publicKey->getPrivateKey('clientId'); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertNotNull($pubKey); |
|
49
|
|
|
$this->assertNotNull($privKey); |
|
50
|
|
|
$this->assertSame('RS256', $publicKey->getEncryptionAlgorithm('clientId')); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|