Skip to content

Commit

Permalink
Refining publish service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Hill committed Dec 14, 2011
1 parent b793591 commit 926ed97
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion config.php
Expand Up @@ -14,7 +14,7 @@ class LRConfig
const SUBMISSION_TOS_URL = "http://www.learningregistry.org/tos/cc0/v0-5";
const GPG_METHOD = "LR-PGP.1.0";
const GPG_OWNER = "system@tncurriculumcenter.org";
const GPG_URL = array("http://beta.tncurriculumcenter.org/GPG/public_key.txt");
const GPG_URL = "http://beta.tncurriculumcenter.org/GPG/public_key.txt";

public static function getURL()
{
Expand Down
19 changes: 7 additions & 12 deletions lib/bencode.php
Expand Up @@ -58,27 +58,19 @@ public function encode($value)
switch($type)
{
case 'integer':

$out.= 'i' . $value . 'e';

break;

case 'string':

$out.= strlen($value) . ':' . utf8_encode($value);

break;

case 'array':

if(!$this->is_associative($value))
{
$out.= 'l';
foreach($value as $entry)
{
$out.= $this->encode($entry);
}

$out.= 'e';
}
else
Expand All @@ -89,14 +81,17 @@ public function encode($value)
{
$out.= $this->encode($key) . $this->encode($entry);
}

$out.= 'e';
}

break;

case 'NULL' :
$out .= $this->encode((string)'NULL');
break;
case 'boolean' :
$out .= $this->encode((string) $value);
break;
default:
throw new bencoding_exception('type must be integer / string or array');
throw new bencoding_exception('type must be integer / string or array. Type is '.$type);
break;
}

Expand Down
25 changes: 14 additions & 11 deletions lib/signature.php
Expand Up @@ -7,7 +7,7 @@ class LRSignature
static function sign_file($hash)
{
$gpg = new Crypt_GPG();
$gpg->addSignKey('wegrata@gmail.com');
$gpg->addSignKey(LRConfig::GPG_OWNER);
$signature = $gpg->sign($hash, Crypt_GPG::SIGN_MODE_CLEAR);
return $signature;
}
Expand All @@ -22,9 +22,11 @@ static function normalize_data($data)
{
if (is_null($data)){
return "null";
} else if (is_numeric($data)){
} else if (is_numeric($data))
{
return strval($data);
} else if (is_bool($data)){
} else if (is_bool($data))
{
return $data ? "true" : "false";
}else if(is_array($data)){
foreach($data as $subKey => $subValue)
Expand All @@ -37,19 +39,20 @@ static function normalize_data($data)

static function format_data_to_sign(LRDocument $document){

unset($document['digital_signature']);
unset($document->digital_signature);

unset($document['_id']);
unset($document['_rev']);
unset($document->_id);
unset($document->_rev);

unset($document['doc_ID']);
unset($document['publishing_node']);
unset($document['update_timestamp']);
unset($document['node_timestamp']);
unset($document['create_timestamp']);
unset($document->doc_id);
unset($document->publishing_node);
unset($document->update_timestamp);
unset($document->node_timestamp);
unset($document->create_timestamp);

$document = self::normalize_data($document);
$encoder = new bencoding();
$document = (array) $document;
$data = utf8_encode($encoder->encode($document));
$hash = hash('SHA256',$data);
return $hash;
Expand Down
2 changes: 1 addition & 1 deletion obj/document.php
Expand Up @@ -25,7 +25,7 @@ class LRDocument
'signer'=>''
);

protected $digital_signature;
public $digital_signature;

/*
* Constructor
Expand Down
2 changes: 1 addition & 1 deletion svc/publish.php
Expand Up @@ -4,7 +4,7 @@
// @license Apache 2.0 License http://www.apache.org/licenses/LICENSE-2.0.html
defined('LREXEC') or die('Access Denied');

require_once('..'.DS.'obj'.DS.'document.php');
require_once(LRDIR.DS.'obj'.DS.'document.php');

class LRPublish extends LRService
{
Expand Down
16 changes: 6 additions & 10 deletions tests/svc/publish.php
Expand Up @@ -2,12 +2,13 @@
// @package LR-PHP
// @copyright 2011 Jeffrey Hill
// @license Apache 2.0 License http://www.apache.org/licenses/LICENSE-2.0.html
require_once(LRDIR.DS.'lr.php');
require_once(LRDIR.DS.'config.php');
require_once('../../lr.php');
require_once('../../config.php');

class LRPublishTest
{
public function testPublish() {
public function testPublish()
{

$doc_1 = new stdClass();
$doc_1->resource_data =
Expand All @@ -29,16 +30,12 @@ public function testPublish() {
"curator"=>"John Doe",
"owner"=>"John Doe",
"submitter"=>"John Doe",
"signer"=>"", // GPG???
"signer"=>LRConfig::GPG_OWNER, // TODO: GPG Public key store provides this?
"submitter_type"=>"agent"
);
LR::init('publish');
// Overloaded static calls only work in PHP 5.3+. Call the service directly to add document
LR::getService()->addDocument($doc_1);
foreach(LR::getService()->documents as $document)
{
$this->assertInstanceOf('LRDocument', $document);
}
$e = LR::execute();
if($e == true)
{
Expand All @@ -48,5 +45,4 @@ public function testPublish() {
}
}

LRPublishTest::testPublish();
?>
LRPublishTest::testPublish();
13 changes: 9 additions & 4 deletions tests/svc/service.php
Expand Up @@ -2,13 +2,18 @@
// @package LR-PHP
// @copyright 2011 Jeffrey Hill
// @license Apache 2.0 License http://www.apache.org/licenses/LICENSE-2.0.html
require_once('../../lr.php');
require_once('../lr.php');
require_once(LRDIR.DS.'svc'.DS.'service.php');

class LRServiceTest extends PHPUnit_Framework_TestCase
{
public function testService() {
//TODO: Convert this to an actual PHPUnitTest
$this->assertFalse(TRUE);

public function testVerb()
{
$lrService = new LRService;
$lrService->setVerb("default");
$result = $lrService->getVerb();
$this->assertEquals("default", $result);
}
}

Expand Down

0 comments on commit 926ed97

Please sign in to comment.