Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php final class PhabricatorUserEditorTestCase extends PhabricatorTestCase { protecte..

Decoded Output download

<?php

final class PhabricatorUserEditorTestCase extends PhabricatorTestCase {

  protected function getPhabricatorTestCaseConfiguration() {
    return array(
      self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
    );
  }

  public function testRegistrationEmailOK() {
    $env = PhabricatorEnv::beginScopedEnv();
    $env->overrideEnvConfig('auth.email-domains', array('example.com'));

    $this->registerUser(
      'PhabricatorUserEditorTestCaseOK',
      '[email protected]');

    $this->assertTrue(true);
  }

  public function testRegistrationEmailInvalid() {
    $env = PhabricatorEnv::beginScopedEnv();
    $env->overrideEnvConfig('auth.email-domains', array('example.com'));

    $prefix = str_repeat('a', PhabricatorUserEmail::MAX_ADDRESS_LENGTH);
    $email = $prefix.'@[email protected]';

    try {
      $this->registerUser('PhabricatorUserEditorTestCaseInvalid', $email);
    } catch (Exception $ex) {
      $caught = $ex;
    }

    $this->assertTrue($caught instanceof Exception);
  }

  public function testRegistrationEmailDomain() {
    $env = PhabricatorEnv::beginScopedEnv();
    $env->overrideEnvConfig('auth.email-domains', array('example.com'));

    $caught = null;
    try {
      $this->registerUser(
        'PhabricatorUserEditorTestCaseDomain',
        '[email protected]');
    } catch (Exception $ex) {
      $caught = $ex;
    }

    $this->assertTrue($caught instanceof Exception);
  }

  public function testRegistrationEmailApplicationEmailCollide() {
    $app_email = '[email protected]';
    $app_email_object =
      PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail(
        $this->generateNewTestUser());
    $app_email_object->setAddress($app_email);
    $app_email_object->setApplicationPHID('test');
    $app_email_object->save();

    $caught = null;
    try {
      $this->registerUser(
        'PhabricatorUserEditorTestCaseDomain',
        $app_email);
    } catch (Exception $ex) {
      $caught = $ex;
    }
    $this->assertTrue($caught instanceof Exception);
  }

  private function registerUser($username, $email) {
    $user = id(new PhabricatorUser())
      ->setUsername($username)
      ->setRealname($username);

    $email = id(new PhabricatorUserEmail())
      ->setAddress($email)
      ->setIsVerified(0);

    id(new PhabricatorUserEditor())
      ->setActor($user)
      ->createNewUser($user, $email);
  }

}
 ?>

Did this file decode correctly?

Original Code

<?php

final class PhabricatorUserEditorTestCase extends PhabricatorTestCase {

  protected function getPhabricatorTestCaseConfiguration() {
    return array(
      self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
    );
  }

  public function testRegistrationEmailOK() {
    $env = PhabricatorEnv::beginScopedEnv();
    $env->overrideEnvConfig('auth.email-domains', array('example.com'));

    $this->registerUser(
      'PhabricatorUserEditorTestCaseOK',
      '[email protected]');

    $this->assertTrue(true);
  }

  public function testRegistrationEmailInvalid() {
    $env = PhabricatorEnv::beginScopedEnv();
    $env->overrideEnvConfig('auth.email-domains', array('example.com'));

    $prefix = str_repeat('a', PhabricatorUserEmail::MAX_ADDRESS_LENGTH);
    $email = $prefix.'@[email protected]';

    try {
      $this->registerUser('PhabricatorUserEditorTestCaseInvalid', $email);
    } catch (Exception $ex) {
      $caught = $ex;
    }

    $this->assertTrue($caught instanceof Exception);
  }

  public function testRegistrationEmailDomain() {
    $env = PhabricatorEnv::beginScopedEnv();
    $env->overrideEnvConfig('auth.email-domains', array('example.com'));

    $caught = null;
    try {
      $this->registerUser(
        'PhabricatorUserEditorTestCaseDomain',
        '[email protected]');
    } catch (Exception $ex) {
      $caught = $ex;
    }

    $this->assertTrue($caught instanceof Exception);
  }

  public function testRegistrationEmailApplicationEmailCollide() {
    $app_email = '[email protected]';
    $app_email_object =
      PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail(
        $this->generateNewTestUser());
    $app_email_object->setAddress($app_email);
    $app_email_object->setApplicationPHID('test');
    $app_email_object->save();

    $caught = null;
    try {
      $this->registerUser(
        'PhabricatorUserEditorTestCaseDomain',
        $app_email);
    } catch (Exception $ex) {
      $caught = $ex;
    }
    $this->assertTrue($caught instanceof Exception);
  }

  private function registerUser($username, $email) {
    $user = id(new PhabricatorUser())
      ->setUsername($username)
      ->setRealname($username);

    $email = id(new PhabricatorUserEmail())
      ->setAddress($email)
      ->setIsVerified(0);

    id(new PhabricatorUserEditor())
      ->setActor($user)
      ->createNewUser($user, $email);
  }

}

Function Calls

None

Variables

None

Stats

MD5 afcc462b1dfe35a852e1302aa5dff120
Eval Count 0
Decode Time 105 ms