예제 #1
0
 public function testOverrideOrder()
 {
     $outer = PhabricatorEnv::beginScopedEnv();
     $middle = PhabricatorEnv::beginScopedEnv();
     $inner = PhabricatorEnv::beginScopedEnv();
     $caught = null;
     try {
         if (phutil_is_hiphop_runtime()) {
             $middle->__destruct();
         }
         unset($middle);
     } catch (Exception $ex) {
         $caught = $ex;
     }
     $this->assertEqual(true, $caught instanceof Exception, "Destroying a scoped environment which is not on the top of the stack " . "should throw.");
     $caught = null;
     try {
         if (phutil_is_hiphop_runtime()) {
             $inner->__destruct();
         }
         unset($inner);
     } catch (Exception $ex) {
         $caught = $ex;
     }
     $this->assertEqual(true, $caught instanceof Exception, "Destroying a scoped environment which is not on the top of the stack " . "should throw.");
     // Although we popped the other two out-of-order, we still expect to end
     // up in the right state after handling the exceptions, so this should
     // execute without issues.
     if (phutil_is_hiphop_runtime()) {
         $outer->__destruct();
     }
     unset($outer);
 }
 public function testDropUnconfiguredPublicMail()
 {
     list($task, $user, $mail) = $this->buildMail('public');
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('metamta.public-replies', false);
     $mail->save();
     $mail->processReceivedMail();
     $this->assertEqual(MetaMTAReceivedMailStatus::STATUS_NO_PUBLIC_MAIL, $mail->getStatus());
 }
예제 #3
0
 protected function willRunTests()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/scripts/__init_script__.php';
     $config = $this->getComputedConfiguration();
     if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
         LiskDAO::beginIsolateAllLiskEffectsToCurrentProcess();
     }
     $this->env = PhabricatorEnv::beginScopedEnv();
 }
 private function assertEmail($expect, $herald_hints)
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('phabricator.production-uri', 'http://test.com/');
     $env->overrideEnvConfig('metamta.herald.show-hints', $herald_hints);
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection('salmon');
     $body->addTextSection('HEADER', "bass\ntrout\n");
     $body->addHeraldSection('/xscript/');
     $this->assertEqual($expect, $body->render());
 }
 public function testDropDisabledSenderMail()
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('metamta.maniphest.public-create-email', '*****@*****.**');
     $user = $this->generateNewTestUser()->setIsDisabled(true)->save();
     $mail = new PhabricatorMetaMTAReceivedMail();
     $mail->setHeaders(array('Message-ID' => '*****@*****.**', 'From' => $user->loadPrimaryEmail()->getAddress(), 'To' => '*****@*****.**'));
     $mail->save();
     $mail->processReceivedMail();
     $this->assertEqual(MetaMTAReceivedMailStatus::STATUS_DISABLED_SENDER, $mail->getStatus());
 }
 public function testRegistrationEmailDomain()
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('auth.email-domains', array('example.com'));
     $caught = null;
     try {
         $this->registerUser('PhabricatorUserEditorTestCaseDomain', '*****@*****.**');
     } catch (Exception $ex) {
         $caught = $ex;
     }
     $this->assertTrue($caught instanceof Exception);
 }
 public function testDropUnknownSenderMail()
 {
     $this->setManiphestCreateEmail();
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('phabricator.allow-email-users', false);
     $env->overrideEnvConfig('metamta.maniphest.default-public-author', null);
     $mail = new PhabricatorMetaMTAReceivedMail();
     $mail->setHeaders(array('Message-ID' => '*****@*****.**', 'To' => '*****@*****.**', 'From' => '*****@*****.**'));
     $mail->save();
     $mail->processReceivedMail();
     $this->assertEqual(MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, $mail->getStatus());
 }
 public function testMultiplePaymentProviders()
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('phortune.test.enabled', true);
     $method = id(new PhortunePaymentMethod())->setMetadataValue('type', 'test.multiple');
     $caught = null;
     try {
         $provider = $method->buildPaymentProvider();
     } catch (Exception $ex) {
         $caught = $ex;
     }
     $this->assertTrue($caught instanceof PhortuneMultiplePaymentProvidersException, 'Expect exception when more than one provider handles a payment method.');
 }
 public function testAddressSimilarity()
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('metamta.single-reply-handler-prefix', 'prefix');
     $base = '*****@*****.**';
     $same = array('*****@*****.**', '"Abrahamn Lincoln" <*****@*****.**>', '*****@*****.**', '*****@*****.**');
     foreach ($same as $address) {
         $this->assertTrue(PhabricatorMailReceiver::matchAddresses($base, $address), pht('Address %s', $address));
     }
     $diff = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     foreach ($diff as $address) {
         $this->assertFalse(PhabricatorMailReceiver::matchAddresses($base, $address), pht('Address: %s', $address));
     }
 }
 public function testControllerAccessControls()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/support/PhabricatorStartup.php';
     $application_configuration = new AphrontDefaultApplicationConfiguration();
     $host = 'meow.example.com';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $request = id(new AphrontRequest($host, '/'))->setApplicationConfiguration($application_configuration)->setRequestData(array());
     $controller = new PhabricatorTestController();
     $controller->setRequest($request);
     $u_public = id(new PhabricatorUser())->setUsername('public');
     $u_unverified = $this->generateNewTestUser()->setUsername('unverified')->save();
     $u_unverified->setIsEmailVerified(0)->save();
     $u_normal = $this->generateNewTestUser()->setUsername('normal')->save();
     $u_disabled = $this->generateNewTestUser()->setIsDisabled(true)->setUsername('disabled')->save();
     $u_admin = $this->generateNewTestUser()->setIsAdmin(true)->setUsername('admin')->save();
     $u_notapproved = $this->generateNewTestUser()->setIsApproved(0)->setUsername('notapproved')->save();
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('phabricator.base-uri', 'http://' . $host);
     $env->overrideEnvConfig('policy.allow-public', false);
     $env->overrideEnvConfig('auth.require-email-verification', false);
     $env->overrideEnvConfig('auth.email-domains', array());
     $env->overrideEnvConfig('security.require-multi-factor-auth', false);
     // Test standard defaults.
     $this->checkAccess(pht('Default'), id(clone $controller), $request, array($u_normal, $u_admin, $u_unverified), array($u_public, $u_disabled, $u_notapproved));
     // Test email verification.
     $env->overrideEnvConfig('auth.require-email-verification', true);
     $this->checkAccess(pht('Email Verification Required'), id(clone $controller), $request, array($u_normal, $u_admin), array($u_unverified, $u_public, $u_disabled, $u_notapproved));
     $this->checkAccess(pht('Email Verification Required, With Exception'), id(clone $controller)->setConfig('email', false), $request, array($u_normal, $u_admin, $u_unverified), array($u_public, $u_disabled, $u_notapproved));
     $env->overrideEnvConfig('auth.require-email-verification', false);
     // Test admin access.
     $this->checkAccess(pht('Admin Required'), id(clone $controller)->setConfig('admin', true), $request, array($u_admin), array($u_normal, $u_unverified, $u_public, $u_disabled, $u_notapproved));
     // Test disabled access.
     $this->checkAccess(pht('Allow Disabled'), id(clone $controller)->setConfig('enabled', false), $request, array($u_normal, $u_unverified, $u_admin, $u_disabled, $u_notapproved), array($u_public));
     // Test no login required.
     $this->checkAccess(pht('No Login Required'), id(clone $controller)->setConfig('login', false), $request, array($u_normal, $u_unverified, $u_admin, $u_public), array($u_disabled, $u_notapproved));
     // Test public access.
     $this->checkAccess(pht('Public Access'), id(clone $controller)->setConfig('public', true), $request, array($u_normal, $u_unverified, $u_admin), array($u_disabled, $u_public));
     $env->overrideEnvConfig('policy.allow-public', true);
     $this->checkAccess(pht('Public + configured'), id(clone $controller)->setConfig('public', true), $request, array($u_normal, $u_unverified, $u_admin, $u_public), array($u_disabled, $u_notapproved));
     $env->overrideEnvConfig('policy.allow-public', false);
     $app = PhabricatorApplication::getByClass('PhabricatorTestApplication');
     $app->reset();
     $app->setPolicy(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicies::POLICY_NOONE);
     $app_controller = id(clone $controller)->setCurrentApplication($app);
     $this->checkAccess(pht('Application Controller'), $app_controller, $request, array(), array($u_normal, $u_unverified, $u_admin, $u_public, $u_disabled, $u_notapproved));
     $this->checkAccess(pht('Application Controller'), id(clone $app_controller)->setConfig('login', false), $request, array($u_normal, $u_unverified, $u_admin, $u_public), array($u_disabled, $u_notapproved));
 }
예제 #11
0
 protected function willRunTests()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/scripts/__init_script__.php';
     $config = $this->getComputedConfiguration();
     if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
         LiskDAO::beginIsolateAllLiskEffectsToCurrentProcess();
     }
     if ($config[self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES]) {
         ++self::$storageFixtureReferences;
         if (!self::$storageFixture) {
             self::$storageFixture = $this->newStorageFixture();
         }
     }
     $this->env = PhabricatorEnv::beginScopedEnv();
 }
예제 #12
0
 public function testOverrideOrder()
 {
     $outer = PhabricatorEnv::beginScopedEnv();
     $inner = PhabricatorEnv::beginScopedEnv();
     $caught = null;
     try {
         $outer->__destruct();
     } catch (Exception $ex) {
         $caught = $ex;
     }
     $this->assertTrue($caught instanceof Exception, 'Destroying a scoped environment which is not on the top of the stack ' . 'should throw.');
     if (phutil_is_hiphop_runtime()) {
         $inner->__destruct();
     }
     unset($inner);
     if (phutil_is_hiphop_runtime()) {
         $outer->__destruct();
     }
     unset($outer);
 }
예제 #13
0
 protected function willRunTests()
 {
     $config = $this->getComputedConfiguration();
     if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) {
         LiskDAO::beginIsolateAllLiskEffectsToCurrentProcess();
     }
     $this->env = PhabricatorEnv::beginScopedEnv();
     // NOTE: While running unit tests, we act as though all applications are
     // installed, regardless of the install's configuration. Tests which need
     // to uninstall applications are responsible for adjusting state themselves
     // (such tests are exceedingly rare).
     $this->env->overrideEnvConfig('phabricator.uninstalled-applications', array());
     $this->env->overrideEnvConfig('phabricator.show-beta-applications', true);
     // Reset application settings to defaults, particularly policies.
     $this->env->overrideEnvConfig('phabricator.application-settings', array());
     // We can't stub this service right now, and it's not generally useful
     // to publish notifications about test execution.
     $this->env->overrideEnvConfig('notification.enabled', false);
     // TODO: Remove this when we remove "releeph.installed".
     $this->env->overrideEnvConfig('releeph.installed', true);
     $this->env->overrideEnvConfig('phabricator.base-uri', 'http://phabricator.example.com');
 }
 /**
  * Verify that POLICY_PUBLIC is interpreted as POLICY_USER when public
  * policies are disallowed.
  */
 public function testPublicPolicyDisabled()
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('policy.allow-public', false);
     $this->expectVisibility($this->buildObject(PhabricatorPolicies::POLICY_PUBLIC), array('public' => false, 'user' => true, 'admin' => true), 'Public Policy (Disabled in Config)');
 }