Exemplo n.º 1
0
 /**
  * create dependent objects before running each test
  */
 public final function setUp()
 {
     // run the default setUp() method first
     parent::setUp();
     $password = "******";
     $activation = bin2hex(random_bytes(16));
     $salt = bin2hex(random_bytes(32));
     $hash = hash_pbkdf2("sha512", $password, $salt, 262144);
     // creates and inserts Company to sql for User foreign key relations
     $this->company = new Company(null, "Taco B.", "404 Taco St.", "suite:666", "Attention!!", "NM", "Burque", "87106", "5055551111", "*****@*****.**", "www.tocobell.com");
     $this->company->insert($this->getPDO());
     $_SESSION["company"] = $this->company;
     // creates and inserts Crew to sql for User foreign key relations
     $this->crew = new Crew(null, $this->company->getCompanyId(), "the moon");
     $this->crew->insert($this->getPDO());
     // creates and inserts Access to sql for User foreign key relations
     $this->access = new Access(null, "requestor or admin");
     $this->access->insert($this->getPDO());
     // create and insert a User to own the test Request
     $this->requestor = new User(null, $this->company->getCompanyId(), $this->crew->getCrewId(), $this->access->getAccessId(), "5551212", "Johnny", "Requestorman", "*****@*****.**", $activation, $hash, $salt);
     $this->requestor->insert($this->getPDO());
     $this->admin = new User(null, $this->company->getCompanyId(), $this->crew->getCrewId(), $this->access->getAccessId(), "5552121", "Suzy", "Hughes", "*****@*****.**", $activation, $hash, $salt);
     $this->admin->insert($this->getPDO());
     // calculate the date (just use the time the unit test was setup...)
     $this->VALID_REQUESTTIMESTAMP = new \DateTime();
     $this->VALID_REQUESTACTIONTIMESTAMP = new \DateTime();
 }
Exemplo n.º 2
0
 /**
  * test grabbing all Crews
  **/
 public function testGetAllValidCrews()
 {
     //count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowcount("crew");
     //create a new Crew and insert it into mySQL
     $crew = new Crew(null, $this->company->getCompanyId(), $this->VALID_CREWLOCATION);
     $crew->insert($this->getPDO());
     //grab the data from mySQL and enforce the fields match our expectations
     $pdoCrews = Crew::getAllCrews($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("crew"));
     foreach ($pdoCrews as $pdoCrew) {
         if ($pdoCrew->getCrewId() === $crew->getCrewId()) {
             $this->assertEquals($pdoCrew->getCrewId(), $crew->getCrewId());
             $this->assertEquals($pdoCrew->getCrewLocation(), $crew->getCrewLocation());
             $this->assertEquals($pdoCrew->getCrewCompanyId(), $crew->getCrewCompanyId());
         }
     }
 }
Exemplo n.º 3
0
                 throw new RuntimeException("Crew does not exist", 404);
             }
             $crew->setCrewLocation($requestObject->crewLocation);
             $crew->update($pdo);
             $reply->message = "Crew updated OK";
         } else {
             if ($method === "POST") {
                 $crew = new Crew(null, $requestObject->crewCompanyId, $requestObject->crewLocation);
                 $crew->insert($pdo);
                 $reply->message = "Crew created OK";
             }
         }
     } else {
         if ($method === "DELETE") {
             verifyXsrf();
             $crew = Crew::getCrewByCrewId($pdo, $id);
             if ($crew === null) {
                 throw new RuntimeException("Crew does not exist", 404);
             }
             $crew->delete($pdo);
             $deletedObject = new stdClass();
             $deletedObject->crewId = $id;
             $reply->message = "Crew deleted OK";
         }
     }
 } else {
     //if not an admin, and attempting a method other than get, throw an exception
     if (empty($method) === false && $method !== "GET") {
         throw new RuntimeException("Only administrators are allowed to modify entries", 401);
     }
 }
Exemplo n.º 4
0
         $companyAttn = null;
     }
     if (empty($requestObject->companyUrl) !== true) {
         $companyUrl = filter_var($requestObject->companyUrl, FILTER_SANITIZE_URL);
     } else {
         $companyUrl = null;
     }
 }
 //		if($password !== $verifyPassword) {
 //			throw(new InvalidArgumentException ("Password and verify password must match."));
 //		}
 //create a new company for the user
 $company = new Company(null, $companyAttn, $companyName, $companyAddress1, $companyAddress2, $companyCity, $companyState, $companyZip, "111-111-1111", $companyEmail, $companyUrl);
 $company->insert($pdo);
 //create a new crew for the user
 $crew = new Crew(null, $company->getCompanyId(), "");
 $crew->insert($pdo);
 //create new user
 //create password salt, hash and activation code
 $activation = bin2hex(random_bytes(16));
 $salt = bin2hex(random_bytes(32));
 $hash = hash_pbkdf2("sha512", "password", $salt, 262144);
 $user = new User(null, $company->getCompanyId(), $crew->getCrewId(), Access::ADMIN, "5055551212", $userFirstName, $userLastName, $userEmail, $activation, $hash, $salt);
 $user->insert($pdo);
 $messageSubject = "Time Crunch Account Activation";
 //building the activation link that can travel to another server and still work. This is the link that will be clicked to confirm the account.
 // FIXME: make sure URL is /public_html/activation/$activation
 $basePath = dirname($_SERVER["SCRIPT_NAME"], 4);
 $urlglue = $basePath . "/activation/" . $activation;
 $confirmLink = "https://" . $_SERVER["SERVER_NAME"] . $urlglue;
 $message = <<<EOF