function testsanitizeName() { // good names $this->assertIdentical(PSUHardware::sanitizeName("adam"), "ADAM"); $this->assertIdentical(PSUHardware::sanitizeName("adam01"), "ADAM01"); $this->assertIdentical(PSUHardware::sanitizeName("adam-01"), "ADAM-01"); // bad characters $this->assertFalse(PSUHardware::sanitizeName("adam?01")); $this->assertFalse(PSUHardware::sanitizeName("adam_01")); $this->assertFalse(PSUHardware::sanitizeName("adam01!")); // dash at end is invalid $this->assertFalse(PSUHardware::sanitizeName("adam-")); // nonalpha at beginning is invalid $this->assertFalse(PSUHardware::sanitizeName("9adam")); $this->assertFalse(PSUHardware::sanitizeName("-adam")); // too short $this->assertFalse(PSUHardware::sanitizeName("a")); $this->assertFalse(PSUHardware::sanitizeName("ad")); $this->assertFalse(PSUHardware::sanitizeName("ada")); // long enough $this->assertTrue(PSUHardware::sanitizeName("adam")); }
<?php /** * Save changes to hardware from hardware.html. */ if (!IDMObject::authZ('permission', 'ape_hardware')) { die('You do not have hardware privileges.'); } require_once 'PSUHardware.class.php'; if (isset($_POST['ajax'])) { $id = isset($_POST['id']) ? $_POST['id'] : null; $value = isset($_POST['value']) ? $_POST['value'] : null; list($kind, $id) = explode('-', $id); try { $person = PSUHardware::userForID($id); $person = new PSUPerson($person); if ($kind === 'mac') { $person->hardware->changeMAC($id, $value); die(strtolower($person->hardware[$id]['mac_address'])); } elseif ($kind === 'name') { $person->hardware->changeName($id, $value); die(strtolower($person->hardware[$id]['computer_name'])); } elseif ($kind === 'comments') { $person->hardware->changeComments($id, $value); die($person->hardware[$id]['comments']); } } catch (Exception $e) { $_SESSION['errors'][] = 'Error: ' . $e->getMessage(); PSUHTML::redirect($BASE_URL . '/hardware/u/' . $person->username); } }