-
Notifications
You must be signed in to change notification settings - Fork 135
/
ProcessorTest.php
112 lines (97 loc) · 3.53 KB
/
ProcessorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\SAML2\Assertion;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\MockInterface;
use Psr\Log\LoggerInterface;
use SimpleSAML\SAML2\Assertion\Decrypter;
use SimpleSAML\SAML2\Assertion\Exception\InvalidAssertionException;
use SimpleSAML\SAML2\Assertion\Processor;
use SimpleSAML\SAML2\Assertion\Transformer\TransformerInterface;
use SimpleSAML\SAML2\Assertion\Validation\AssertionValidator;
use SimpleSAML\SAML2\Assertion\Validation\SubjectConfirmationValidator;
use SimpleSAML\SAML2\Configuration\IdentityProvider;
use SimpleSAML\SAML2\Signature\Validator;
use SimpleSAML\SAML2\Utilities\ArrayCollection;
use SimpleSAML\SAML2\XML\saml\Assertion;
use SimpleSAML\SAML2\XML\saml\EncryptedAssertion;
use SimpleSAML\XML\DOMDocumentFactory;
use stdClass;
/**
* @covers \SimpleSAML\SAML2\Assertion\Processor
* @package simplesamlphp/saml2
* @runTestsInSeparateProcesses
*/
final class ProcessorTest extends MockeryTestCase
{
/**
* @var \SimpleSAML\SAML2\Assertion\Processor
*/
private static Processor $processor;
/**
* @var MockInterface&Decrypter
*/
private static MockInterface $decrypter;
public static function setUpBeforeClass(): void
{
self::$decrypter = Mockery::mock(Decrypter::class);
$validator = Mockery::mock(Validator::class);
$assertionValidator = Mockery::mock(AssertionValidator::class);
$subjectConfirmationValidator = Mockery::mock(SubjectConfirmationValidator::class);
$transformer = Mockery::mock(TransformerInterface::class);
$identityProvider = new IdentityProvider([]);
$logger = Mockery::mock(LoggerInterface::class);
self::$processor = new Processor(
self::$decrypter,
$validator,
$assertionValidator,
$subjectConfirmationValidator,
$transformer,
$identityProvider,
$logger,
);
}
/**
* @test
*/
public function processorCorrectlyEncryptsAssertions(): void
{
$encryptedAssertion = EncryptedAssertion::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/saml_EncryptedAssertion.xml'
)->documentElement
);
$assertion = Assertion::fromXML(
DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/saml_Assertion.xml'
)->documentElement
);
$testData = [
[$assertion],
[$encryptedAssertion],
[$assertion, $encryptedAssertion, $assertion],
[$encryptedAssertion, $encryptedAssertion, $encryptedAssertion],
];
foreach ($testData as $assertions) {
self::$decrypter
->shouldReceive('decrypt')
->andReturn($assertion);
$collection = new ArrayCollection($assertions);
$result = self::$processor->decryptAssertions($collection);
self::assertInstanceOf(ArrayCollection::class, $result);
foreach ($result as $assertion) {
self::assertInstanceOf(Assertion::class, $assertion);
}
}
}
/**
* @test
*/
public function unsuportedAssertionsAreRejected(): void
{
$this->expectException(InvalidAssertionException::class);
$this->expectExceptionMessage('The assertion must be of type: EncryptedAssertion or Assertion');
self::$processor->decryptAssertions(new ArrayCollection([new stdClass()]));
}
}