Пример #1
0
	/**
	 * Test that a message can be written to a log file.
	 *
	 * @return \Core\Utilities\Logger\LogFile The log file created.
	 */
	public function testWrite(){
		$type = 'testphpunit';
		$msg  = \BaconIpsumGenerator::Make_a_Sentence();
		$code = '/test/' . Core::RandomHex(6);

		// First, I'll test the functional method.
		\Core\Utilities\Logger\append_to($type, $msg, $code);

		// Now a file should exist called testphpunit.log that contains the line above.
		$this->assertTrue(file_exists(ROOT_PDIR . 'logs/' . $type . '.log'));
		$contents = file_get_contents(ROOT_PDIR . 'logs/' . $type . '.log');
		$this->assertContains($msg, $contents);
		$this->assertContains($code, $contents);

		// And now the class method, (should be identical).
		$type = 'testphpunit';
		$msg  = \BaconIpsumGenerator::Make_a_Sentence();
		$code = '/test/' . Core::RandomHex(6);

		// First, I'll test the functional method.
		$log = new \Core\Utilities\Logger\LogFile($type);
		$log->write($msg, $code);

		// Now a file should exist called testphpunit.log that contains the line above.
		$this->assertTrue($log->exists());
		$contents = $log->getContents();
		$this->assertContains($msg, $contents);
		$this->assertContains($code, $contents);

		return $log;
	}
Пример #2
0
 protected function setUp()
 {
     // Setup some variables that will be used throughout this method.
     $title = 'Blog Bug 409 [' . Core::RandomHex(6) . ']';
     $this->blog = new BlogModel();
     $this->blog->set('title', $title);
     // Make sure the page model has been loaded into this model too.
     $page = $this->blog->getLink('Page');
     $page->set('title', $title);
     $this->blog->save();
     $bacon = new BaconIpsumGenerator();
     // Create an article with an invalid title.
     $this->article = new BlogArticleModel();
     $this->article->setFromArray(['blogid' => $this->blog->get('id'), 'title' => 'Sömé "ḮnvÁlid" & \'Bad\' T¹tle!¡', 'body' => $bacon->getParagraphsAsMarkup(), 'status' => 'published']);
     $this->article->save();
 }
Пример #3
0
	/**
	 * Page to test the UI of various Core elements
	 */
	public function testui(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('g:admin')){
			// This test page is an admin-only utility.
			return View::ERROR_ACCESSDENIED;
		}

		$lorem = new BaconIpsumGenerator();

		$skins = [];
		$admindefault = null;
		foreach(ThemeHandler::GetTheme()->getSkins() as $dat){
			$skins[ $dat['file'] ] = $dat['title'];
			if($dat['admindefault']) $admindefault = $dat['file'];
		}

		if($request->getParameter('skin')){
			$skin = $request->getParameter('skin');
		}
		else{
			$skin = $admindefault;
		}

		$view->mastertemplate = $skin;
		$view->title = 'Test General UI/UX';
		$view->assign('lorem_p', $lorem->getParagraphsAsMarkup(3));
		$view->assign(
			'lis', [
				$lorem->getWord(3),
				$lorem->getWord(3),
				$lorem->getWord(3),
				$lorem->getWord(3),
				$lorem->getWord(3),
			]
		);
		$view->assign('skins', $skins);
		$view->assign('skin', $skin);
	}
Пример #4
0
 /**
  * Test the creation of a blog article based off the newly created blog
  *
  * @depends testCreateBlog
  */
 public function testCreateBlogArticle()
 {
     // Update the current user so it has admin access.
     \Core\user()->set('admin', true);
     // Setup some variables that will be used throughout this method.
     $title = 'New Test Blog Article';
     $randomsnippet = 'Random-Snippet-' . Core::RandomHex(10);
     $lorem = new BaconIpsumGenerator();
     $body = $lorem->getParagraph(1);
     // Tack on the random snipped I'll be looking for.
     $body .= $lorem->getParagraphsAsMarkup(8, $randomsnippet);
     $blog = new BlogModel(self::$TestBlogID);
     $request = new PageRequest('/blog/article/create/' . self::$TestBlogID);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that article creation returns a valid page');
     // The returned data should have a "form" available.  This is the actual creation form.
     /** @var $form Form */
     $form = $view->getVariable('form');
     $this->assertInstanceOf('Form', $form, 'Checking that the form is set from the blog article create controller');
     // Set some variables on the form
     $form->getElement('page[title]')->set('value', $title);
     $form->getElement('page[rewriteurl]')->set('value', $blog->get('rewriteurl') . '/' . \Core\str_to_url($title));
     $form->getElement('model[image]')->set('value', 'public/blog/blog-test-image.png');
     $form->getElement('model[body]')->set('value', $body);
     // Copy in the image
     $src = \Core\Filestore\Factory::File(ROOT_PDIR . 'components/blog/tests/blog-test-image.png');
     /** @var $dest \Core\Filestore\File */
     $dest = \Core\Filestore\Factory::File('public/blog/blog-test-image.png');
     $src->copyTo($dest, true);
     // make sure that it exists
     $this->assertTrue($dest->exists(), 'Checking that files can be copied into the public filestore');
     // And submit this form to the handler.
     // On a successful submission, it should be simply the URL of the blog.
     $formsubmission = call_user_func_array($form->get('callsmethod'), array($form));
     if ($formsubmission === false) {
         throw new Exception(implode("\n", $form->getErrors()));
     }
     // Go to the parent listing page and find this entry.
     $request = new PageRequest($blog->get('rewriteurl'));
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error);
     $html = $view->fetch();
     $this->assertContains($title, $html);
     $this->assertContains('itemtype="http://schema.org/BlogPosting"', $html);
     preg_match_all('#<div[^>]*itemtype="http://schema.org/BlogPosting"[^>]*>.*<a[^>]*href="(.*)"[^>]*>(.*)</a>#msU', $html, $matches);
     // Title should now have three keys, with at least one value each.
     $this->assertNotEmpty($matches[1]);
     $this->assertNotEmpty($matches[2]);
     // This node contains the URL.
     $foundurl = $matches[1][0];
     $foundtitle = trim($matches[2][0]);
     // Make sure the url contains the site url.
     $this->assertStringStartsWith(ROOT_URL, $foundurl);
     // And trim it off.  This is because PageRequest expects that the url is already trimmed.
     $foundurl = '/' . substr($foundurl, strlen(ROOT_URL));
     $this->assertEquals($title, $foundtitle);
     //$this->assertStringStartsWith('/blog/article/view/', $formsubmission, 'Checking that blog article creation was successful');
     // Go to the page and make sure that it loads up!
     $request = new PageRequest($foundurl);
     $request->execute();
     $view = $request->getView();
     $this->assertEquals(200, $view->error, 'Checking that public blog article exists');
     $html = $view->fetch();
     $this->assertContains($title, $html, 'Checking that the public blog article page contains the correct title');
     $this->assertContains($randomsnippet, $html, 'Checking that the public blog article page contains the correct body');
     $this->assertContains('blog-test-image', $html, 'Checking that the public blog article page contains the correct image');
 }
Пример #5
0
	/**
	 * Send the commands to a user to verify they have access to the provided GPG key.
	 *
	 * @param \UserModel $user
	 * @param string     $fingerprint
	 * @param boolean    $cli         Set to false to send non-CLI instructions.
	 *
	 * @return false|string
	 */
	public static function SendVerificationEmail(\UserModel $user, $fingerprint, $cli = true){
		$sentence = trim(\BaconIpsumGenerator::Make_a_Sentence());

		$nonce = \NonceModel::Generate(
			'30 minutes',
			null,
			[
				'sentence' => $sentence,
				'key' => $fingerprint,
				'user' => $user->get('id'),
			]
		);

		$key = $user->get('apikey');
		$url = \Core\resolve_link('/gpgauth/rawverify');
		if($cli){
			$cmd = <<<EOD
echo -n "{$sentence}" \\
| gpg -b -a --default-key $fingerprint \\
| curl --data-binary @- \\
--header "X-Core-Nonce-Key: $nonce" \\
$url

EOD;
		}
		else{
			$cmd = <<<EOD
echo -n "{$sentence}" | gpg -b -a
EOD;
		}


		$email = new \Email();
		$email->templatename = 'emails/user/gpgauth_key_verification.tpl';
		$email->setSubject('GPG Key Change Request');
		$email->assign('key', $fingerprint);
		$email->assign('sentence', $sentence);
		$email->assign('user', $user);
		$email->assign('cmd', $cmd);
		$email->to($user->get('email'));
		$email->setEncryption($fingerprint);

		\SystemLogModel::LogSecurityEvent('/user/gpg/submit', 'Verification requested for key ' . $fingerprint, null, $user->get('id'));

		if(!$email->send()){
			return false;
		}
		else{
			return $nonce;
		}
	}