Ejemplo n.º 1
0
 public function testIPv6Validator()
 {
     print __METHOD__ . "\n";
     $validator = new IPv6Validator();
     $errors = array();
     // Valid:
     $errors = $validator->validate('1:2::3:4/64', $errors);
     $this->assertTrue(count($errors) == 0);
     $errors = $validator->validate('2001:0db8:85a3:0000:0000:8a2e:0370:7334', $errors);
     $this->assertTrue(count($errors) == 0);
     $errors = $validator->validate('2001:0db8:85a3::8a2e:0370:7334', $errors);
     $this->assertTrue(count($errors) == 0);
     $errors = $validator->validate('fe80::2000:aff:fea7:f7c', $errors);
     $this->assertTrue(count($errors) == 0);
     $errors = $validator->validate('1:2::3:4/64', $errors);
     $this->assertTrue(count($errors) == 0);
     $errors = $validator->validate('2001:adb8:85a3:7334:0000:0000:0000:0000', $errors);
     $this->assertTrue(count($errors) == 0);
     $errors = $validator->validate('2001:adb8:85a3:7334:0000:0000:0000:0000/40', $errors);
     $this->assertTrue(count($errors) == 0);
     // Invalid:
     $errors = $validator->validate('123:', $errors);
     $this->assertTrue(count($errors) == 1);
     $errors = $validator->validate('fe80::2000:aff:fea7:f7c/0', $errors);
     $this->assertTrue(count($errors) == 2);
     $errors = $validator->validate('fe80::2000:aff:fea7:f7c/illegal', $errors);
     $this->assertTrue(count($errors) == 3);
     $errors = $validator->validate('invalid', $errors);
     $this->assertTrue(count($errors) == 4);
     $errors = $validator->validate('', $errors);
     $this->assertTrue(count($errors) == 5);
     $errors = $validator->validate(' ', $errors);
     $this->assertTrue(count($errors) == 6);
 }
Ejemplo n.º 2
0
 /**
  * Validates user inputted service data against the
  * checks in the gocdb_schema.xml.
  * @param array $se_data containing all the fields for a Service 
  * @throws \Exception If the SE data can't be
  *                   validated. The \Exception message will contain a human
  *                   readable description of which field failed validation.
  * @return null
  */
 private function validate($se_data, $type)
 {
     require_once __DIR__ . '/Validate.php';
     $serv = new \org\gocdb\services\Validate();
     foreach ($se_data as $field => $value) {
         $valid = $serv->validate($type, $field, $value);
         if (!$valid) {
             $error = "{$field} contains an invalid value: {$value}";
             throw new \Exception($error);
         }
     }
     // Apply additional logic for validation that can't be captured solely using gocdb_schema.xml
     if (!empty($se_data['HOST_IP_V6'])) {
         require_once __DIR__ . '/validation/IPv6Validator.php';
         $validator = new \IPv6Validator();
         $errors = array();
         $errors = $validator->validate($se_data['HOST_IP_V6'], $errors);
         if (count($errors) > 0) {
             throw new \Exception($errors[0]);
             // show the first message.
         }
     }
 }
Ejemplo n.º 3
0
 public function testValidateEmptyValue()
 {
     $v = new IPv6Validator();
     $this->assertTrue($v->validate(''));
     $this->assertTrue($v->validate(null));
 }