Skip to content

Commit

Permalink
Add ApplicationHelper to RemoteVettingService integration test
Browse files Browse the repository at this point in the history
Use the ApplicationHelper itself instead of a mock in the integration
test to test it's behavior.
  • Loading branch information
pablothedude committed Feb 24, 2021
1 parent 31ec0aa commit c49e1c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ services:
self_service.service.application:
class: Surfnet\StepupSelfService\SelfServiceBundle\Service\ApplicationHelper
arguments:
$kernelRootDir: "%kernel.root_dir%"
$kernelProjectDir: "%kernel.project_dir%"

self_service.service.identity:
class: Surfnet\StepupSelfService\SelfServiceBundle\Service\IdentityService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

class ApplicationHelper
{
private $kernelRootDir;
private $kernelProjectDir;

/**
* @param string $kernelRootDir
* @param string $kernelProjectDir
*/
public function __construct($kernelRootDir)
public function __construct($kernelProjectDir)
{
Assert::string($kernelRootDir, 'Kernel root directory must have a string value');
$this->kernelRootDir = $kernelRootDir;
Assert::string($kernelProjectDir, 'Kernel project directory must have a string value');
$this->kernelProjectDir = $kernelProjectDir;
}

/**
Expand All @@ -44,7 +44,7 @@ public function __construct($kernelRootDir)
public function getApplicationVersion()
{
// The buildPath (version string) is the installation directory of the project. And is derived from the
// kernel.root_dir (which is the app folder).
return basename(realpath($this->kernelRootDir . '/../'));
// kernel.project_dir (which is the app folder).
return basename(realpath($this->kernelProjectDir));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,72 +45,20 @@ class RemoteVettingServiceTest extends TestCase
* @var RemoteVettingService
*/
private $service;


private $publicKey = <<<CERT
-----BEGIN CERTIFICATE-----
MIIC6jCCAdICCQC9cRx5wiwWOjANBgkqhkiG9w0BAQsFADA3MRwwGgYDVQQDDBNT
ZWxmU2VydmljZSBTQU1MIFNQMRcwFQYDVQQKDA5EZXZlbG9wbWVudCBWTTAeFw0x
ODA3MzAxMjMwNDdaFw0yMz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eoe+NvOF/UtwjfOAVVlG+0AInum
3AvG9m5zHLFCt3j1JjCxj0cCgYEAv4IrFjiJ2DwsbVBhZDYt+nLR/EmDSqLTEhH6
gVcr2mIJxsbXlEhawg4hctX3TBaTMurL1f0rQIwvug12yDdJgjadDFPF/uTC4cHK
Qp8T2beZHVGg+OX4/nfAW4a0TMYJoDSSzftd7RH88E9DP7+30r6KjKkb3sL/0kyq
df7Qf9kCgYAi1vf0bc6GgWf0CA+7NtZivl4Pw1aZEZI7tKY2cC95KKTycPhxSpq5
g72XdHAp+gaJoSBledEYMJfE5Xsdf5r0F1v5xDe87Dn+zT7UXpw4JrDE16jBKwv1
pTLyJ51aerY27qJEtZ3JqbCux853aa2cxLIoje+5Kxso33bPe0EXGg==
-----END RSA PRIVATE KEY-----
KEY;
/**
* @var RemoteVettingContext
* @var string
*/
private $remoteVettingContext;
private $publicKey = '';
/**
* @var AttributeMapper
* @var string
*/
private $attributeMapper;
private $privateKey = '';
/**
* @var m\LegacyMockInterface|m\MockInterface|IdentityProviderFactory
* @var AttributeMapper
*/
private $identityProviderFactory;
private $attributeMapper;
/**
* @var m\LegacyMockInterface|m\MockInterface|ApplicationHelper
* @var ApplicationHelper
*/
private $applicationHelper;
/**
Expand All @@ -121,10 +69,6 @@ class RemoteVettingServiceTest extends TestCase
* @var FakeIdentityWriter
*/
private $fakeIdentityWriter;
/**
* @var IdentityEncrypter
*/
private $identityEncrypter;
/**
* @var TestLogger
*/
Expand All @@ -133,25 +77,30 @@ class RemoteVettingServiceTest extends TestCase
protected function setUp(): void
{
parent::setUp();

$kernelRootPath = realpath(__DIR__ . '/../../../../../../');

$this->publicKey = file_get_contents($kernelRootPath. '/src/Surfnet/StepupSelfService/SelfServiceBundle/Tests/Resources/encryption.crt');
$this->privateKey = file_get_contents($kernelRootPath . '/src/Surfnet/StepupSelfService/SelfServiceBundle/Tests/Resources/encryption.key');

$this->remoteVettingConfiguration = m::mock(RemoteVettingConfiguration::class);
$this->applicationHelper = m::mock(ApplicationHelper::class);
$this->applicationHelper = new ApplicationHelper($kernelRootPath);
$this->fakeIdentityWriter = new FakeIdentityWriter();
$this->logger = new TestLogger();
$session = new Session(new MockFileSessionStorage());

$this->identityEncrypter = new IdentityEncrypter($this->remoteVettingConfiguration, $this->fakeIdentityWriter);
$identityEncrypter = new IdentityEncrypter($this->remoteVettingConfiguration, $this->fakeIdentityWriter);
$this->attributeMapper = new AttributeMapper($this->remoteVettingConfiguration);
$this->remoteVettingContext = new RemoteVettingContext($session);
$remoteVettingContext = new RemoteVettingContext($session);

$now = new DateTime();
$mockTime = new DateTime('@1614004537',$now->getTimezone());
DateTimeHelper::setCurrentTime($mockTime);

$this->service = new RemoteVettingService(
$this->remoteVettingContext,
$remoteVettingContext,
$this->attributeMapper,
$this->identityEncrypter,
$identityEncrypter,
$this->applicationHelper,
$this->logger
);
Expand Down Expand Up @@ -192,9 +141,6 @@ public function test_happy_flow()
'familyName' => 'familyName',
]);

$this->applicationHelper->shouldReceive('getApplicationVersion')
->andReturn('1.0.0');

$this->remoteVettingConfiguration->shouldReceive("getPublicKey")
->andReturn($this->publicKey);

Expand All @@ -214,7 +160,7 @@ public function test_happy_flow()

// test encrypted result
$result = Decrypter::decrypt($this->fakeIdentityWriter->getData(), $this->privateKey);
$this->assertSame('{"attribute-data":{"local-attributes":{"nameId":"john.doe@example.com","attributes":{"email":["john@example.com"],"firstName":["Johnie"],"familyName":["Doe"],"telephone":["0612345678"]}},"remote-attributes":{"nameId":"john.doe@example.com","attributes":{"emailAddress":["johndoe@example.com"],"givenName":["John"],"familyName":["Doe"],"fullName":["John Doe"]}},"matching-results":{"email":{"local":{"name":"email","value":["john@example.com"]},"remote":{"name":"emailAddress","value":["johndoe@example.com"]},"is-valid":false,"remarks":""},"firstName":{"local":{"name":"firstName","value":["Johnie"]},"remote":{"name":"givenName","value":["John"]},"is-valid":false,"remarks":""},"familyName":{"local":{"name":"familyName","value":["Doe"]},"remote":{"name":"familyName","value":["Doe"]},"is-valid":false,"remarks":""}}},"remarks":"This seems a pretty decent match","name-id":"john.doe@example.com","institution":"stepup.example.com","remote-vetting-source":"mock","application-version":"1.0.0","time":"2021-02-22T14:35:37+00:00"}', $result);
$this->assertSame('{"attribute-data":{"local-attributes":{"nameId":"john.doe@example.com","attributes":{"email":["john@example.com"],"firstName":["Johnie"],"familyName":["Doe"],"telephone":["0612345678"]}},"remote-attributes":{"nameId":"john.doe@example.com","attributes":{"emailAddress":["johndoe@example.com"],"givenName":["John"],"familyName":["Doe"],"fullName":["John Doe"]}},"matching-results":{"email":{"local":{"name":"email","value":["john@example.com"]},"remote":{"name":"emailAddress","value":["johndoe@example.com"]},"is-valid":false,"remarks":""},"firstName":{"local":{"name":"firstName","value":["Johnie"]},"remote":{"name":"givenName","value":["John"]},"is-valid":false,"remarks":""},"familyName":{"local":{"name":"familyName","value":["Doe"]},"remote":{"name":"familyName","value":["Doe"]},"is-valid":false,"remarks":""}}},"remarks":"This seems a pretty decent match","name-id":"john.doe@example.com","institution":"stepup.example.com","remote-vetting-source":"mock","application-version":"Stepup-SelfService","time":"2021-02-22T14:35:37+00:00"}', $result);

// test logs
$this->assertSame([
Expand Down

0 comments on commit c49e1c1

Please sign in to comment.