From d6ae92fc7256fcd1bb6961d86ba03890b753bcc8 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Thu, 27 May 2021 18:51:28 +0000 Subject: [PATCH] try to get all JsonRequestHandlerController Tests running with success, add page for creating raw transactions --- .../JsonRequestHandlerController.php | 22 +- .../src/Controller/TransactionsController.php | 75 ++++++- .../src/Model/Messages/Gradido/Key.php | 96 --------- .../Model/Messages/Gradido/ReceiverAmount.php | 85 -------- .../Model/Messages/Gradido/SenderAmount.php | 119 ----------- .../Model/Messages/Gradido/SignatureMap.php | 65 ------ .../Model/Messages/Gradido/SignaturePair.php | 123 ----------- .../Messages/Gradido/StateCreateGroup.php | 114 ----------- .../Gradido/StateGroupChangeParent.php | 114 ----------- .../src/Model/Messages/Gradido/Timestamp.php | 101 --------- .../Messages/Gradido/TimestampSeconds.php | 67 ------ .../Model/Messages/Gradido/Transaction.php | 166 --------------- .../Messages/Gradido/TransactionBody.php | 193 ------------------ .../Messages/Gradido/TransactionCreation.php | 136 ------------ .../src/Model/Messages/Gradido/Transfer.php | 85 -------- .../src/Model/Transactions/Transaction.php | 9 +- .../Transactions/TransactionTransfer.php | 2 +- .../Transactions/manual_transaction.ctp | 63 ++++++ .../tests/Fixture/StateBalancesFixture.php | 7 +- .../JsonRequestHandlerControllerTest.php | 27 +-- ...actionJsonRequestHandlerControllerTest.php | 174 ---------------- 21 files changed, 181 insertions(+), 1662 deletions(-) delete mode 100644 community_server/src/Model/Messages/Gradido/Key.php delete mode 100644 community_server/src/Model/Messages/Gradido/ReceiverAmount.php delete mode 100644 community_server/src/Model/Messages/Gradido/SenderAmount.php delete mode 100644 community_server/src/Model/Messages/Gradido/SignatureMap.php delete mode 100644 community_server/src/Model/Messages/Gradido/SignaturePair.php delete mode 100644 community_server/src/Model/Messages/Gradido/StateCreateGroup.php delete mode 100644 community_server/src/Model/Messages/Gradido/StateGroupChangeParent.php delete mode 100644 community_server/src/Model/Messages/Gradido/Timestamp.php delete mode 100644 community_server/src/Model/Messages/Gradido/TimestampSeconds.php delete mode 100644 community_server/src/Model/Messages/Gradido/Transaction.php delete mode 100644 community_server/src/Model/Messages/Gradido/TransactionBody.php delete mode 100644 community_server/src/Model/Messages/Gradido/TransactionCreation.php delete mode 100644 community_server/src/Model/Messages/Gradido/Transfer.php create mode 100644 community_server/src/Template/Transactions/manual_transaction.ctp delete mode 100644 community_server/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php diff --git a/community_server/src/Controller/JsonRequestHandlerController.php b/community_server/src/Controller/JsonRequestHandlerController.php index 12e03be8d..4013ace9f 100644 --- a/community_server/src/Controller/JsonRequestHandlerController.php +++ b/community_server/src/Controller/JsonRequestHandlerController.php @@ -340,12 +340,13 @@ class JsonRequestHandlerController extends AppController { return; } $transaction_body = $transaction->getTransactionBody(); - $transaction_type_name = $transaction_body->getTransactionTypeName(); - $senderUser = null; - if($transaction_type_name === 'transfer') { - $senderUser = $transaction_body->getSpecificTransaction()->getSenderUser(); - } else if($transaction_type_name === 'creation') { - $senderUser = $transaction->getFirstSigningUser(); + $senderUser = $transaction->getFirstSigningUser(); + if($transaction_body != null) { + $transaction_type_name = $transaction_body->getTransactionTypeName(); + + if($transaction_type_name === 'transfer') { + $senderUser = $transaction_body->getSpecificTransaction()->getSenderUser(); + } } // send notification email $noReplyEmail = Configure::read('noReplyEmail'); @@ -373,6 +374,15 @@ class JsonRequestHandlerController extends AppController { private function putTransaction($transactionBase64) { $transaction = new Transaction($transactionBase64); + //echo "new transaction\n$transactionBase64\n"; + /*try { + $transactionBin = sodium_base642bin($transactionBase64, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING); + $transaction = new Transaction($transactionBin); + } catch(\SodiumException $e) { + //echo 'exception: '. $e->getMessage(); + return $this->returnJson(['state' => 'error', 'msg' => 'error decoding base 64', 'details' => $e->getMessage(), 'base64' => $transactionBase64]); + }*/ + //echo "after new transaction
"; if($transaction->hasErrors()) { $this->sendEMailTransactionFailed($transaction, 'parse'); diff --git a/community_server/src/Controller/TransactionsController.php b/community_server/src/Controller/TransactionsController.php index 90e78b7fb..67526dfcc 100644 --- a/community_server/src/Controller/TransactionsController.php +++ b/community_server/src/Controller/TransactionsController.php @@ -7,6 +7,7 @@ use Model\Transactions\Transaction; use Model\Transactions\TransactionBody; use Cake\Core\Configure; +use Cake\I18n\Time; use Cake\ORM\TableRegistry; /** @@ -24,7 +25,7 @@ class TransactionsController extends AppController parent::initialize(); $this->loadComponent('GradidoNumber'); $this->loadComponent('JsonRpcRequestClient'); - $this->Auth->allow(['decode']); + $this->Auth->allow(['decode', 'manualTransaction']); } /** @@ -170,6 +171,78 @@ class TransactionsController extends AppController $this->set('transaction', $transaction); } + public function manualTransaction() + { + if ($this->request->is('post')) { + $data = $this->request->getData(); + $type = $data['type']; + + $transaction = new \Proto\Gradido\GradidoTransaction(); + $transactionBody = new \Proto\Gradido\TransactionBody(); + $transactionBody->setMemo($data['memo']); + $created = new \Proto\Gradido\TimestampSeconds(); + $now = new Time(); + $created->setSeconds($now->getTimestamp()); + $transactionBody->setCreated($created); + if($type == "creation") { + $creation = new \Proto\Gradido\GradidoCreation(); + $target_date = new \Proto\Gradido\TimestampSeconds(); + $target_time = new Time($data['target_date']); + $target_date->setSeconds($target_time->getTimestamp()); + $creation->setTargetDate($target_date); + $receiver = new \Proto\Gradido\TransferAmount(); + $receiver->setAmount(intval($data['amount'])); + $receiver->setPubkey(hex2bin($data['target_public_key'])); + $creation->setReceiver($receiver); + $transactionBody->setCreation($creation); + } else if($type == "transfer") { + $transfer = new \Proto\Gradido\GradidoTransfer(); + $local_transfer = new \Proto\Gradido\LocalTransfer(); + $sender = new \Proto\Gradido\TransferAmount(); + $sender->setAmount(intval($data['amount'])); + $sender->setPubkey(hex2bin($data['sender_public_key'])); + $local_transfer->setSender($sender); + $local_transfer->setReceiver(hex2bin($data['receiver_public_key'])); + $transfer->setLocal($local_transfer); + $transactionBody->setTransfer($transfer); + } + $body_bytes = $transactionBody->serializeToString(); + $transaction->setBodyBytes($body_bytes); + + $protoSigMap = new \Proto\Gradido\SignatureMap(); + $sigPairs = $protoSigMap->getSigPair(); + //echo "sigPairs: "; var_dump($sigPairs); echo "
"; + //return null; + + // sign with keys + //foreach($keys as $key) { + $sigPair = new \Proto\Gradido\SignaturePair(); + $sigPair->setPubKey(hex2bin($data['signer_public_key'])); + + $signature = sodium_crypto_sign_detached($body_bytes, hex2bin($data['signer_private_key'])); + echo "signature: " . bin2hex($signature). "
"; + $sigPair->setEd25519($signature); + + $sigPairs[] = $sigPair; + // SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING + // SODIUM_BASE64_VARIANT_ORIGINAL + $transaction->setSigMap($protoSigMap); + //var_dump($protoSigMap); + $transaction_bin = $transaction->serializeToString(); +// $url_safe = sodium_bin2base64($transaction_bin, sodium_base64_VARIANT_ORIGINAL); + $base64 = [ + //'original' => sodium_bin2base64($transaction_bin, sodium_base64_VARIANT_ORIGINAL), + //'original_nopadding' => sodium_bin2base64($transaction_bin, sodium_base64_VARIANT_ORIGINAL_NO_PADDING), + //'urlsafe' => sodium_bin2base64($transaction_bin, sodium_base64_VARIANT_URLSAFE), + 'urlsafe_nopadding' => sodium_bin2base64($transaction_bin, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING), + 'php' => base64_encode($transaction_bin) + + ]; + + $this->set('base64', $base64); + } + } + public function decode() { $this->viewBuilder()->setLayout('frontend'); diff --git a/community_server/src/Model/Messages/Gradido/Key.php b/community_server/src/Model/Messages/Gradido/Key.php deleted file mode 100644 index b6190304c..000000000 --- a/community_server/src/Model/Messages/Gradido/Key.php +++ /dev/null @@ -1,96 +0,0 @@ -model.messages.gradido.Key - */ -class Key extends \Google\Protobuf\Internal\Message -{ - protected $key; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $ed25519 - * ed25519 signature (libsodium default) - * @type string $ed25519_ref10 - * ed25519 ref10 signature - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * ed25519 signature (libsodium default) - * - * Generated from protobuf field bytes ed25519 = 2; - * @return string - */ - public function getEd25519() - { - return $this->readOneof(2); - } - - /** - * ed25519 signature (libsodium default) - * - * Generated from protobuf field bytes ed25519 = 2; - * @param string $var - * @return $this - */ - public function setEd25519($var) - { - GPBUtil::checkString($var, False); - $this->writeOneof(2, $var); - - return $this; - } - - /** - * ed25519 ref10 signature - * - * Generated from protobuf field bytes ed25519_ref10 = 3; - * @return string - */ - public function getEd25519Ref10() - { - return $this->readOneof(3); - } - - /** - * ed25519 ref10 signature - * - * Generated from protobuf field bytes ed25519_ref10 = 3; - * @param string $var - * @return $this - */ - public function setEd25519Ref10($var) - { - GPBUtil::checkString($var, False); - $this->writeOneof(3, $var); - - return $this; - } - - /** - * @return string - */ - public function getKey() - { - return $this->whichOneof("key"); - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/ReceiverAmount.php b/community_server/src/Model/Messages/Gradido/ReceiverAmount.php deleted file mode 100644 index 240c5a6fe..000000000 --- a/community_server/src/Model/Messages/Gradido/ReceiverAmount.php +++ /dev/null @@ -1,85 +0,0 @@ -model.messages.gradido.ReceiverAmount - */ -class ReceiverAmount extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field bytes ed25519_receiver_pubkey = 1; - */ - private $ed25519_receiver_pubkey = ''; - /** - * Generated from protobuf field sint64 amount = 2; - */ - private $amount = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $ed25519_receiver_pubkey - * @type int|string $amount - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field bytes ed25519_receiver_pubkey = 1; - * @return string - */ - public function getEd25519ReceiverPubkey() - { - return $this->ed25519_receiver_pubkey; - } - - /** - * Generated from protobuf field bytes ed25519_receiver_pubkey = 1; - * @param string $var - * @return $this - */ - public function setEd25519ReceiverPubkey($var) - { - GPBUtil::checkString($var, False); - $this->ed25519_receiver_pubkey = $var; - - return $this; - } - - /** - * Generated from protobuf field sint64 amount = 2; - * @return int|string - */ - public function getAmount() - { - return $this->amount; - } - - /** - * Generated from protobuf field sint64 amount = 2; - * @param int|string $var - * @return $this - */ - public function setAmount($var) - { - GPBUtil::checkInt64($var); - $this->amount = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/SenderAmount.php b/community_server/src/Model/Messages/Gradido/SenderAmount.php deleted file mode 100644 index 52a41f71f..000000000 --- a/community_server/src/Model/Messages/Gradido/SenderAmount.php +++ /dev/null @@ -1,119 +0,0 @@ -model.messages.gradido.SenderAmount - */ -class SenderAmount extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field bytes ed25519_sender_pubkey = 1; - */ - private $ed25519_sender_pubkey = ''; - /** - * Generated from protobuf field sint64 amount = 2; - */ - private $amount = 0; - /** - * sender balance after transaction, including perishability - * - * Generated from protobuf field sint64 senderFinalBalance = 3; - */ - private $senderFinalBalance = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $ed25519_sender_pubkey - * @type int|string $amount - * @type int|string $senderFinalBalance - * sender balance after transaction, including perishability - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field bytes ed25519_sender_pubkey = 1; - * @return string - */ - public function getEd25519SenderPubkey() - { - return $this->ed25519_sender_pubkey; - } - - /** - * Generated from protobuf field bytes ed25519_sender_pubkey = 1; - * @param string $var - * @return $this - */ - public function setEd25519SenderPubkey($var) - { - GPBUtil::checkString($var, False); - $this->ed25519_sender_pubkey = $var; - - return $this; - } - - /** - * Generated from protobuf field sint64 amount = 2; - * @return int|string - */ - public function getAmount() - { - return $this->amount; - } - - /** - * Generated from protobuf field sint64 amount = 2; - * @param int|string $var - * @return $this - */ - public function setAmount($var) - { - GPBUtil::checkInt64($var); - $this->amount = $var; - - return $this; - } - - /** - * sender balance after transaction, including perishability - * - * Generated from protobuf field sint64 senderFinalBalance = 3; - * @return int|string - */ - public function getSenderFinalBalance() - { - return $this->senderFinalBalance; - } - - /** - * sender balance after transaction, including perishability - * - * Generated from protobuf field sint64 senderFinalBalance = 3; - * @param int|string $var - * @return $this - */ - public function setSenderFinalBalance($var) - { - GPBUtil::checkInt64($var); - $this->senderFinalBalance = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/SignatureMap.php b/community_server/src/Model/Messages/Gradido/SignatureMap.php deleted file mode 100644 index 228282747..000000000 --- a/community_server/src/Model/Messages/Gradido/SignatureMap.php +++ /dev/null @@ -1,65 +0,0 @@ -model.messages.gradido.SignatureMap - */ -class SignatureMap extends \Google\Protobuf\Internal\Message -{ - /** - * Each signature pair corresponds to a unique Key required to sign the transaction. - * - * Generated from protobuf field repeated .model.messages.gradido.SignaturePair sigPair = 1; - */ - private $sigPair; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \Model\Messages\Gradido\SignaturePair[]|\Google\Protobuf\Internal\RepeatedField $sigPair - * Each signature pair corresponds to a unique Key required to sign the transaction. - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * Each signature pair corresponds to a unique Key required to sign the transaction. - * - * Generated from protobuf field repeated .model.messages.gradido.SignaturePair sigPair = 1; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getSigPair() - { - return $this->sigPair; - } - - /** - * Each signature pair corresponds to a unique Key required to sign the transaction. - * - * Generated from protobuf field repeated .model.messages.gradido.SignaturePair sigPair = 1; - * @param \Model\Messages\Gradido\SignaturePair[]|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setSigPair($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Model\Messages\Gradido\SignaturePair::class); - $this->sigPair = $arr; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/SignaturePair.php b/community_server/src/Model/Messages/Gradido/SignaturePair.php deleted file mode 100644 index 203eb5677..000000000 --- a/community_server/src/Model/Messages/Gradido/SignaturePair.php +++ /dev/null @@ -1,123 +0,0 @@ -model.messages.gradido.SignaturePair - */ -class SignaturePair extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field bytes pubKey = 1; - */ - private $pubKey = ''; - protected $signature; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $pubKey - * @type string $ed25519 - * ed25519 signature (libsodium default) - * @type string $ed25519_ref10 - * ed25519 ref10 signature - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field bytes pubKey = 1; - * @return string - */ - public function getPubKey() - { - return $this->pubKey; - } - - /** - * Generated from protobuf field bytes pubKey = 1; - * @param string $var - * @return $this - */ - public function setPubKey($var) - { - GPBUtil::checkString($var, False); - $this->pubKey = $var; - - return $this; - } - - /** - * ed25519 signature (libsodium default) - * - * Generated from protobuf field bytes ed25519 = 2; - * @return string - */ - public function getEd25519() - { - return $this->readOneof(2); - } - - /** - * ed25519 signature (libsodium default) - * - * Generated from protobuf field bytes ed25519 = 2; - * @param string $var - * @return $this - */ - public function setEd25519($var) - { - GPBUtil::checkString($var, False); - $this->writeOneof(2, $var); - - return $this; - } - - /** - * ed25519 ref10 signature - * - * Generated from protobuf field bytes ed25519_ref10 = 3; - * @return string - */ - public function getEd25519Ref10() - { - return $this->readOneof(3); - } - - /** - * ed25519 ref10 signature - * - * Generated from protobuf field bytes ed25519_ref10 = 3; - * @param string $var - * @return $this - */ - public function setEd25519Ref10($var) - { - GPBUtil::checkString($var, False); - $this->writeOneof(3, $var); - - return $this; - } - - /** - * @return string - */ - public function getSignature() - { - return $this->whichOneof("signature"); - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/StateCreateGroup.php b/community_server/src/Model/Messages/Gradido/StateCreateGroup.php deleted file mode 100644 index 4273ef93d..000000000 --- a/community_server/src/Model/Messages/Gradido/StateCreateGroup.php +++ /dev/null @@ -1,114 +0,0 @@ -model.messages.gradido.StateCreateGroup - */ -class StateCreateGroup extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field string name = 1; - */ - private $name = ''; - /** - * Generated from protobuf field .model.messages.gradido.Key groupPublicKey = 2; - */ - private $groupPublicKey = null; - /** - * Generated from protobuf field .model.messages.gradido.Key parentGroupPublicKey = 3; - */ - private $parentGroupPublicKey = null; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $name - * @type \Model\Messages\Gradido\Key $groupPublicKey - * @type \Model\Messages\Gradido\Key $parentGroupPublicKey - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\StateCreateGroup::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field string name = 1; - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Generated from protobuf field string name = 1; - * @param string $var - * @return $this - */ - public function setName($var) - { - GPBUtil::checkString($var, True); - $this->name = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key groupPublicKey = 2; - * @return \Model\Messages\Gradido\Key - */ - public function getGroupPublicKey() - { - return $this->groupPublicKey; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key groupPublicKey = 2; - * @param \Model\Messages\Gradido\Key $var - * @return $this - */ - public function setGroupPublicKey($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\Key::class); - $this->groupPublicKey = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key parentGroupPublicKey = 3; - * @return \Model\Messages\Gradido\Key - */ - public function getParentGroupPublicKey() - { - return $this->parentGroupPublicKey; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key parentGroupPublicKey = 3; - * @param \Model\Messages\Gradido\Key $var - * @return $this - */ - public function setParentGroupPublicKey($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\Key::class); - $this->parentGroupPublicKey = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/StateGroupChangeParent.php b/community_server/src/Model/Messages/Gradido/StateGroupChangeParent.php deleted file mode 100644 index c5371d76c..000000000 --- a/community_server/src/Model/Messages/Gradido/StateGroupChangeParent.php +++ /dev/null @@ -1,114 +0,0 @@ -model.messages.gradido.StateGroupChangeParent - */ -class StateGroupChangeParent extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field .model.messages.gradido.Key groupPublicKey = 1; - */ - private $groupPublicKey = null; - /** - * Generated from protobuf field .model.messages.gradido.Key newParentGroupPublicKey = 2; - */ - private $newParentGroupPublicKey = null; - /** - * Generated from protobuf field .model.messages.gradido.Key oldParentGroupPublicKey = 3; - */ - private $oldParentGroupPublicKey = null; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \Model\Messages\Gradido\Key $groupPublicKey - * @type \Model\Messages\Gradido\Key $newParentGroupPublicKey - * @type \Model\Messages\Gradido\Key $oldParentGroupPublicKey - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\StateGroupChangeParent::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field .model.messages.gradido.Key groupPublicKey = 1; - * @return \Model\Messages\Gradido\Key - */ - public function getGroupPublicKey() - { - return $this->groupPublicKey; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key groupPublicKey = 1; - * @param \Model\Messages\Gradido\Key $var - * @return $this - */ - public function setGroupPublicKey($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\Key::class); - $this->groupPublicKey = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key newParentGroupPublicKey = 2; - * @return \Model\Messages\Gradido\Key - */ - public function getNewParentGroupPublicKey() - { - return $this->newParentGroupPublicKey; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key newParentGroupPublicKey = 2; - * @param \Model\Messages\Gradido\Key $var - * @return $this - */ - public function setNewParentGroupPublicKey($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\Key::class); - $this->newParentGroupPublicKey = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key oldParentGroupPublicKey = 3; - * @return \Model\Messages\Gradido\Key - */ - public function getOldParentGroupPublicKey() - { - return $this->oldParentGroupPublicKey; - } - - /** - * Generated from protobuf field .model.messages.gradido.Key oldParentGroupPublicKey = 3; - * @param \Model\Messages\Gradido\Key $var - * @return $this - */ - public function setOldParentGroupPublicKey($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\Key::class); - $this->oldParentGroupPublicKey = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/Timestamp.php b/community_server/src/Model/Messages/Gradido/Timestamp.php deleted file mode 100644 index 19721729b..000000000 --- a/community_server/src/Model/Messages/Gradido/Timestamp.php +++ /dev/null @@ -1,101 +0,0 @@ -model.messages.gradido.Timestamp - */ -class Timestamp extends \Google\Protobuf\Internal\Message -{ - /** - * Number of complete seconds since the start of the epoch - * - * Generated from protobuf field int64 seconds = 1; - */ - private $seconds = 0; - /** - * Number of nanoseconds since the start of the last second - * - * Generated from protobuf field int32 nanos = 2; - */ - private $nanos = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $seconds - * Number of complete seconds since the start of the epoch - * @type int $nanos - * Number of nanoseconds since the start of the last second - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * Number of complete seconds since the start of the epoch - * - * Generated from protobuf field int64 seconds = 1; - * @return int|string - */ - public function getSeconds() - { - return $this->seconds; - } - - /** - * Number of complete seconds since the start of the epoch - * - * Generated from protobuf field int64 seconds = 1; - * @param int|string $var - * @return $this - */ - public function setSeconds($var) - { - GPBUtil::checkInt64($var); - $this->seconds = $var; - - return $this; - } - - /** - * Number of nanoseconds since the start of the last second - * - * Generated from protobuf field int32 nanos = 2; - * @return int - */ - public function getNanos() - { - return $this->nanos; - } - - /** - * Number of nanoseconds since the start of the last second - * - * Generated from protobuf field int32 nanos = 2; - * @param int $var - * @return $this - */ - public function setNanos($var) - { - GPBUtil::checkInt32($var); - $this->nanos = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/TimestampSeconds.php b/community_server/src/Model/Messages/Gradido/TimestampSeconds.php deleted file mode 100644 index 2a588a312..000000000 --- a/community_server/src/Model/Messages/Gradido/TimestampSeconds.php +++ /dev/null @@ -1,67 +0,0 @@ -model.messages.gradido.TimestampSeconds - */ -class TimestampSeconds extends \Google\Protobuf\Internal\Message -{ - /** - * Number of complete seconds since the start of the epoch - * - * Generated from protobuf field int64 seconds = 1; - */ - private $seconds = 0; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $seconds - * Number of complete seconds since the start of the epoch - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\BasicTypes::initOnce(); - parent::__construct($data); - } - - /** - * Number of complete seconds since the start of the epoch - * - * Generated from protobuf field int64 seconds = 1; - * @return int|string - */ - public function getSeconds() - { - return $this->seconds; - } - - /** - * Number of complete seconds since the start of the epoch - * - * Generated from protobuf field int64 seconds = 1; - * @param int|string $var - * @return $this - */ - public function setSeconds($var) - { - GPBUtil::checkInt64($var); - $this->seconds = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/Transaction.php b/community_server/src/Model/Messages/Gradido/Transaction.php deleted file mode 100644 index 065cd80bb..000000000 --- a/community_server/src/Model/Messages/Gradido/Transaction.php +++ /dev/null @@ -1,166 +0,0 @@ -model.messages.gradido.Transaction - */ -class Transaction extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field uint64 id = 1; - */ - private $id = 0; - /** - * Generated from protobuf field .model.messages.gradido.TimestampSeconds received = 2; - */ - private $received = null; - /** - * Generated from protobuf field .model.messages.gradido.SignatureMap sigMap = 3; - */ - private $sigMap = null; - /** - * Generated from protobuf field bytes txHash = 4; - */ - private $txHash = ''; - /** - * Generated from protobuf field bytes bodyBytes = 5; - */ - private $bodyBytes = ''; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type int|string $id - * @type \Model\Messages\Gradido\TimestampSeconds $received - * @type \Model\Messages\Gradido\SignatureMap $sigMap - * @type string $txHash - * @type string $bodyBytes - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Transaction::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field uint64 id = 1; - * @return int|string - */ - public function getId() - { - return $this->id; - } - - /** - * Generated from protobuf field uint64 id = 1; - * @param int|string $var - * @return $this - */ - public function setId($var) - { - GPBUtil::checkUint64($var); - $this->id = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.TimestampSeconds received = 2; - * @return \Model\Messages\Gradido\TimestampSeconds - */ - public function getReceived() - { - return $this->received; - } - - /** - * Generated from protobuf field .model.messages.gradido.TimestampSeconds received = 2; - * @param \Model\Messages\Gradido\TimestampSeconds $var - * @return $this - */ - public function setReceived($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\TimestampSeconds::class); - $this->received = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.SignatureMap sigMap = 3; - * @return \Model\Messages\Gradido\SignatureMap - */ - public function getSigMap() - { - return $this->sigMap; - } - - /** - * Generated from protobuf field .model.messages.gradido.SignatureMap sigMap = 3; - * @param \Model\Messages\Gradido\SignatureMap $var - * @return $this - */ - public function setSigMap($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\SignatureMap::class); - $this->sigMap = $var; - - return $this; - } - - /** - * Generated from protobuf field bytes txHash = 4; - * @return string - */ - public function getTxHash() - { - return $this->txHash; - } - - /** - * Generated from protobuf field bytes txHash = 4; - * @param string $var - * @return $this - */ - public function setTxHash($var) - { - GPBUtil::checkString($var, False); - $this->txHash = $var; - - return $this; - } - - /** - * Generated from protobuf field bytes bodyBytes = 5; - * @return string - */ - public function getBodyBytes() - { - return $this->bodyBytes; - } - - /** - * Generated from protobuf field bytes bodyBytes = 5; - * @param string $var - * @return $this - */ - public function setBodyBytes($var) - { - GPBUtil::checkString($var, False); - $this->bodyBytes = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/TransactionBody.php b/community_server/src/Model/Messages/Gradido/TransactionBody.php deleted file mode 100644 index 3452d4251..000000000 --- a/community_server/src/Model/Messages/Gradido/TransactionBody.php +++ /dev/null @@ -1,193 +0,0 @@ -model.messages.gradido.TransactionBody - */ -class TransactionBody extends \Google\Protobuf\Internal\Message -{ - /** - * max 150 chars - * - * Generated from protobuf field string memo = 1; - */ - private $memo = ''; - /** - * Generated from protobuf field .model.messages.gradido.TimestampSeconds created = 2; - */ - private $created = null; - protected $data; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type string $memo - * max 150 chars - * @type \Model\Messages\Gradido\TimestampSeconds $created - * @type \Model\Messages\Gradido\StateCreateGroup $createGroup - * @type \Model\Messages\Gradido\StateGroupChangeParent $groupChangeParent - * @type \Model\Messages\Gradido\Transfer $transfer - * @type \Model\Messages\Gradido\TransactionCreation $creation - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\TransactionBody::initOnce(); - parent::__construct($data); - } - - /** - * max 150 chars - * - * Generated from protobuf field string memo = 1; - * @return string - */ - public function getMemo() - { - return $this->memo; - } - - /** - * max 150 chars - * - * Generated from protobuf field string memo = 1; - * @param string $var - * @return $this - */ - public function setMemo($var) - { - GPBUtil::checkString($var, True); - $this->memo = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.TimestampSeconds created = 2; - * @return \Model\Messages\Gradido\TimestampSeconds - */ - public function getCreated() - { - return $this->created; - } - - /** - * Generated from protobuf field .model.messages.gradido.TimestampSeconds created = 2; - * @param \Model\Messages\Gradido\TimestampSeconds $var - * @return $this - */ - public function setCreated($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\TimestampSeconds::class); - $this->created = $var; - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.StateCreateGroup createGroup = 6; - * @return \Model\Messages\Gradido\StateCreateGroup - */ - public function getCreateGroup() - { - return $this->readOneof(6); - } - - /** - * Generated from protobuf field .model.messages.gradido.StateCreateGroup createGroup = 6; - * @param \Model\Messages\Gradido\StateCreateGroup $var - * @return $this - */ - public function setCreateGroup($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\StateCreateGroup::class); - $this->writeOneof(6, $var); - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.StateGroupChangeParent groupChangeParent = 7; - * @return \Model\Messages\Gradido\StateGroupChangeParent - */ - public function getGroupChangeParent() - { - return $this->readOneof(7); - } - - /** - * Generated from protobuf field .model.messages.gradido.StateGroupChangeParent groupChangeParent = 7; - * @param \Model\Messages\Gradido\StateGroupChangeParent $var - * @return $this - */ - public function setGroupChangeParent($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\StateGroupChangeParent::class); - $this->writeOneof(7, $var); - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.Transfer transfer = 8; - * @return \Model\Messages\Gradido\Transfer - */ - public function getTransfer() - { - return $this->readOneof(8); - } - - /** - * Generated from protobuf field .model.messages.gradido.Transfer transfer = 8; - * @param \Model\Messages\Gradido\Transfer $var - * @return $this - */ - public function setTransfer($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\Transfer::class); - $this->writeOneof(8, $var); - - return $this; - } - - /** - * Generated from protobuf field .model.messages.gradido.TransactionCreation creation = 9; - * @return \Model\Messages\Gradido\TransactionCreation - */ - public function getCreation() - { - return $this->readOneof(9); - } - - /** - * Generated from protobuf field .model.messages.gradido.TransactionCreation creation = 9; - * @param \Model\Messages\Gradido\TransactionCreation $var - * @return $this - */ - public function setCreation($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\TransactionCreation::class); - $this->writeOneof(9, $var); - - return $this; - } - - /** - * @return string - */ - public function getData() - { - return $this->whichOneof("data"); - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/TransactionCreation.php b/community_server/src/Model/Messages/Gradido/TransactionCreation.php deleted file mode 100644 index ae5f86e07..000000000 --- a/community_server/src/Model/Messages/Gradido/TransactionCreation.php +++ /dev/null @@ -1,136 +0,0 @@ -model.messages.gradido.TransactionCreation - */ -class TransactionCreation extends \Google\Protobuf\Internal\Message -{ - /** - * 40 Byte - * - * Generated from protobuf field .model.messages.gradido.ReceiverAmount receiverAmount = 1; - */ - private $receiverAmount = null; - /** - * 4 Byte - * - * Generated from protobuf field sint32 ident_hash = 2; - */ - private $ident_hash = 0; - /** - * 8 Byte - * - * Generated from protobuf field .model.messages.gradido.TimestampSeconds target_date = 3; - */ - private $target_date = null; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \Model\Messages\Gradido\ReceiverAmount $receiverAmount - * 40 Byte - * @type int $ident_hash - * 4 Byte - * @type \Model\Messages\Gradido\TimestampSeconds $target_date - * 8 Byte - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\TransactionCreation::initOnce(); - parent::__construct($data); - } - - /** - * 40 Byte - * - * Generated from protobuf field .model.messages.gradido.ReceiverAmount receiverAmount = 1; - * @return \Model\Messages\Gradido\ReceiverAmount - */ - public function getReceiverAmount() - { - return $this->receiverAmount; - } - - /** - * 40 Byte - * - * Generated from protobuf field .model.messages.gradido.ReceiverAmount receiverAmount = 1; - * @param \Model\Messages\Gradido\ReceiverAmount $var - * @return $this - */ - public function setReceiverAmount($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\ReceiverAmount::class); - $this->receiverAmount = $var; - - return $this; - } - - /** - * 4 Byte - * - * Generated from protobuf field sint32 ident_hash = 2; - * @return int - */ - public function getIdentHash() - { - return $this->ident_hash; - } - - /** - * 4 Byte - * - * Generated from protobuf field sint32 ident_hash = 2; - * @param int $var - * @return $this - */ - public function setIdentHash($var) - { - GPBUtil::checkInt32($var); - $this->ident_hash = $var; - - return $this; - } - - /** - * 8 Byte - * - * Generated from protobuf field .model.messages.gradido.TimestampSeconds target_date = 3; - * @return \Model\Messages\Gradido\TimestampSeconds - */ - public function getTargetDate() - { - return $this->target_date; - } - - /** - * 8 Byte - * - * Generated from protobuf field .model.messages.gradido.TimestampSeconds target_date = 3; - * @param \Model\Messages\Gradido\TimestampSeconds $var - * @return $this - */ - public function setTargetDate($var) - { - GPBUtil::checkMessage($var, \Model\Messages\Gradido\TimestampSeconds::class); - $this->target_date = $var; - - return $this; - } - -} - diff --git a/community_server/src/Model/Messages/Gradido/Transfer.php b/community_server/src/Model/Messages/Gradido/Transfer.php deleted file mode 100644 index 2c031d02b..000000000 --- a/community_server/src/Model/Messages/Gradido/Transfer.php +++ /dev/null @@ -1,85 +0,0 @@ -model.messages.gradido.Transfer - */ -class Transfer extends \Google\Protobuf\Internal\Message -{ - /** - * Generated from protobuf field repeated .model.messages.gradido.SenderAmount senderAmounts = 1; - */ - private $senderAmounts; - /** - * Generated from protobuf field repeated .model.messages.gradido.ReceiverAmount receiverAmounts = 2; - */ - private $receiverAmounts; - - /** - * Constructor. - * - * @param array $data { - * Optional. Data for populating the Message object. - * - * @type \Model\Messages\Gradido\SenderAmount[]|\Google\Protobuf\Internal\RepeatedField $senderAmounts - * @type \Model\Messages\Gradido\ReceiverAmount[]|\Google\Protobuf\Internal\RepeatedField $receiverAmounts - * } - */ - public function __construct($data = NULL) { - \GPBMetadata\Transfer::initOnce(); - parent::__construct($data); - } - - /** - * Generated from protobuf field repeated .model.messages.gradido.SenderAmount senderAmounts = 1; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getSenderAmounts() - { - return $this->senderAmounts; - } - - /** - * Generated from protobuf field repeated .model.messages.gradido.SenderAmount senderAmounts = 1; - * @param \Model\Messages\Gradido\SenderAmount[]|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setSenderAmounts($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Model\Messages\Gradido\SenderAmount::class); - $this->senderAmounts = $arr; - - return $this; - } - - /** - * Generated from protobuf field repeated .model.messages.gradido.ReceiverAmount receiverAmounts = 2; - * @return \Google\Protobuf\Internal\RepeatedField - */ - public function getReceiverAmounts() - { - return $this->receiverAmounts; - } - - /** - * Generated from protobuf field repeated .model.messages.gradido.ReceiverAmount receiverAmounts = 2; - * @param \Model\Messages\Gradido\ReceiverAmount[]|\Google\Protobuf\Internal\RepeatedField $var - * @return $this - */ - public function setReceiverAmounts($var) - { - $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Model\Messages\Gradido\ReceiverAmount::class); - $this->receiverAmounts = $arr; - - return $this; - } - -} - diff --git a/community_server/src/Model/Transactions/Transaction.php b/community_server/src/Model/Transactions/Transaction.php index 40be13cd3..db7ed9e5b 100644 --- a/community_server/src/Model/Transactions/Transaction.php +++ b/community_server/src/Model/Transactions/Transaction.php @@ -25,7 +25,7 @@ class Transaction extends TransactionBase { //$transactionBin = base64_decode($base64Data, true); //if($transactionBin == false) { //sodium_base64_VARIANT_URLSAFE_NO_PADDING - if(is_a($base64Data, '\Proto\Gradido\Transaction')) { + if(is_a($base64Data, '\Proto\Gradido\GradidoTransaction')) { $this->mProtoTransaction = $base64Data; $this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes()); return; @@ -93,7 +93,11 @@ class Transaction extends TransactionBase { return $this->mTransactionBody; } - public function getFirstPublic() { + public function getFirstPublic() + { + if(!$this->mProtoTransaction || !$this->mProtoTransaction->getSigMap()) { + return ''; + } $sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair(); return $sigPairs[0]->getPubKey(); } @@ -111,6 +115,7 @@ class Transaction extends TransactionBase { $sigMap = $this->mProtoTransaction->getSigMap(); if(!$sigMap) { $this->addError('Transaction', 'signature map is zero'); + //var_dump($this->mProtoTransaction); return false; } //var_dump($sigMap); diff --git a/community_server/src/Model/Transactions/TransactionTransfer.php b/community_server/src/Model/Transactions/TransactionTransfer.php index 4f3f4e88c..c36583c13 100644 --- a/community_server/src/Model/Transactions/TransactionTransfer.php +++ b/community_server/src/Model/Transactions/TransactionTransfer.php @@ -58,7 +58,7 @@ class TransactionTransfer extends TransactionBase { //$this->addError('TransactionTransfer::validate', 'not implemented yet'); //return false; //$time = microtime(true); - static $functionName = 'TransactionCreation::validate'; + static $functionName = 'TransactionTransfer::validate'; $sigPubHexs = []; foreach($sigPairs as $sigPair) diff --git a/community_server/src/Template/Transactions/manual_transaction.ctp b/community_server/src/Template/Transactions/manual_transaction.ctp new file mode 100644 index 000000000..30bda1175 --- /dev/null +++ b/community_server/src/Template/Transactions/manual_transaction.ctp @@ -0,0 +1,63 @@ +loadHelper('Form', [ + 'templates' => 'horizontal_form', +]); +$now = new \DateTime; +?> + 0) : ?> +
+ +
+ + +
+

+
+ Form->create() ?> + Form->control('type', ['type' => 'hidden', 'value' => 'creation']) ?> + Form->control('target_public_key', ['type'=> 'text']) ?> + Form->control('target_date', ['type'=> 'text', 'placeholder' => 'yyyy-mm-dd hh:ii:ss', 'default' => $now->format('Y-m-d H:i:s')]) ?> + Form->control('amount', ['type'=> 'number']) ?> + Form->control('memo', ['type'=> 'textarea', 'rows' => '8', 'cols' => 40]) ?> + Form->control('signer_public_key', ['type' => 'text']) ?> + Form->control('signer_private_key', ['type'=> 'text']) ?> + Form->submit(); ?> + Form->end() ?> +
+
+
+

+
+ Form->create() ?> + Form->control('type', ['type' => 'hidden', 'value' => 'transfer']) ?> + Form->control('sender_public_key', ['type'=> 'text']) ?> + Form->control('receiver_public_key', ['type'=> 'text']) ?> + Form->control('amount', ['type'=> 'number']) ?> + Form->control('memo', ['type'=> 'textarea', 'rows' => '8', 'cols' => 40]) ?> + Form->control('signer_public_key', ['type' => 'text']) ?> + Form->control('signer_private_key', ['type'=> 'text']) ?> + Form->submit(); ?> + Form->end() ?> +
+
+ +
+ +
+ \ No newline at end of file diff --git a/community_server/tests/Fixture/StateBalancesFixture.php b/community_server/tests/Fixture/StateBalancesFixture.php index f4a6fd7fc..015366c80 100644 --- a/community_server/tests/Fixture/StateBalancesFixture.php +++ b/community_server/tests/Fixture/StateBalancesFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * StateBalancesFixture */ -class StateBalancesFixture extends TestFixture +class StateBalancesFixture extends BaseTestFixture { /** * Fields @@ -36,8 +36,11 @@ class StateBalancesFixture extends TestFixture */ public function init() { - $this->records = [ + $sql = [ + [4, 4, '2021-05-27 17:47:50', '2021-05-27 17:47:50', 28808497], + [5, 1, '2021-05-27 17:47:51', '2021-05-27 17:47:50', 9823963] ]; + $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); } } diff --git a/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php b/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php index d8a241d7d..e6766129d 100644 --- a/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php +++ b/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php @@ -22,6 +22,7 @@ class JsonRequestHandlerControllerTest extends TestCase 'app.TransactionCreations', 'app.Transactions', 'app.StateUsers', + 'app.StateUserTransactions', 'app.StateErrors', 'app.TransactionSignatures', 'app.TransactionSendCoins', @@ -31,10 +32,10 @@ class JsonRequestHandlerControllerTest extends TestCase public $transactions = [ 'validCreation' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQJ8wF12eZo3hcMAlAKKJ9WLT-zuSkNmGh7D98UEqH4KoIysnCkXqEya9EBZl9o11_nJ8xmm_nOevuVjR-GfLMQ8qSQoOSGFsbG8gV2VsdCAxMjMSBgiZm4ruBUovCicKIJSuE1uTzZ8zdStOVcQZA6P6oTp1u5C_1BHqHUoaXnEfEKDakwEQtYntlgo', - 'validCreation900' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQNVZ8Ae3Zbg3G0wZ840fzKan6N4KtTcSe0KYi17kQwFmsl18oFxXv8_s6j1xXFrIKjy1_1Olq0a7xYLErDMkjwYqORIGCNb5iu4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgNHKCBC1ie2WCg', - 'validCreation1200' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQEEey5QMAdldoOTP_jTETHgOQriGsixEY0cziQeRfT_J5YtbI_A6AizEYD-JcxmRmXzv1xjjTgsV39Y32ta2CQkqORIGCIeGi-4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgOy4CxC1ie2WCg', + 'validCreation900' => 'CmYKZAog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8SQCaZHmvmvJOt336E3qst3rn1pptdAR5ZPzePaUT10x0_Yky8FnEiQtMGNy1yT94QErzwQudJZjJwDY2uyK4cTgkSOxIGCKb1vYUGOjEKJwog4zad42I86ERtBCTEAT56HXGiZxrj178eeY6_BmXRRfIQgNHKCBoGCIDMuf8F', + 'validCreation1200' => 'CmYKZAog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8SQF8jptIrosEyVmCf3WEIGVOK0NR8YCcO0j-s8v2yUyR5BKus0ciT6B7IA5LDtn7eQX6zHjg1v5WlsTiZuOpuNgwSRAoHVG8gbXVjaBIGCL3Jv4UGOjEKJwog4zad42I86ERtBCTEAT56HXGiZxrj178eeY6_BmXRRfIQgOy4CxoGCOG5toQG', 'notBase64' => 'CgpIYWxsbyBXZW-0EgYIyfSG7gV_LwonCiCboKikqwjZfes9xuqgthFH3', - 'validTransfer' => 'GmYKZAoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0SQDddHyKzAX3LBV0PuDiPc6lxkUipss5tyuLRpMtFJQnT30tsbYIkA1FXimjMKOoiuLswf4OLLV3bAIYehW-b9AgqYQoFSGFsbG8SBgiJlaPvBUJQCiYKIIGQvaWF7l8dn799BugeaewY4TN2EEz_VLdFfrfT73ENEICfSRImCiDtdleSLxhUgEbMW9DpqIwsykFj3-z_enKEOuGnXrmW8xCAn0k', + 'validTransfer' => 'CmYKZAog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8SQA0ZVQ9T1qBabzmgDO1NAWNy2J6mlv0YjMP99CiV7bSR0zemt5XoM-kTviR1aTqKggzpSYSyTN5T6gIx2xa-hgkSYwoLTXkgQmlydGhkYXkSBgie0L-FBjJMCkoKJgog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8QgIl6EiDjNp3jYjzoRG0EJMQBPnodcaJnGuPXvx55jr8GZdFF8g', 'errornusTransfer' => 'ClxGcm9oZXMgTmV1ZXMgSmFociB1bmQgREFOS0UsIGRhc3MgZHUgZGljaCBzbyBlaW5zZXR6dCBmw7xyIEdyYWRpZG8hIEhlcnpsaWNoZSBHcsO8w59lIFRlcmVzYRIGCPjjgvEFQlAKJgogUQwFYeVlGlfWDrkXNN7rHwejoCDJKt+YkYJfbJVyj3EQwIQ9EiYKIPXIRnUhVJ/zCs5+y/VaTBjTIoYizJNwS+JC//xsbQrHEMCEPQ==', 'creationValid' => 'GmYKZAogLtKKHPXhFtg2FUBrxXcVIiHC93SlZW9moOdUD3V21xsSQHpXYAGiVmSfhjB3o7OPx0ZJuPXrDk5eu1_AOhQBODU3KpUqBRA9yMX54S_mvGijGubCNRcMLcm7wiYbyAG-3AkqSwoQZWluIE1vbmF0c2dlaGFsdBIGCKqs5vEFSi8KJwoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0QgNrECRDKyd3uAQ' ]; @@ -51,7 +52,7 @@ class JsonRequestHandlerControllerTest extends TestCase $this->get('/JsonRequestHandler'); $this->assertResponseOk(); - $expected = json_encode(['state' => 'error', 'msg' => 'no post']); + $expected = json_encode(['state' => 'error', 'msg' => 'unknown method for get', 'details' => null]); $this->assertEquals($expected, (string)$this->_response->getBody()); } @@ -87,7 +88,7 @@ class JsonRequestHandlerControllerTest extends TestCase //$this->post('/TransactionJsonRequestHandler', ['method' => 'putTransaction', 'transaction' => 'CgpIYWxsbyBXZWx0EgYIyfSG7gVKLwonCiCboKikqwjZfes9xuqgthFH3/cHHaWchkUhWiGhQjB23xCg2pMBELWJ7ZYK']); $this->postAndParse( ['method' => 'foobar', 'transaction' => $this->transactions['validCreation']], - ['state' => 'error', 'msg' => 'unknown method', 'details' => 'foobar'] + ['state' => 'error', 'msg' => 'unknown method for post', 'details' => 'foobar'] ); } @@ -97,7 +98,8 @@ class JsonRequestHandlerControllerTest extends TestCase $this->postAndParse( ['method' => 'putTransaction', 'transaction' => $this->transactions['notBase64']], ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ - ['Transaction' => 'invalid base64 string'] + ['Transaction' => 'invalid base64 string'], + ['base64' => 'CgpIYWxsbyBXZW-0EgYIyfSG7gV_LwonCiCboKikqwjZfes9xuqgthFH3'] ]] ); } @@ -114,9 +116,10 @@ class JsonRequestHandlerControllerTest extends TestCase public function testToLargeCreationSum() { + $this->postAndParse( ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation900']], - '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' + '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1.000 GDD per Month for in target_date not allowed"}]}' ); } @@ -124,7 +127,7 @@ class JsonRequestHandlerControllerTest extends TestCase { $this->postAndParse( ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation1200']], - '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' + '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1.000 GDD per Month for in target_date not allowed"}]}' ); } @@ -159,14 +162,14 @@ class JsonRequestHandlerControllerTest extends TestCase private function postAndParse($params, $expected) { - //$this->enableCsrfToken(); + $this->enableCsrfToken(); //$this->enableSecurityToken(); - $token = 'my-csrf-token'; - $this->cookie('csrfToken', $token); + //$token = 'my-csrf-token'; + //$this->cookie('csrfToken', $token); $this->configRequest([ - 'headers' => ['Accept' => 'application/json', 'X-CSRF-Token' => $token] + 'headers' => ['Accept' => 'application/json']//, 'X-CSRF-Token' => $token] ]); $this->disableErrorHandlerMiddleware(); diff --git a/community_server/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php b/community_server/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php deleted file mode 100644 index 7ad28760c..000000000 --- a/community_server/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php +++ /dev/null @@ -1,174 +0,0 @@ - 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQJ8wF12eZo3hcMAlAKKJ9WLT-zuSkNmGh7D98UEqH4KoIysnCkXqEya9EBZl9o11_nJ8xmm_nOevuVjR-GfLMQ8qSQoOSGFsbG8gV2VsdCAxMjMSBgiZm4ruBUovCicKIJSuE1uTzZ8zdStOVcQZA6P6oTp1u5C_1BHqHUoaXnEfEKDakwEQtYntlgo', - 'validCreation900' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQNVZ8Ae3Zbg3G0wZ840fzKan6N4KtTcSe0KYi17kQwFmsl18oFxXv8_s6j1xXFrIKjy1_1Olq0a7xYLErDMkjwYqORIGCNb5iu4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgNHKCBC1ie2WCg', - 'validCreation1200' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQEEey5QMAdldoOTP_jTETHgOQriGsixEY0cziQeRfT_J5YtbI_A6AizEYD-JcxmRmXzv1xjjTgsV39Y32ta2CQkqORIGCIeGi-4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgOy4CxC1ie2WCg', - 'notBase64' => 'CgpIYWxsbyBXZW-0EgYIyfSG7gV_LwonCiCboKikqwjZfes9xuqgthFH3', - 'validTransfer' => 'GmYKZAoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0SQDddHyKzAX3LBV0PuDiPc6lxkUipss5tyuLRpMtFJQnT30tsbYIkA1FXimjMKOoiuLswf4OLLV3bAIYehW-b9AgqYQoFSGFsbG8SBgiJlaPvBUJQCiYKIIGQvaWF7l8dn799BugeaewY4TN2EEz_VLdFfrfT73ENEICfSRImCiDtdleSLxhUgEbMW9DpqIwsykFj3-z_enKEOuGnXrmW8xCAn0k', - 'errornusTransfer' => 'ClxGcm9oZXMgTmV1ZXMgSmFociB1bmQgREFOS0UsIGRhc3MgZHUgZGljaCBzbyBlaW5zZXR6dCBmw7xyIEdyYWRpZG8hIEhlcnpsaWNoZSBHcsO8w59lIFRlcmVzYRIGCPjjgvEFQlAKJgogUQwFYeVlGlfWDrkXNN7rHwejoCDJKt+YkYJfbJVyj3EQwIQ9EiYKIPXIRnUhVJ/zCs5+y/VaTBjTIoYizJNwS+JC//xsbQrHEMCEPQ==' - ]; - - /*public function setUp() { - parent::setUp(); - } -*/ - public function testWrongMethod() - { - $this->configRequest([ - 'headers' => ['Accept' => 'application/json'] - ]); - $this->get('/TransactionJsonRequestHandler'); - $this->assertResponseOk(); - - $expected = json_encode(['state' => 'error', 'msg' => 'no post']); - $this->assertEquals($expected, (string)$this->_response->getBody()); - } - - public function testInvalidJson() - { - $this->configRequest([ - 'headers' => ['Accept' => 'application/json'] - ]); - $this->post('/TransactionJsonRequestHandler', '{This isn\'t valid json}'); - $this->assertResponseOk(); - - $expected = json_encode(['state' => 'error', 'msg' => 'parameter error']); - $this->assertEquals($expected, (string)$this->_response->getBody()); - } - - public function testNotSetTransaction() - { - $this->postAndParse( - ['method' => 'putTransaction'], - ['state' => 'error', 'msg' => 'parameter error'] - ); - } - public function testNotSetMethod() - { - $this->postAndParse( - ['transaction' => $this->transactions['validCreation']], - ['state' => 'error', 'msg' => 'parameter error'] - ); - } - - public function testUnknownMethod() - { - //$this->post('/TransactionJsonRequestHandler', ['method' => 'putTransaction', 'transaction' => 'CgpIYWxsbyBXZWx0EgYIyfSG7gVKLwonCiCboKikqwjZfes9xuqgthFH3/cHHaWchkUhWiGhQjB23xCg2pMBELWJ7ZYK']); - $this->postAndParse( - ['method' => 'foobar', 'transaction' => $this->transactions['validCreation']], - ['state' => 'error', 'msg' => 'unknown method', 'details' => 'foobar'] - ); - - } - - public function testInvalidEncodedTransaction() { - //"msg":"error parsing transaction","details":[{"Transaction":"base64 decode error"}] - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['notBase64']], - ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ - ['Transaction' => 'invalid base64 string'] - ]] - ); - } - - public function testInvalidTransaction() { - - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => base64_encode('Hallo Miau Welt')], - ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ - ['Transaction' => 'Error occurred during parsing: Unexpected wire type.'] - ]] - ); - } - - public function testToLargeCreationSum() - { - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation900']], - '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' - ); - } - - public function testToLargeCreation() - { - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation1200']], - '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' - ); - } - - public function testValidTransfer() - { - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['validTransfer']], - ['state' => 'success'] - ); - } - - /*public function testMissingPreviousTransaction() - { - - }*/ - - public function testValidTransaction() - { - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation']], - ['state' => 'success'] - ); - } - - private function postAndParse($params, $expected) - { - - $this->configRequest([ - 'headers' => ['Accept' => 'application/json'] - ]); - - $this->disableErrorHandlerMiddleware(); - $this->post('/TransactionJsonRequestHandler', json_encode($params)); - - // Check that the response was a 200 - $this->assertResponseOk(); - - $responseBodyString = (string)$this->_response->getBody(); - $json = json_decode($responseBodyString); - $this->assertNotFalse($json); - - if(is_array($expected)) { - $expected = json_encode($expected); - } - $this->assertEquals($expected, $responseBodyString); - } -}