PHPSecInfoのテスト項目を追加
PHPSecInfoネタの続きです。
配賦されているzipアーカイブのphpsecinfo-20060801/PhpSecInfo/Test/Coreあたりを見てもらえれば説明の必要もナサゲですが。。。xUnitと同様で、PhpSecInfo_Test_Coreクラスを継承し、
- _execTestメソッド
- 具体的なテスト内容を記述し、結果レベル(PHPSECINFO_TEST_RESULT_XXXとして定義済)を返す
- XXX:OK, NOTICE, WARN, ERROR, NOTRUN
- _setMessagesメソッド
- 各結果レベルに対するメッセージを定義する
を実装したファイルをTest以下のディレクトリに配置するだけで簡単に作れます。
たとえば、大垣さんのセキュリティ本

Webアプリセキュリティ対策入門 ~あなたのサイトは大丈夫?
- 作者: 大垣靖男
- 出版社/メーカー: 技術評論社
- 発売日: 2006/03/16
- メディア: 単行本
- 購入: 6人 クリック: 54回
- この商品を含むブログ (19件) を見る
<?php
/**
* Test class for shortA_open_tag
*
* @package PhpSecInfo
* @author Hideyuki Shimooka <shimooka@doyouphp.jp>
*/
/**
* require the PhpSecInfo_Test_Core class
*/
require_once('PhpSecInfo/Test/Test_Core.php');
/**
* Test class for short_open_tag
*
* @package PhpSecInfo
*/
class PhpSecInfo_Test_Core_Short_Open_Tag extends PhpSecInfo_Test_Core
{
/**
* This should be a <b>unique</b>, human-readable identifier for this test
*
* @var string
*/
var $test_name = "short_open_tag";
/**
* Checks to see if short_open_tag is enabled
*
*/
function _execTest() {
if (!$this->getBooleanIniValue('short_open_tag')) {
return PHPSECINFO_TEST_RESULT_WARN;
}
return PHPSECINFO_TEST_RESULT_NOTICE;
}
/**
* Set the messages specific to this test
*
*/
function _setMessages() {
parent::_setMessages();
$this->setMessageForResult(
PHPSECINFO_TEST_RESULT_NOTICE, 'en',
'short_open_tag is enabled. For portable, redistributable code, be sure not to use short tags.');
$this->setMessageForResult(
PHPSECINFO_TEST_RESULT_WARN, 'en',
'short_open_tag is disbled. Your code will be disclosed if the short tags (<?) in your scripts. For portable, redistributable code, be sure not to use short tags.');
}
}しかし、PhpSecInfoクラスのloadTestsメソッドで、BAKファイルとか*~ファイルまでinclude_onceしてしまうのはどうかと。。。
if (!is_dir($this_dir->path.DIRECTORY_SEPARATOR.$entry)) {せめて、
if (!is_dir($this_dir->path.DIRECTORY_SEPARATOR.$entry) && preg_match('/\.php$/', $entry)) {ぐらいして欲しいぞ。。。