public function testCreate() { $uniqueApplicationName = makeUniqueName('AccountStoreMappingTest Test Create'); $application = \Stormpath\Resource\Application::instantiate(array('name' => $uniqueApplicationName)); self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMappingWithDir = \Stormpath\Resource\AccountStoreMapping::instantiate(); $accountStoreMappingWithDir->accountStore = self::$directory; $accountStoreMappingWithDir->application = $application; \Stormpath\Resource\AccountStoreMapping::create($accountStoreMappingWithDir); $href = $accountStoreMappingWithDir->href; $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::get($href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStoreMapping', $accountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\Directory', $accountStoreMapping->accountStore); $this->assertEquals($uniqueApplicationName, $accountStoreMapping->application->name); $accountStoreMapping->delete(); $application->delete(); }
public function testAuthenticateWithAccountStore() { $application = self::$application; $groupA = new \stdClass(); $groupA->name = 'New Group in town A: ' . md5(time() . microtime() . uniqid()); $groupA = \Stormpath\Resource\Group::instantiate($groupA); $application->createGroup($groupA); $groupB = new \stdClass(); $groupB->name = 'New Group in town B: ' . md5(time() . microtime() . uniqid()); $groupB = \Stormpath\Resource\Group::instantiate($groupB); $application->createGroup($groupB); $accountStoreMappingA = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $groupA)); $application->createAccountStoreMapping($accountStoreMappingA); $accountStoreMappingB = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $groupB)); $application->createAccountStoreMapping($accountStoreMappingB); $account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'Account Name', 'surname' => 'Surname', 'username' => 'super_unique_username', 'email' => '*****@*****.**', 'password' => 'superP4ss')); $application->createAccount($account); $groupA->addAccount($account); $authenticationRequest = new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => $accountStoreMappingA->getAccountStore())); $result = $application->authenticateAccount($authenticationRequest); $this->assertEquals('*****@*****.**', $result->account->email); try { $authenticationRequest = new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => $accountStoreMappingB->getAccountStore())); $application->authenticateAccount($authenticationRequest); $account->delete(); $accountStoreMappingB->delete(); $accountStoreMappingA->delete(); $groupB->delete(); $groupA->delete(); $this->fail('Authentication should have failed.'); } catch (\Stormpath\Resource\ResourceError $re) { $this->assertEquals(400, $re->getStatus()); $this->assertEquals(7104, $re->getErrorCode()); $this->assertContains('Invalid', $re->getMessage()); $this->assertEquals("Login attempt failed because there is no Account in the Application's associated Account Stores with the specified username or email.", $re->getDeveloperMessage()); $this->assertContains('7104', $re->getMoreInfo()); } try { new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => 'not an instance of AccountStore')); $this->fail('UsernamePasswordRequest instantiation should have failed.'); } catch (\InvalidArgumentException $iae) { $this->assertEquals("The value for accountStore in the \$options array should be an instance of \\Stormpath\\Resource\\AccountStore", $iae->getMessage()); } catch (\Exception $e) { $this->fail('UsernamePasswordRequest instantiation with wrong type for account store should have thrown InvalidArgumentException.'); } $account->delete(); $accountStoreMappingB->delete(); $accountStoreMappingA->delete(); $groupB->delete(); $groupA->delete(); }
public function testCreate() { $application = \Stormpath\Resource\Application::instantiate(array('name' => "App" . md5(time() . microtime() . uniqid()))); self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMappingWithDir = \Stormpath\Resource\AccountStoreMapping::instantiate(); $accountStoreMappingWithDir->accountStore = self::$directory; $accountStoreMappingWithDir->application = $application; \Stormpath\Resource\AccountStoreMapping::create($accountStoreMappingWithDir); $href = $accountStoreMappingWithDir->href; $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::get($href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStoreMapping', $accountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\Directory', $accountStoreMapping->accountStore); $this->assertContains('App', $accountStoreMapping->application->name); $accountStoreMapping->delete(); $application->delete(); }
/** * @test */ public function it_can_add_an_account_store_mapping() { $application = \Stormpath\Resource\Application::instantiate(['name' => makeUniqueName('OrgTest'), 'description' => 'Description of Main App', 'status' => 'enabled']); $application = self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::instantiate(['organization' => self::$organization, 'accountStore' => self::$directory, 'isDefaultAccountStore' => true, 'isDefaultGroupStore' => true]); $test1 = self::$organization->createOrganizationAccountStoreMapping($accountStoreMapping); $this->assertInstanceOf('\\Stormpath\\Resource\\AccountStoreMapping', $test1); $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::instantiate(['accountStore' => self::$organization, 'application' => $application, 'isDefaultAccountStore' => true]); $test2 = $application->createAccountStoreMapping($accountStoreMapping); $this->assertInstanceOf('\\Stormpath\\Resource\\AccountStoreMapping', $test2); $org = Organization::get(self::$organization->href); $this->assertNotNull($org->accountStoreMappings->href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStore', $org->defaultAccountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\AccountStore', $org->defaultGroupStoreMapping); $asm = $org->accountStoreMappings; foreach ($asm as $mapping) { $this->assertEquals($org->href, $mapping->organization->href); $this->assertEquals(self::$directory->href, $mapping->accountStore->href); } $app = Application::get($application->href); $this->assertNotNull($app->accountStoreMappings->href); $asm = $app->accountStoreMappings; foreach ($asm as $mapping) { $this->assertEquals($app->href, $mapping->application->href); $this->assertEquals(self::$organization->href, $mapping->accountStore->href); } $application->delete(); }