From 2a753f16acfcdea5ab7b8265b2aab795a70782cc Mon Sep 17 00:00:00 2001 From: Ian Neilson Date: Thu, 11 Feb 2021 16:09:48 +0000 Subject: [PATCH] Tests with new minimal sample dataset Add RoleServiceTest2 to testsuite. Simplistic creation of minimal user objects for testing failed due to incoming requirement for UserIdentifiers. --- INSTALL.md | 22 +- lib/Doctrine/deploy/AddGroupRoles.php | 34 +-- lib/Doctrine/deploy/AddServiceGroups.php | 51 ++++ lib/Doctrine/deploy/AddSiteRoles.php | 2 +- lib/Doctrine/deploy/AddSites.php | 18 +- lib/Doctrine/deploy/AddTiers.php | 15 -- lib/Doctrine/deploy/AddTimezones.php | 22 -- lib/Doctrine/deploy/AddUtils.php | 22 +- .../deploy/DeployRequiredDataRunner.php | 8 +- .../deploy/DeploySampleDataRunner.php | 7 +- .../simpleSampleData/CertStatusChanges.xml | 11 + .../simpleSampleData/CertStatusDate.xml | 8 + lib/Doctrine/deploy/simpleSampleData/NGIs.xml | 9 + .../deploy/simpleSampleData/Scopes.xml | 10 + .../simpleSampleData/ServiceEndpoints.xml | 26 ++ .../deploy/simpleSampleData/ServiceGroups.xml | 19 ++ .../deploy/simpleSampleData/Sites.xml | 28 +++ .../deploy/simpleSampleData/UsersAndRoles.xml | 31 +++ .../APIAuthenticationService.php | 4 + tests/DoctrineTestSuite1.php | 8 + tests/doctrine/TestUtil.php | 40 +++- tests/doctrine/truncateDataTables.xml | 61 ++--- tests/phpunit.xml | 41 +++- .../APIAuthenticationServiceTest.php | 166 +++++++++++++ .../lib/Gocdb_Services/RoleServiceTest2.php | 223 ++++++++++++++++++ .../lib/Gocdb_Services/ServiceTestUtil.php | 128 ++++++++++ .../lib/Gocdb_Services/SiteServiceTest.php | 204 ++++++++++++++++ .../lib/Gocdb_Services/UserServiceTest.php | 197 ++++++++++++++++ 28 files changed, 1265 insertions(+), 150 deletions(-) create mode 100644 lib/Doctrine/deploy/AddServiceGroups.php delete mode 100644 lib/Doctrine/deploy/AddTiers.php delete mode 100644 lib/Doctrine/deploy/AddTimezones.php create mode 100644 lib/Doctrine/deploy/simpleSampleData/CertStatusChanges.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/CertStatusDate.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/NGIs.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/Scopes.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/ServiceEndpoints.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/ServiceGroups.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/Sites.xml create mode 100644 lib/Doctrine/deploy/simpleSampleData/UsersAndRoles.xml create mode 100644 tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php create mode 100644 tests/unit/lib/Gocdb_Services/RoleServiceTest2.php create mode 100644 tests/unit/lib/Gocdb_Services/ServiceTestUtil.php create mode 100644 tests/unit/lib/Gocdb_Services/SiteServiceTest.php create mode 100644 tests/unit/lib/Gocdb_Services/UserServiceTest.php diff --git a/INSTALL.md b/INSTALL.md index be67fd19a..48b5eba08 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -422,15 +422,23 @@ $ cd lib/Doctrine $ php deploy/DeployRequiredDataRunner.php requiredData ``` -### Deploy Sample Data +### OPTIONAL: Deploy Sample Data -Optional - you can deploy some sample data to seed your DB with sample users, -sites and services. +You can choose to deploy some sample data to seed your DB with sample users, +sites and services. Two sample data sets are available. Choose one of - -```bash -$ cd lib/Doctrine -$ php deploy/DeploySampleDataRunner.php sampleData -``` +1. Minimal - just enough to get going with no real-world associations. + + ```bash + $ cd lib/Doctrine + $ php deploy/DeploySampleDataRunner.php simpleSampleData + ``` +1. "Real World" - a small subset derived from real data. + + ```bash + $ cd lib/Doctrine + $ php deploy/DeploySampleDataRunner.php sampleData + ``` ### ORACLE ONLY: Deploy an existing DB .dmp file to populate your DB diff --git a/lib/Doctrine/deploy/AddGroupRoles.php b/lib/Doctrine/deploy/AddGroupRoles.php index ab4f7a5d1..23228a918 100644 --- a/lib/Doctrine/deploy/AddGroupRoles.php +++ b/lib/Doctrine/deploy/AddGroupRoles.php @@ -3,38 +3,6 @@ require_once __DIR__."/../bootstrap.php"; require_once __DIR__."/AddUtils.php"; -/** - * AddNGIs.php: Loads a list of NGIs from an XML file and inserts them into - * the doctrine prototype. - * XML format is the output from get_roc_list PI query, e.g: - - - - Patricia - Gomes - Miss - - https://testing.host.com/portal/index.php?Page_Type=View_Object&object_id=113158&grid_id=0 - pgomes@cbpf.br - +55(21)21417419 - - - /C=BR/O=ICPEDU/O=UFF BrGrid CA/O=CBPF/OU=LAFEX/CN=Patricia Gomes - - - - - Regional First Line Support - ROC_LA - group - - - Site Operations Deputy Manager - CBPF - site - - - */ $usersRolesFileName = __DIR__ . "/" . $GLOBALS['dataDir'] . "/UsersAndRoles.xml"; $usersRoles = simplexml_load_file($usersRolesFileName); @@ -125,4 +93,4 @@ } } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddServiceGroups.php b/lib/Doctrine/deploy/AddServiceGroups.php new file mode 100644 index 000000000..c4e7ba75a --- /dev/null +++ b/lib/Doctrine/deploy/AddServiceGroups.php @@ -0,0 +1,51 @@ + $value) { + switch ($key) { + case "NAME": + $name = (string) $value; + break; + case "DESCRIPTION": + $desc = (string) $value; + break; + case "MONITORED": + if ( (string) $value == "Y") {$monitored = true;} + break; + case "CONTACT_EMAIL": + $email = (string) $value; + break; + case "SCOPE": + $scope = (string) $value; + break; + default: + throw new LogicException("Unknown ServiceGroup key in input XML: ". $key); + } + } + $instance->setName($name); + $instance->setDescription($desc); + $instance->setMonitored($monitored); + $instance->setEmail($email); + $instance->addScope(getScope($entityManager, $scope)); + + $entityManager->persist($instance); +} + +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddSiteRoles.php b/lib/Doctrine/deploy/AddSiteRoles.php index 9aef8b5cf..b8fc466b0 100644 --- a/lib/Doctrine/deploy/AddSiteRoles.php +++ b/lib/Doctrine/deploy/AddSiteRoles.php @@ -102,4 +102,4 @@ } } } -$entityManager->flush(); \ No newline at end of file +$entityManager->flush(); diff --git a/lib/Doctrine/deploy/AddSites.php b/lib/Doctrine/deploy/AddSites.php index 699b2297a..bb2210ad8 100644 --- a/lib/Doctrine/deploy/AddSites.php +++ b/lib/Doctrine/deploy/AddSites.php @@ -98,21 +98,7 @@ } $doctrineSite->setCertificationStatus($certStatus); - // get the scope - $dql = "SELECT s FROM Scope s WHERE s.name = ?1"; - $scopes = $entityManager->createQuery($dql) - ->setParameter(1, (string) $xmlSite->SCOPE) - ->getResult(); - /* Error checking: ensure each Site's "SCOPE" refers to exactly - * one SCOPE */ - if(count($scopes) !== 1) { - throw new Exception(count($scopes) . " SCOPEs found with name: " . - $xmlSite->SCOPE); - } - foreach($scopes as $scope) { - $scope = $scope; - } - $doctrineSite->addScope($scope); + $doctrineSite->addScope(getScope($entityManager, (string) $xmlSite->SCOPE)); // get / set the country $dql = "SELECT c FROM Country c WHERE c.name = ?1"; @@ -241,4 +227,4 @@ $entityManager->flush(); } catch (Exception $e) { echo $e->getMessage(); -} \ No newline at end of file +} diff --git a/lib/Doctrine/deploy/AddTiers.php b/lib/Doctrine/deploy/AddTiers.php deleted file mode 100644 index c30485c4a..000000000 --- a/lib/Doctrine/deploy/AddTiers.php +++ /dev/null @@ -1,15 +0,0 @@ -setName($tierName); - $entityManager->persist($tier); -} - -$entityManager->flush(); \ No newline at end of file diff --git a/lib/Doctrine/deploy/AddTimezones.php b/lib/Doctrine/deploy/AddTimezones.php deleted file mode 100644 index 3e86a5d33..000000000 --- a/lib/Doctrine/deploy/AddTimezones.php +++ /dev/null @@ -1,22 +0,0 @@ -setName($name); - $entityManager->persist($doctrineTimezone); -} - -$entityManager->flush(); \ No newline at end of file diff --git a/lib/Doctrine/deploy/AddUtils.php b/lib/Doctrine/deploy/AddUtils.php index 20904d298..a029702f6 100644 --- a/lib/Doctrine/deploy/AddUtils.php +++ b/lib/Doctrine/deploy/AddUtils.php @@ -46,4 +46,24 @@ function isBad($site) { } else { return true; } -} \ No newline at end of file +} +/** + * Return a scope object given a scope name + * @param EntityManager $entityManager + * @param string $scope + * @return \Scope + */ +function getScope($entityManager, $scope) { + // get the scope + $dql = "SELECT s FROM Scope s WHERE s.name = ?1"; + $scopes = $entityManager->createQuery($dql) + ->setParameter(1, $scope) + ->getResult(); + /* Error checking: ensure each Site's "SCOPE" refers to exactly + * one SCOPE */ + if(count($scopes) !== 1) { + throw new Exception(count($scopes) . " SCOPEs found with name: " . $scope); + } + + return $scopes[0]; +} diff --git a/lib/Doctrine/deploy/DeployRequiredDataRunner.php b/lib/Doctrine/deploy/DeployRequiredDataRunner.php index 486968d42..5b030a921 100644 --- a/lib/Doctrine/deploy/DeployRequiredDataRunner.php +++ b/lib/Doctrine/deploy/DeployRequiredDataRunner.php @@ -29,12 +29,6 @@ require __DIR__."/AddCountries.php"; echo "Added Countries OK\n"; -//require __DIR__."/AddTimezones.php"; -//echo "Added Timezones OK\n"; - -require __DIR__."/AddTiers.php"; -echo "Added Tiers OK\n"; - require __DIR__."/AddRoleTypes.php"; echo "Added Roles OK\n"; @@ -42,4 +36,4 @@ echo "Added Certification Statuses OK\n"; require __DIR__."/AddServiceTypes.php"; -echo "Added Service Types OK\n"; \ No newline at end of file +echo "Added Service Types OK\n"; diff --git a/lib/Doctrine/deploy/DeploySampleDataRunner.php b/lib/Doctrine/deploy/DeploySampleDataRunner.php index 06b11c851..1d0985283 100644 --- a/lib/Doctrine/deploy/DeploySampleDataRunner.php +++ b/lib/Doctrine/deploy/DeploySampleDataRunner.php @@ -22,7 +22,7 @@ die("Please specify your data directory (sampleData) \n"); } -print_r("Deploying Sample Data\n"); +print_r("Deploying Sample Data from ".$GLOBALS['dataDir']."\n"); require __DIR__."/AddProjects.php"; echo "Added Projects OK\n"; @@ -49,4 +49,7 @@ echo "Added NGI level Roles OK\n"; require __DIR__."/AddEgiRoles.php"; -echo "Added EGI level Roles OK\n"; \ No newline at end of file +echo "Added EGI level Roles OK\n"; + +require __DIR__."/AddServiceGroups.php"; +echo "Added Service Groups OK\n"; diff --git a/lib/Doctrine/deploy/simpleSampleData/CertStatusChanges.xml b/lib/Doctrine/deploy/simpleSampleData/CertStatusChanges.xml new file mode 100644 index 000000000..5be1583ba --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/CertStatusChanges.xml @@ -0,0 +1,11 @@ + + + + 1262304001 + SITE_1 + Uncertified + Certified + /CN=SOME CN + Record of a change of status + + diff --git a/lib/Doctrine/deploy/simpleSampleData/CertStatusDate.xml b/lib/Doctrine/deploy/simpleSampleData/CertStatusDate.xml new file mode 100644 index 000000000..cd427ac2a --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/CertStatusDate.xml @@ -0,0 +1,8 @@ + + + + SITE_1 + Certified + 01-JAN-10 00.00.01 AM + + diff --git a/lib/Doctrine/deploy/simpleSampleData/NGIs.xml b/lib/Doctrine/deploy/simpleSampleData/NGIs.xml new file mode 100644 index 000000000..f29e8f9a7 --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/NGIs.xml @@ -0,0 +1,9 @@ + + + + NGI-1 + A sample NGI + ngi-contact@ngi-1.org + ngi-1-security@ngi-1.org + + diff --git a/lib/Doctrine/deploy/simpleSampleData/Scopes.xml b/lib/Doctrine/deploy/simpleSampleData/Scopes.xml new file mode 100644 index 000000000..80b16439f --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/Scopes.xml @@ -0,0 +1,10 @@ + + + + + Local + + + EGI + + diff --git a/lib/Doctrine/deploy/simpleSampleData/ServiceEndpoints.xml b/lib/Doctrine/deploy/simpleSampleData/ServiceEndpoints.xml new file mode 100644 index 000000000..d1fb8f9d5 --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/ServiceEndpoints.xml @@ -0,0 +1,26 @@ + + + + SITE-1 + service-1.site-1.org + CE + Y + Y + Local + /DC=org/DC=site-1/CN=service-1.site-1.org + 127.0.0.01 + SL5 + 64 bit + A service on Site 1 + + + + + diff --git a/lib/Doctrine/deploy/simpleSampleData/ServiceGroups.xml b/lib/Doctrine/deploy/simpleSampleData/ServiceGroups.xml new file mode 100644 index 000000000..22d04513e --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/ServiceGroups.xml @@ -0,0 +1,19 @@ + + + + Group1_Services + A test service group + Y + contact@site-1.org + Local + + + diff --git a/lib/Doctrine/deploy/simpleSampleData/Sites.xml b/lib/Doctrine/deploy/simpleSampleData/Sites.xml new file mode 100644 index 000000000..e99e04048 --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/Sites.xml @@ -0,0 +1,28 @@ + + + + SITE-PK-1 + SITE-1 + SITE NUMBER 1 + Test site description for Site 1. + http://www.site-1.org/ + contact@site-1.org + csirt@site-1.org + +12 34 5678 01 + DK + Denmark + NGI-1 + Test + Certified + Europe/Zurich + 127.0.0.1/127.0.0.99 + +12 34 5678 02 + +12 34 5678 03 + EGI + + site-1.org + + -06.47 + 62.00 + + diff --git a/lib/Doctrine/deploy/simpleSampleData/UsersAndRoles.xml b/lib/Doctrine/deploy/simpleSampleData/UsersAndRoles.xml new file mode 100644 index 000000000..b1ed7d386 --- /dev/null +++ b/lib/Doctrine/deploy/simpleSampleData/UsersAndRoles.xml @@ -0,0 +1,31 @@ + + + + Alpha + Beta + + alpha.beta@beta.com + +01 2345 67 0000 + + + /CN=Alpha Beta + + + SITE-1 + + Site Administrator + SITE-1 + site + + + Regional Staff (ROD) + NGI-1 + group + + + COD Staff + EGI + group + + + diff --git a/lib/Gocdb_Services/APIAuthenticationService.php b/lib/Gocdb_Services/APIAuthenticationService.php index f4a77cc49..8b939a04a 100644 --- a/lib/Gocdb_Services/APIAuthenticationService.php +++ b/lib/Gocdb_Services/APIAuthenticationService.php @@ -259,6 +259,10 @@ private function validate($data, $identifier, $type) { throw new \Exception("Invalid x509 DN"); } + //If the entity is of type OIDC subject, do a more thorough check again + if ($type == 'OIDC Subject' && !preg_match("/^([a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12})$/", $identifier)) { + throw new \Exception("Invalid OIDC Subject"); + } } } diff --git a/tests/DoctrineTestSuite1.php b/tests/DoctrineTestSuite1.php index 984979220..ec1d51efc 100644 --- a/tests/DoctrineTestSuite1.php +++ b/tests/DoctrineTestSuite1.php @@ -18,6 +18,10 @@ require_once __DIR__ . '/unit/lib/Gocdb_Services/RoleActionAuthorisationServiceTest.php'; require_once __DIR__ . '/unit/lib/Gocdb_Services/RoleActionMappingServiceTest.php'; require_once __DIR__ . '/unit/lib/Gocdb_Services/ScopeServiceTest.php'; +require_once __DIR__ . '/unit/lib/Gocdb_Services/UserServiceTest.php'; +require_once __DIR__ . '/unit/lib/Gocdb_Services/SiteServiceTest.php'; +require_once __DIR__ . '/unit/lib/Gocdb_Services/RoleServiceTest2.php'; +require_once __DIR__ . '/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php'; require_once __DIR__ . '/writeAPI/siteMethods.php'; require_once __DIR__ . '/writeAPI/serviceMethods.php'; require_once __DIR__ . '/writeAPI/endpointMethods.php'; @@ -50,6 +54,10 @@ public static function suite() { $suite->addTestSuite('RoleActionAuthorisationServiceTest'); $suite->addTestSuite('RoleActionMappingServiceTest'); $suite->addTestSuite('ScopeServiceTest'); + $suite->addTestSuite('UserServiceTest'); + $suite->addTestSuite('SiteServiceTest'); + $suite->addTestSuite('RoleServiceTest2'); + $suite->addTestSuite('APIAuthenticationServiceTest'); $suite->addTestSuite('WriteAPIsiteMethodsTests'); $suite->addTestSuite('WriteAPIserviceMethodsTests'); $suite->addTestSuite('WriteAPIendpointMethodsTests'); diff --git a/tests/doctrine/TestUtil.php b/tests/doctrine/TestUtil.php index ca97235e0..eedafeeba 100644 --- a/tests/doctrine/TestUtil.php +++ b/tests/doctrine/TestUtil.php @@ -11,6 +11,14 @@ */ class TestUtil { + // A helper function for several of the helper functions: + // Create a new object of the given name and call the 'setName' method. + private static function createAndName($className, $name) { + $instance = new $className(); + $instance->setName($name); + return $instance; + } + public static function createRoleActionRecord(){ /*$rar = new RoleActionRecord($updatedByUserId, $updatedByUserPrinciple, $roleId, $rolePreStatus, $roleNewStatus, $roleTypeId, @@ -134,11 +142,37 @@ public static function createSampleCertStatusLog($addedBy = '/some/user'){ } public static function createSampleScope($description, $name){ - $scope = new Scope(); + $scope = self::createAndName('Scope', $name); $scope->setDescription($description); - $scope->setName($name); return $scope; } + public static function createSampleInfrastructure($name){ + return self::createAndName('Infrastructure', $name); + } + public static function createSampleCertStatus($name){ + return self::createAndName('certificationStatus',$name); + } + public static function createSampleCountry($name){ + $country = self::createAndName('country',$name); + $country->setCode('UTP'); + return $country; + } + /** + * Generate a useless minimal Role Action Auth Service + * NB. Should be done in the siteService constructor (?) + */ + public static function createSampleRoleAAS($xmlRoleMappings = null) { + + // Dump mappings to a temporary file + // Create RoleActionMappingService with non-default roleActionMappings file + $roleAMS = new org\gocdb\services\RoleActionMappingService(); + $roleAMS->setRoleActionMappingsXmlPath($xmlRoleMappings); + + // Create RoleActionAuthorisationService with dependencies + $roleAAS = new org\gocdb\services\RoleActionAuthorisationService($roleAMS); + + return $roleAAS; + } public static function createSampleUserIdentifier($name, $key) { $identifier = new UserIdentifier(); @@ -146,7 +180,5 @@ public static function createSampleUserIdentifier($name, $key) { $identifier->setKeyValue($key); return $identifier; } - } - ?> diff --git a/tests/doctrine/truncateDataTables.xml b/tests/doctrine/truncateDataTables.xml index 2973a98bd..0380b72bf 100644 --- a/tests/doctrine/truncateDataTables.xml +++ b/tests/doctrine/truncateDataTables.xml @@ -8,21 +8,21 @@ With the default operation of CLEAN_INSERT, you can specify that you want to TRUNCATE a table and not insert any values by listing that table as an element without any attributes (to ensure an empty table). - + Impt: You can specify DELETE_ALL rather than TRUNCATE in your fixture (see getSetUpOperation()) - to issue a DELETE from which is more portable than a - TRUNCATE table
(some DBs require high privileges for truncate statements - and also do not allow truncates across tables with FK contstraints e.g. Oracle). - + to issue a DELETE from
which is more portable than a + TRUNCATE table
(some DBs require high privileges for truncate statements + and also do not allow truncates across tables with FK contstraints e.g. Oracle). + Ordering of the table elements below is SIGNIFICANT. You must consider - foreign key constraints when deleting data from tables. When + foreign key constraints when deleting data from tables. When DELETE_ALL is used, the order of the tables below is read in REVERSE - by phpunit (so the last table specified is truncated/delete_all first). - - Therefore, entities that hold/own the FKs must be deleted FIRST, e.g. - Site has many Services, therefore since Services holds - the FK (as it is on the 'many' side), this table MUST be cleared before Site ! - + by phpunit (so the last table specified is truncated/delete_all first). + + Therefore, entities that hold/own the FKs must be deleted FIRST, e.g. + Site has many Services, therefore since Services holds + the FK (as it is on the 'many' side), this table MUST be cleared before Site ! + The most common reason you would want to ensure an empty table as a part of your fixture is when your test should be inserting data to that table. @@ -30,26 +30,27 @@ - - + + - + - + - + + - - + + - + - + @@ -58,26 +59,26 @@ - - + + - + - - + + - + - + - + - + diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 8858faf55..c065d13cd 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -9,12 +9,12 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * @author David Meredith + * + * @author David Meredith */--> - - + - - + to do so. We have to be selective on which tests to write for which packages. + --> ../lib/Doctrine/entities/ ../lib/DAOs/ @@ -71,5 +71,22 @@ PHPUnit configuration file for tests. - - \ No newline at end of file + + + + + + + + diff --git a/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php b/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php new file mode 100644 index 000000000..1f30ac5a4 --- /dev/null +++ b/tests/unit/lib/Gocdb_Services/APIAuthenticationServiceTest.php @@ -0,0 +1,166 @@ +dbOpsFactory = new PHPUnit_Extensions_Database_Operation_Factory(); + } + /** + * Overridden. + */ + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + echo "\n\n-------------------------------------------------\n"; + echo "Executing APIAuthEntServiceTest. . .\n"; + } + + /** + * Overridden. Returns the test database connection. + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + protected function getConnection() { + require_once __DIR__ . '/../../../doctrine/bootstrap_pdo.php'; + return getConnectionToTestDB(); + } + + /** + * Overridden. Returns the test dataset. + * Defines how the initial state of the database should look before each test is executed. + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected function getDataSet() { + $dataset = $this->createFlatXMLDataSet(__DIR__ . '/../../../doctrine/truncateDataTables.xml'); + return $dataset; + // Use below to return an empty data set if we don't want to truncate and seed + //return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(); + } + + /** + * Overridden. + */ + protected function getSetUpOperation() { + // CLEAN_INSERT is default + //return PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(); + //return PHPUnit_Extensions_Database_Operation_Factory::UPDATE(); + //return PHPUnit_Extensions_Database_Operation_Factory::NONE(); + // + // Issue a DELETE from
which is more portable than a + // TRUNCATE table
(some DBs require high privileges for truncate statements + // and also do not allow truncates across tables with FK contstraints e.g. Oracle) + return $this->dbOpsFactory->DELETE_ALL(); + } + + /** + * Overridden. + */ + protected function getTearDownOperation() { + // NONE is default + return $this->dbOpsFactory->NONE(); + } + + /** + * Sets up the fixture, e.g create a new entityManager for each test run + * This method is called before each test method is executed. + */ + protected function setUp() { + parent::setUp(); + $this->entityManager = $this->createEntityManager(); + } + + /** + * @return EntityManager + */ + private function createEntityManager(){ + $entityManager = null; // Initialise in local scope to avoid unused variable warnings + require __DIR__ . '/../../../doctrine/bootstrap_doctrine.php'; + return $entityManager; + } + + /** + * Called after setUp() and before each test. Used for common assertions + * across all tests. + */ + protected function assertPreConditions() { + $con = $this->getConnection(); + $fixture = __DIR__ . '/../../../doctrine/truncateDataTables.xml'; + $tables = simplexml_load_file($fixture); + + foreach($tables as $tableName) { + $sql = "SELECT * FROM ".$tableName->getName(); + $result = $con->createQueryTable('results_table', $sql); + if($result->getRowCount() != 0){ + throw new RuntimeException("Invalid fixture. Table has rows: ".$tableName->getName()); + } + } + } + public function testGetAPIAuthentication () { + print __METHOD__ . "\n"; + + $siteData = ServiceTestUtil::getSiteData($this->entityManager); + $siteService = ServiceTestUtil::getSiteService($this->entityManager); + $site = ServiceTestUtil::createAndAddSite($this->entityManager, $siteData); + + $user = TestUtil::createSampleUser('Beta','User'); + $user->setAdmin(true); + + $identifier = TestUtil::createSampleUserIdentifier('X.509','/Beta.User'); + ServiceTestUtil::persistAndFlush($this->entityManager, $identifier); + + $user->addUserIdentifierDoJoin($identifier); + + ServiceTestUtil::persistAndFlush($this->entityManager, $user); + + $authEntServ = new org\gocdb\services\APIAuthenticationService(); + $authEntServ->setEntityManager($this->entityManager); + + $this->assertTrue($authEntServ instanceof org\gocdb\services\APIAuthenticationService, + 'Failed to create APIAuthenticationService'); + + $ident = '/CN=A Dummy Subject'; + $type = 'X509'; + // Start with no APIAuthentication entities to be found + $this->assertNull($authEntServ->getAPIAuthentication($ident, $type), + "Non-null value returned when searching for APIAuthentication entity " . + "for id:{$ident} with type:{$type} when expected none."); + + $authEnt = $siteService->addAPIAuthEntity($site, $user, + array('IDENTIFIER' => $ident, + 'TYPE' => $type, + 'ALLOW_WRITE' => false)); + + $this->assertTrue($authEnt instanceof \APIAuthentication, + "Failed to add APIAuthentication entity for id:{$ident} with type:{$type}."); + + $authEntMatched = $authEntServ->getAPIAuthentication($ident, $type); + + $this->assertTrue($authEnt === $authEntMatched, + "Failed to return APIAuthentication entity for id:{$ident} with type:{$type}."); + + } +} diff --git a/tests/unit/lib/Gocdb_Services/RoleServiceTest2.php b/tests/unit/lib/Gocdb_Services/RoleServiceTest2.php new file mode 100644 index 000000000..d21f488e7 --- /dev/null +++ b/tests/unit/lib/Gocdb_Services/RoleServiceTest2.php @@ -0,0 +1,223 @@ +dbOpsFactory = new PHPUnit_Extensions_Database_Operation_Factory(); + } + /** + * Overridden. + */ + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + echo "\n\n-------------------------------------------------\n"; + echo "Executing RoleServiceTest. . .\n"; + } + + /** + * Overridden. Returns the test database connection. + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + protected function getConnection() { + require_once __DIR__ . '/../../../doctrine/bootstrap_pdo.php'; + return getConnectionToTestDB(); + } + + /** + * Overridden. Returns the test dataset. + * Defines how the initial state of the database should look before each test is executed. + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected function getDataSet() { + return $this->createFlatXMLDataSet(__DIR__ . '/../../../doctrine/truncateDataTables.xml'); + // Use below to return an empty data set if we don't want to truncate and seed + //return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(); + } + + /** + * Overridden. + */ + protected function getSetUpOperation() { + // CLEAN_INSERT is default + //return PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(); + //return PHPUnit_Extensions_Database_Operation_Factory::UPDATE(); + //return PHPUnit_Extensions_Database_Operation_Factory::NONE(); + // + // Issue a DELETE from
which is more portable than a + // TRUNCATE table
(some DBs require high privileges for truncate statements + // and also do not allow truncates across tables with FK contstraints e.g. Oracle) + return $this->dbOpsFactory->DELETE_ALL(); + } + + /** + * Overridden. + */ + protected function getTearDownOperation() { + // NONE is default + return $this->dbOpsFactory->NONE(); + } + + /** + * Sets up the fixture, e.g create a new entityManager for each test run + * This method is called before each test method is executed. + */ + protected function setUp() { + parent::setUp(); + $this->entityManager = $this->createEntityManager(); + $this->util = new TestUtil(); + $this->user = $this->util->createSampleUser("Alpha", "Beta"); + $this->user->setAdmin(true); + + $identifier = $this->util->createSampleUserIdentifier('X.509',"/CN=Alpha Beta"); + $this->entityManager->persist($identifier); + + $this->user->addUserIdentifierDoJoin($identifier); + $this->entityManager->persist($this->user); + + $this->site = $this->util->createSampleSite("Site1"); + $this->entityManager->persist($this->site); + + $this->roleServ = new \org\gocdb\services\Role(); + $this->roleServ->setEntityManager($this->entityManager); + } + + /** + * @return EntityManager + */ + private function createEntityManager(){ + $entityManager = null; // Initialise in local scope to avoid unused variable warnings + require __DIR__ . '/../../../doctrine/bootstrap_doctrine.php'; + return $entityManager; + } + + /** + * Called after setUp() and before each test. Used for common assertions + * across all tests. + */ + protected function assertPreConditions() { + $con = $this->getConnection(); + $fixture = __DIR__ . '/../../../doctrine/truncateDataTables.xml'; + $tables = simplexml_load_file($fixture); + + foreach($tables as $tableName) { + $sql = "SELECT * FROM ".$tableName->getName(); + $result = $con->createQueryTable('results_table', $sql); + if($result->getRowCount() != 0){ + throw new RuntimeException("Invalid fixture. Table has rows: ".$tableName->getName()); + } + } + } + /** + * Create some roles + */ + private function createTestRoles (array $roleNames) { + + foreach ($roleNames as $type) { + $roleType = $this->util->createSampleRoleType($type); + $role = $this->util->createSampleRole($this->user, $roleType, $this->site, \RoleStatus::GRANTED); + $this->entityManager->persist($roleType); + $this->entityManager->persist($role); + $roles[] = $role; + }; + + $this->entityManager->flush(); + + return $roles; + } + /** + * Attach an APIAuthentication credential to user and site + */ + private function addAPIAuthEntity() { + // The only way to add an APIAuthentication credential is by creating + // a site service ... + + $siteServ = new \org\gocdb\services\Site(); + $siteServ->setEntityManager($this->entityManager); + + // No role mappings are created or tested - we rely in user being an admin + $ram = new \org\gocdb\services\RoleActionMappingService(); + $ras = new \org\gocdb\services\RoleActionAuthorisationService($ram); + + $ras->setEntityManager($this->entityManager); + + $siteServ->setRoleActionAuthorisationService($ras); + + $siteServ->addAPIAuthEntity( + $this->site, + $this->user, + array( + "IDENTIFIER" => $this->user->getUserIdentifiers()[0]->getKeyValue(), + "TYPE" => "X509", + "ALLOW_WRITE" => false + ) + ); + return; + } + /** + * Tests begin here + */ + public function testNullCheckOrphanAPIAuth () { + print __METHOD__ . "\n"; + + $roles = $this->createTestRoles(array("Manager","Administrator")); + + // No APIAuthentication credentials are yet assigned so the + // check should pass. + $this->assertNull($this->roleServ->checkOrphanAPIAuth($roles[0])); + + $this->addAPIAuthEntity(); + + // User has two roles so the check should pass. + $this->assertNull($this->roleServ->checkOrphanAPIAuth($roles[0])); + + } + /** + * @depends testNullCheckOrphanAPIAuth + * @expectedException Exception + */ + public function testFailCheckOrphanAPIAuth () { + print __METHOD__ . "\n"; + + $roles = $this->createTestRoles(array("Manager")); + + $this->addAPIAuthEntity(); + + // Should fail because there is only one role. + $this->roleServ->checkOrphanAPIAuth($roles[0]); + } +} diff --git a/tests/unit/lib/Gocdb_Services/ServiceTestUtil.php b/tests/unit/lib/Gocdb_Services/ServiceTestUtil.php new file mode 100644 index 000000000..f0bdcfab5 --- /dev/null +++ b/tests/unit/lib/Gocdb_Services/ServiceTestUtil.php @@ -0,0 +1,128 @@ +persist($instance); + $em->flush(); + } + /** + * Create some test site data + * @param EntityManager $em Entity Manager handle + */ + public static function getSiteData ($em) { + + $infra = TestUtil::createSampleInfrastructure('Production'); + $em->persist($infra); + + $ngi = TestUtil::createSampleNGI('ngi1_'); + $em->persist($ngi); + + $scope = TestUtil::createSampleScope('scope 1', 'Scope1'); + $em->persist($scope); + + $certStatus = TestUtil::createSampleCertStatus('Certified'); + $em->persist($certStatus); + + $country = TestUtil::createSampleCountry('Utopia'); + $em->persist($country); + + $em->flush(); + + $siteData = array ( + 'NGI' => $ngi->getId(), + 'Site' => array( + 'SHORT_NAME' => 's1', + 'DESCRIPTION' => 'A test site', + 'OFFICIAL_NAME' => 'An-official-site', + 'EMAIL' => 'anon@localhost.net', + 'HOME_URL' => 'https://www.s1.localhost.net', + 'CONTACTTEL' => '001 234 567 8', + 'GIIS_URL' => null, + 'LATITUDE' => '0', + 'LONGITUDE' => '0', + 'CSIRTEMAIL' => null, + 'IP_RANGE' => null, + 'IP_V6_RANGE' => null, + 'DOMAIN' => 's1.localhost.net', + 'LOCATION' => null, + 'CSIRTTEL' => '001 234 567 8', + 'EMERGENCYTEL' => '001 234 567 8', + 'EMERGENCYEMAIL' => 'anon@localhost.net', + 'HELPDESKEMAIL' => 'anon@localhost.net', + 'TIMEZONE' => 'GMT'), + 'Scope_ids' => array($scope->getId()), + 'ReservedScope_ids' => array(), + 'ProductionStatus' => $infra->getId(), + 'Certification_Status' => $certStatus->getId(), + 'Country' => $country->getId() + ); + + return $siteData; + } + /** + * Create and return a minimal Site Service instance + * @param \Doctrine\ORM\EntityManager EntityManager $em + * @param array $siteData Minimal initial site data array + * @return \Site $site + */ + public static function createAndAddSite ($em, $siteData) { + + $user = TestUtil::createSampleUser('Alpha','User'); + // We don't want to test all the roleAction logic here so simply make us an admin + $user->setAdmin(true); + + $identifier = TestUtil::createSampleUserIdentifier('X.509', '/Alpha.User'); + ServiceTestUtil::persistAndFlush($em, $identifier); + + $user->addUserIdentifierDoJoin($identifier); + + ServiceTestUtil::persistAndFlush($em, $user); + + $siteService = ServiceTestUtil::getSiteService($em); + + $site = $siteService->addSite($siteData, $user); + + return $site; + } + /** + * Generate minimal Site Service + * @param \Doctrine\ORM\EntityManager EntityManager $em + * @return org\gocdb\services\Site $siteService + */ + public static function getSiteService ($em) { + $siteService = new org\gocdb\services\Site(); + $siteService->setEntityManager($em); + + // Need stubs for both role and scope services + $roleAAS = TestUtil::createSampleRoleAAS(__DIR__ . + "/../../resources/roleActionMappingSamples/TestRoleActionMappings5.xml"); + + $roleAAS->setEntityManager($em); + $siteService->setRoleActionAuthorisationService($roleAAS); + $siteService->setScopeService(ServiceTestUtil::getScopeService($em)); + + return $siteService; + } + /** + * Generate a useless minimal Scope Service + * NB. Should be done in the siteService constructor (?) + */ + private static function getScopeService($em) { + $scopeService = new \org\gocdb\services\Scope(); + $scopeService->setEntityManager($em); + + return $scopeService; + } +} diff --git a/tests/unit/lib/Gocdb_Services/SiteServiceTest.php b/tests/unit/lib/Gocdb_Services/SiteServiceTest.php new file mode 100644 index 000000000..eea333b54 --- /dev/null +++ b/tests/unit/lib/Gocdb_Services/SiteServiceTest.php @@ -0,0 +1,204 @@ +dbOpsFactory = new PHPUnit_Extensions_Database_Operation_Factory(); + } + /** + * Overridden. + */ + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + echo "\n\n-------------------------------------------------\n"; + echo "Executing SiteServiceTest. . .\n"; + } + + /** + * Overridden. Returns the test database connection. + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + protected function getConnection() { + require_once __DIR__ . '/../../../doctrine/bootstrap_pdo.php'; + return getConnectionToTestDB(); + } + + /** + * Overridden. Returns the test dataset. + * Defines how the initial state of the database should look before each test is executed. + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected function getDataSet() { + $dataset = $this->createFlatXMLDataSet(__DIR__ . '/../../../doctrine/truncateDataTables.xml'); + return $dataset; + // Use below to return an empty data set if we don't want to truncate and seed + //return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(); + } + + /** + * Overridden. + */ + protected function getSetUpOperation() { + // CLEAN_INSERT is default + //return PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(); + //return PHPUnit_Extensions_Database_Operation_Factory::UPDATE(); + //return PHPUnit_Extensions_Database_Operation_Factory::NONE(); + // + // Issue a DELETE from
which is more portable than a + // TRUNCATE table
(some DBs require high privileges for truncate statements + // and also do not allow truncates across tables with FK contstraints e.g. Oracle) + return $this->dbOpsFactory->DELETE_ALL(); + } + + /** + * Overridden. + */ + protected function getTearDownOperation() { + // NONE is default + return $this->dbOpsFactory->NONE(); + } + + /** + * Sets up the fixture, e.g create a new entityManager for each test run + * This method is called before each test method is executed. + */ + protected function setUp() { + parent::setUp(); + $this->entityManager = $this->createEntityManager(); + $this->testUtil = new TestUtil(); + } + + /** + * @return EntityManager + */ + private function createEntityManager(){ + $entityManager = null; // Initialise in local scope to avoid unused variable warnings + require __DIR__ . '/../../../doctrine/bootstrap_doctrine.php'; + return $entityManager; + } + + /** + * Called after setUp() and before each test. Used for common assertions + * across all tests. + */ + protected function assertPreConditions() { + $con = $this->getConnection(); + $fixture = __DIR__ . '/../../../doctrine/truncateDataTables.xml'; + $tables = simplexml_load_file($fixture); + + foreach($tables as $tableName) { + $sql = "SELECT * FROM ".$tableName->getName(); + $result = $con->createQueryTable('results_table', $sql); + if($result->getRowCount() != 0){ + throw new RuntimeException("Invalid fixture. Table has rows: ".$tableName->getName()); + } + } + } + /** + * Helper function to persist a test object + */ + protected function persistAndFlush ($instance) { + $this->entityManager->persist($instance); + $this->entityManager->flush(); + } + + /* + * Tests begin here + * First basic check we can instantiate a Site Service and create a site with it. + */ + public function testAddSite() { + print __METHOD__ . "\n"; + + $siteData = ServiceTestUtil::getSiteData($this->entityManager); + $siteService = ServiceTestUtil::getSiteService($this->entityManager); + + // The most basic check + $this->assertTrue($siteService instanceof org\gocdb\services\Site, + 'Site Service failed to create and return a Site service'); + + ServiceTestUtil::createAndAddSite($this->entityManager, $siteData); + + // Check + // N.B. Although getSitesFilterByParams says all the filters are optional, + // in fact, if you don't specify a scope 'EGI' is forced on you :-( + + $this->assertCount(1, $siteService->getSitesFilterByParams( array('scope' => 'Scope1'))); + } + /** + * @depends testAddSite + * Check that authentication entities can be added and removed correctly using the Site Service + */ + public function testAddAPIAuthentication() { + print __METHOD__ . "\n"; + + /** @var \User */ + $user = $this->testUtil->createSampleUser('Beta','User','/Beta.User'); + // We don't want to test all the roleAction logic here so simply make us an admin + $user->setAdmin(true); + $this->persistAndFlush($user); + + $siteData = ServiceTestUtil::getSiteData($this->entityManager); + $siteService = ServiceTestUtil::getSiteService($this->entityManager); + ServiceTestUtil::createAndAddSite($this->entityManager, $siteData); + + $sites = $siteService->getSitesFilterByParams(array('scope' => 'Scope1')); + $site = $sites[0]; + + // Check we can add an authenticationEntity to a site and it is properly + // associated with the user. + + $authEnt = $siteService->addAPIAuthEntity($site, $user, + array('IDENTIFIER' => '/CN=A Dummy Subject' , + 'TYPE' => 'X509', + 'ALLOW_WRITE' => false)); + + $this->assertTrue($authEnt instanceof \APIAuthentication, + 'Site Service failed to add APIAuthentication'); + $siteAuthEnts = $site->getAPIAuthenticationEntities(); + $userAuthEnts = $user->getAPIAuthenticationEntities(); + $this->assertTrue($userAuthEnts[0] === $siteAuthEnts[0], + 'Site Service failed to link user and site APIAuthenticationEntity'); + + // Check the delete and cleanup on site and user sides goes ok + + $this->assertNull($siteService->deleteAPIAuthEntity($authEnt, $user), + 'Site Service failed to delete APIAuthenticationEntity'); + $this->assertEmpty($user->getAPIAuthenticationEntities(), + 'Site Service failed to remove APIAuthenticationEntity from User'); + $this->assertEmpty($site->getAPIAuthenticationEntities(), + 'Site Service failed to remove APIAuthenticationEntity from Site'); + } +} diff --git a/tests/unit/lib/Gocdb_Services/UserServiceTest.php b/tests/unit/lib/Gocdb_Services/UserServiceTest.php new file mode 100644 index 000000000..1aa47a98d --- /dev/null +++ b/tests/unit/lib/Gocdb_Services/UserServiceTest.php @@ -0,0 +1,197 @@ +dbOpsFactory = new PHPUnit_Extensions_Database_Operation_Factory(); + } + /** + * Overridden. + */ + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + echo "\n\n-------------------------------------------------\n"; + echo "Executing UserServiceTest. . .\n"; + } + + /** + * Overridden. Returns the test database connection. + * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection + */ + protected function getConnection() { + require_once __DIR__ . '/../../../doctrine/bootstrap_pdo.php'; + return getConnectionToTestDB(); + } + + /** + * Overridden. Returns the test dataset. + * Defines how the initial state of the database should look before each test is executed. + * @return PHPUnit_Extensions_Database_DataSet_IDataSet + */ + protected function getDataSet() { + return $this->createFlatXMLDataSet(__DIR__ . '/../../../doctrine/truncateDataTables.xml'); + // Use below to return an empty data set if we don't want to truncate and seed + //return new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(); + } + + /** + * Overridden. + */ + protected function getSetUpOperation() { + // CLEAN_INSERT is default + //return PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT(); + //return PHPUnit_Extensions_Database_Operation_Factory::UPDATE(); + //return PHPUnit_Extensions_Database_Operation_Factory::NONE(); + // + // Issue a DELETE from
which is more portable than a + // TRUNCATE table
(some DBs require high privileges for truncate statements + // and also do not allow truncates across tables with FK contstraints e.g. Oracle) + return $this->dbOpsFactory->DELETE_ALL(); + } + + /** + * Overridden. + */ + protected function getTearDownOperation() { + // NONE is default + return $this->dbOpsFactory->NONE(); + } + + /** + * Sets up the fixture, e.g create a new entityManager for each test run + * This method is called before each test method is executed. + */ + protected function setUp() { + parent::setUp(); + $this->entityManager = $this->createEntityManager(); + } + + /** + * @return EntityManager + */ + private function createEntityManager(){ + $entityManager = null; // Initialise in local scope to avoid unused variable warnings + require __DIR__ . '/../../../doctrine/bootstrap_doctrine.php'; + return $entityManager; + } + + /** + * Called after setUp() and before each test. Used for common assertions + * across all tests. + */ + protected function assertPreConditions() { + $con = $this->getConnection(); + $fixture = __DIR__ . '/../../../doctrine/truncateDataTables.xml'; + $tables = simplexml_load_file($fixture); + + foreach($tables as $tableName) { + $sql = "SELECT * FROM ".$tableName->getName(); + $result = $con->createQueryTable('results_table', $sql); + if($result->getRowCount() != 0){ + throw new RuntimeException("Invalid fixture. Table has rows: ".$tableName->getName()); + } + } + } + /** + * Create some test user data + */ + private function getUserData () { + + $userData = array ( + 'TITLE' => 'President', + 'FORENAME' => 'Forename', + 'SURNAME' => 'Surname', + 'EMAIL' => 'forename.surname@somedomain.net', + 'TELEPHONE' => '01234 56789' + ); + + return $userData; + } + /** + * Create a minimal identifier + */ + private function getUserIdentifier () { + + $userIdentifier = array ('NAME'=>'X.509','VALUE'=>'/CN=Forename Surname'); + + return ($userIdentifier); + } + + private function createAndRegisterUser ($userData, $userIdentifier) { + + $userService = new org\gocdb\services\User(); + $userService->setEntityManager($this->entityManager); + $userService->register($userData, $userIdentifier); + + return $userService; + } + /* + * Tests begin here + */ + public function testRegisterUser() { + print __METHOD__ . "\n"; + + $userData = $this->getUserData(); + $userIdentifier = $this->getUserIdentifier(); + $userService = $this->createAndRegisterUser($userData, $userIdentifier); + + $user = $userService->getUserByPrinciple($userIdentifier['VALUE']); + + // Check that we get an instance of User class in the correct namespace returned. + $this->assertTrue($user instanceof \User, 'User service failed to registered and return a User'); + + } + /** + * @depends testRegisterUser + */ + public function testAddAPIAuthentication () { + print __METHOD__ . "\n"; + + $userData = $this->getUserData(); + $userIdentifier = $this->getUserIdentifier(); + $userService = $this->createAndRegisterUser($userData, $userIdentifier); + + $authEnt = new \APIAuthentication(); + $authEnt->setIdentifier($userIdentifier['VALUE']); + $authEnt->setType("X509"); + + $user = $userService->getUserByPrinciple($userIdentifier['VALUE']); + + $user->addAPIAuthenticationEntitiesDoJoin($authEnt); + + $authUser = $authEnt->getUser(); + // Check that both sides of the relationship match + $this->assertEquals($user->getId(), $authUser->getId()); + } +}