From b6343e8ab2c608aa97700c8e87f904a7b7730096 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 13 May 2020 13:04:28 +0000 Subject: [PATCH 01/12] adding missing files to git --- src/Controller/ElopageWebhookController.php | 51 +++++ tests/Fixture/ElopageBuysFixture.php | 64 ++++++ tests/Fixture/UsersFixture.php | 61 ++++++ .../Controller/ElopageBuysControllerTest.php | 80 ++++++++ .../JsonRequestHandlerControllerTest.php | 183 ++++++++++++++++++ ...actionJsonRequestHandlerControllerTest.php | 174 +++++++++++++++++ .../Controller/UsersControllerTest.php | 78 ++++++++ .../Model/Table/AdminErrorsTableTest.php | 83 ++++++++ .../Model/Table/ElopageBuysTableTest.php | 97 ++++++++++ .../Model/Table/StateErrorsTableTest.php | 84 ++++++++ .../Model/Table/StateUsersTableTest.php | 97 ++++++++++ tests/TestCase/Model/Table/UsersTableTest.php | 95 +++++++++ .../Transactions/TransactionCreationTest.php | 113 +++++++++++ 13 files changed, 1260 insertions(+) create mode 100644 src/Controller/ElopageWebhookController.php create mode 100644 tests/Fixture/ElopageBuysFixture.php create mode 100644 tests/Fixture/UsersFixture.php create mode 100644 tests/TestCase/Controller/ElopageBuysControllerTest.php create mode 100644 tests/TestCase/Controller/JsonRequestHandlerControllerTest.php create mode 100644 tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php create mode 100644 tests/TestCase/Controller/UsersControllerTest.php create mode 100644 tests/TestCase/Model/Table/AdminErrorsTableTest.php create mode 100644 tests/TestCase/Model/Table/ElopageBuysTableTest.php create mode 100644 tests/TestCase/Model/Table/StateErrorsTableTest.php create mode 100644 tests/TestCase/Model/Table/StateUsersTableTest.php create mode 100644 tests/TestCase/Model/Table/UsersTableTest.php create mode 100644 tests/TestCase/Model/Transactions/TransactionCreationTest.php diff --git a/src/Controller/ElopageWebhookController.php b/src/Controller/ElopageWebhookController.php new file mode 100644 index 000000000..4e806fa69 --- /dev/null +++ b/src/Controller/ElopageWebhookController.php @@ -0,0 +1,51 @@ +Auth->allow(['put']); + + } + + public function put() + { + $this->autoRender = false; + $data = $this->request->getData(); + $response = $this->response->withType('text/plain'); + + $dataString = http_build_query($data); + //$this->recursiveArrayToString($data, $dataString); + // %5B => [ + // %5D => ] + $dataString = preg_replace(['/\%5B/', '/\%5D/'], ['[', ']'], $dataString); + //var_dump($dataString); + + //2020-02-27T13:52:32+01:00 + $dateString = date('c'); + $fh = fopen('/etc/grd_login/php_elopage_requests.txt', 'a'); + if($fh === FALSE) { + return $response->withStringBody('400 ERROR'); + } + fwrite($fh, $dateString); + fwrite($fh, "\n"); + fwrite($fh, $dataString); + fwrite($fh, "\n"); + fclose($fh); + + + return $response->withStringBody('200 OK'); + + } +} diff --git a/tests/Fixture/ElopageBuysFixture.php b/tests/Fixture/ElopageBuysFixture.php new file mode 100644 index 000000000..20be0f4e3 --- /dev/null +++ b/tests/Fixture/ElopageBuysFixture.php @@ -0,0 +1,64 @@ + ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'elopage_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'affiliate_program_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'publisher_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'order_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'product_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'product_price' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'payer_email' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'publisher_email' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'payed' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], + 'success_date' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], + 'event' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null], + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], + ], + '_options' => [ + 'engine' => 'InnoDB', + 'collation' => 'utf8_bin' + ], + ]; + // @codingStandardsIgnoreEnd + /** + * Init method + * + * @return void + */ + public function init() + { + $this->records = [ + [ + 'id' => 1, + 'elopage_user_id' => 1, + 'affiliate_program_id' => 1, + 'publisher_id' => 1, + 'order_id' => 1, + 'product_id' => 1, + 'product_price' => 1, + 'payer_email' => 'Lorem ipsum dolor sit amet', + 'publisher_email' => 'Lorem ipsum dolor sit amet', + 'payed' => 1, + 'success_date' => '2020-02-13 09:49:46', + 'event' => 'Lorem ipsum dolor sit amet', + ], + ]; + parent::init(); + } +} diff --git a/tests/Fixture/UsersFixture.php b/tests/Fixture/UsersFixture.php new file mode 100644 index 000000000..fc1a9e620 --- /dev/null +++ b/tests/Fixture/UsersFixture.php @@ -0,0 +1,61 @@ + ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'email' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'first_name' => ['type' => 'string', 'length' => 150, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => '', 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'password' => ['type' => 'biginteger', 'length' => 25, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'pubkey' => ['type' => 'binary', 'length' => 32, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], + 'privkey' => ['type' => 'binary', 'length' => 80, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], + 'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '', 'precision' => null], + 'email_checked' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null], + 'language' => ['type' => 'string', 'length' => 4, 'null' => false, 'default' => 'de', 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], + 'email' => ['type' => 'unique', 'columns' => ['email'], 'length' => []], + ], + '_options' => [ + 'engine' => 'InnoDB', + 'collation' => 'utf8_general_ci' + ], + ]; + // @codingStandardsIgnoreEnd + /** + * Init method + * + * @return void + */ + public function init() + { + $this->records = [ + [ + 'id' => 1, + 'email' => 'Lorem ipsum dolor sit amet', + 'first_name' => 'Lorem ipsum dolor sit amet', + 'last_name' => 'Lorem ipsum dolor sit amet', + 'password' => 1, + 'pubkey' => 'Lorem ipsum dolor sit amet', + 'privkey' => 'Lorem ipsum dolor sit amet', + 'created' => '2020-02-13 10:54:19', + 'email_checked' => 1, + 'language' => 'Lo', + ], + ]; + parent::init(); + } +} diff --git a/tests/TestCase/Controller/ElopageBuysControllerTest.php b/tests/TestCase/Controller/ElopageBuysControllerTest.php new file mode 100644 index 000000000..38783976e --- /dev/null +++ b/tests/TestCase/Controller/ElopageBuysControllerTest.php @@ -0,0 +1,80 @@ +markTestIncomplete('Not implemented yet.'); + } + + /** + * Test view method + * + * @return void + */ + public function testView() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test add method + * + * @return void + */ + public function testAdd() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test edit method + * + * @return void + */ + public function testEdit() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test delete method + * + * @return void + */ + public function testDelete() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php b/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php new file mode 100644 index 000000000..d51062563 --- /dev/null +++ b/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php @@ -0,0 +1,183 @@ + '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==', + 'creationValid' => 'GmYKZAogLtKKHPXhFtg2FUBrxXcVIiHC93SlZW9moOdUD3V21xsSQHpXYAGiVmSfhjB3o7OPx0ZJuPXrDk5eu1_AOhQBODU3KpUqBRA9yMX54S_mvGijGubCNRcMLcm7wiYbyAG-3AkqSwoQZWluIE1vbmF0c2dlaGFsdBIGCKqs5vEFSi8KJwoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0QgNrECRDKyd3uAQ' + ]; + + /*public function setUp() { + parent::setUp(); + } +*/ + public function testWrongMethod() + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + $this->get('/JsonRequestHandler'); + $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('/JsonRequestHandler', '{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'] + ); + } + + public function testValidCreation() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['creationValid']], + ['state' => 'success'] + ); + } + + private function postAndParse($params, $expected) + { + + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + + $this->disableErrorHandlerMiddleware(); + $this->post('/JsonRequestHandler', 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); + } +} diff --git a/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php b/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php new file mode 100644 index 000000000..7ad28760c --- /dev/null +++ b/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php @@ -0,0 +1,174 @@ + '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); + } +} diff --git a/tests/TestCase/Controller/UsersControllerTest.php b/tests/TestCase/Controller/UsersControllerTest.php new file mode 100644 index 000000000..db9f98307 --- /dev/null +++ b/tests/TestCase/Controller/UsersControllerTest.php @@ -0,0 +1,78 @@ +markTestIncomplete('Not implemented yet.'); + } + + /** + * Test view method + * + * @return void + */ + public function testView() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test add method + * + * @return void + */ + public function testAdd() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test edit method + * + * @return void + */ + public function testEdit() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test delete method + * + * @return void + */ + public function testDelete() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Table/AdminErrorsTableTest.php b/tests/TestCase/Model/Table/AdminErrorsTableTest.php new file mode 100644 index 000000000..09d7a35fb --- /dev/null +++ b/tests/TestCase/Model/Table/AdminErrorsTableTest.php @@ -0,0 +1,83 @@ +exists('AdminErrors') ? [] : ['className' => AdminErrorsTable::class]; + $this->AdminErrors = TableRegistry::getTableLocator()->get('AdminErrors', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->AdminErrors); + + parent::tearDown(); + } + + /** + * Test initialize method + * + * @return void + */ + public function testInitialize() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test validationDefault method + * + * @return void + */ + public function testValidationDefault() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test buildRules method + * + * @return void + */ + public function testBuildRules() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Table/ElopageBuysTableTest.php b/tests/TestCase/Model/Table/ElopageBuysTableTest.php new file mode 100644 index 000000000..35aecc813 --- /dev/null +++ b/tests/TestCase/Model/Table/ElopageBuysTableTest.php @@ -0,0 +1,97 @@ +exists('ElopageBuys') ? [] : ['className' => ElopageBuysTable::class]; + $this->ElopageBuys = TableRegistry::getTableLocator()->get('ElopageBuys', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->ElopageBuys); + + parent::tearDown(); + } + + /** + * Test initialize method + * + * @return void + */ + public function testInitialize() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test validationDefault method + * + * @return void + */ + public function testValidationDefault() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test buildRules method + * + * @return void + */ + public function testBuildRules() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test defaultConnectionName method + * + * @return void + */ + public function testDefaultConnectionName() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Table/StateErrorsTableTest.php b/tests/TestCase/Model/Table/StateErrorsTableTest.php new file mode 100644 index 000000000..21cbe6128 --- /dev/null +++ b/tests/TestCase/Model/Table/StateErrorsTableTest.php @@ -0,0 +1,84 @@ +exists('StateErrors') ? [] : ['className' => StateErrorsTable::class]; + $this->StateErrors = TableRegistry::getTableLocator()->get('StateErrors', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->StateErrors); + + parent::tearDown(); + } + + /** + * Test initialize method + * + * @return void + */ + public function testInitialize() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test validationDefault method + * + * @return void + */ + public function testValidationDefault() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test buildRules method + * + * @return void + */ + public function testBuildRules() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Table/StateUsersTableTest.php b/tests/TestCase/Model/Table/StateUsersTableTest.php new file mode 100644 index 000000000..49deb1166 --- /dev/null +++ b/tests/TestCase/Model/Table/StateUsersTableTest.php @@ -0,0 +1,97 @@ +exists('StateUsers') ? [] : ['className' => StateUsersTable::class]; + $this->StateUsersTable = TableRegistry::getTableLocator()->get('StateUsers', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->StateUsersTable); + + parent::tearDown(); + } + + /** + * Test initialize method + * + * @return void + */ + public function testInitialize() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test validationDefault method + * + * @return void + */ + public function testValidationDefault() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test buildRules method + * + * @return void + */ + public function testBuildRules() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test getReceiverProposal method + * + * @return void + */ + public function testGetReceiverProposal() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Table/UsersTableTest.php b/tests/TestCase/Model/Table/UsersTableTest.php new file mode 100644 index 000000000..7b730de54 --- /dev/null +++ b/tests/TestCase/Model/Table/UsersTableTest.php @@ -0,0 +1,95 @@ +exists('Users') ? [] : ['className' => UsersTable::class]; + $this->Users = TableRegistry::getTableLocator()->get('Users', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->Users); + + parent::tearDown(); + } + + /** + * Test initialize method + * + * @return void + */ + public function testInitialize() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test validationDefault method + * + * @return void + */ + public function testValidationDefault() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test buildRules method + * + * @return void + */ + public function testBuildRules() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test defaultConnectionName method + * + * @return void + */ + public function testDefaultConnectionName() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Transactions/TransactionCreationTest.php b/tests/TestCase/Model/Transactions/TransactionCreationTest.php new file mode 100644 index 000000000..60a6307ed --- /dev/null +++ b/tests/TestCase/Model/Transactions/TransactionCreationTest.php @@ -0,0 +1,113 @@ + 97, + "b" => 98, + "c" => 99, + "d" => 100, + "aa" => 12513, + "ab" => 12514, + "@" => 64, + ".d" => 5988, + "gmx" => 1701624, + "@gmx" => 135919352, + "@gmx.de" => 3742152099, + "***REMOVED***" => 2928827813, + "***REMOVED***" => 1899591683, + "***REMOVED***" => 2089074830, + "maximilian.muster@gradido.net" => 793144931, + "coin-info5@gradido.net" => 1829129963, + "coin-info6@gradido.net" => 1830178539, + "coin-info8@gradido.net" => 1832275691, + "coin-info9@gradido.net" => 1833324267, + "coin-info10@gradido.net" => 3877298078, + "coin-info11@gradido.net" => 3878346654, + "coin-info12@gradido.net" => 3879395230, + "***REMOVED***" => 2089074830, + "***REMOVED***" => 3996757473, + "***REMOVED***" => 3788634614, + "***REMOVED***" => 807797884, + "***REMOVED***" => 1640973721, + "***REMOVED***" => 2025729173, + "***REMOVED***" => 1961122507, + "***REMOVED***" => 362466358, + "***REMOVED***" => 3796728871, + "***REMOVED***" => 807797884, + "***REMOVED***" => 3794905967, + "***REMOVED***" => 3077694284, + "***REMOVED***" => 3246159770, + "***REMOVED***" => 3123402690, + "testneu-11-12-3@gradido.net" => 4092403827, + "***REMOVED***" => 3151414199, + "***REMOVED***" => 3526188273, + "***REMOVED***" => 966804823, + "***REMOVED***" => 1309273258, + "***REMOVED***" => 995978784, + "***REMOVED***" => 310113324, + "***REMOVED***" => 1309273258, + "***REMOVED***" => 530108573, + "***REMOVED***" => 1734855679, + "***REMOVED***" => 767779182, + "***REMOVED***" => 2247491519, + "***REMOVED***" => 3248626267, + "***REMOVED***" => 3516649930, + "***REMOVED***" => 231214190, + "***REMOVED***" => 4247461928, + "***REMOVED***" => 324829839, + "***REMOVED***" => 3046147747, + "***REMOVED***" => 3207307415, + "***REMOVED***" => 728893500, + "***REMOVED***" => 3905254663, + "***REMOVED***" => 3207307415, + "***REMOVED***" => 1155733239, + "***REMOVED***" => 2013046423, + "***REMOVED***" => 4033835283, + "***REMOVED***" => 1945541625, + "***REMOVED***" => 2310715309, + "***REMOVED***" => 1221362064, + "***REMOVED***" => 4161339877 + ]; + foreach($pairs as $email => $cpp_hash) { + $php_hash = TransactionCreation::DRMakeStringHash($email); + // assertEquals(mixed $expected, mixed $actual[, string $message = '']) + if($php_hash != $cpp_hash) { + $this->assertEquals($cpp_hash, $php_hash, "hashes for $email don't match"); + } + } + } + + +} From 6e28513077d23bcc07c60d9db3f3210ea831f77b Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Thu, 14 May 2020 08:14:05 +0000 Subject: [PATCH 02/12] Move Publisher Path into Tooltip for better layout --- src/Controller/StateBalancesController.php | 5 +- src/Template/StateBalances/overview_gdt.ctp | 55 +++++++++++++++------ 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index a2cff0bde..0b447b60e 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -193,7 +193,10 @@ class StateBalancesController extends AppController //echo "gdtSum: $gdtSum
"; $this->set('gdtSum', $gdtSum); $this->set('ownEntries', $ownEntries); - + $this->set('gdtSumPerEmail', $requestResult['data']['gdtSumPerEmail']); + $this->set('moreEntrysAsShown', $requestResult['data']['moreEntrysAsShown']); + $this->set('user', $user); + if(isset($requestResult['data']['publishers'])) { $publishers = $requestResult['data']['publishers']; $this->set('publishers', $publishers); diff --git a/src/Template/StateBalances/overview_gdt.ctp b/src/Template/StateBalances/overview_gdt.ctp index ccf3e1069..485fbb030 100644 --- a/src/Template/StateBalances/overview_gdt.ctp +++ b/src/Template/StateBalances/overview_gdt.ctp @@ -24,6 +24,10 @@ function publisherLink($publisher, $the) { } $this->assign('title', __('GDT Kontoübersicht')); +$gdtSumFromEmails = 0; +foreach($gdtSumPerEmail as $email => $gdt) { + $gdtSumFromEmails += $gdt; +} ?>
@@ -31,7 +35,10 @@ $this->assign('title', __('GDT Kontoübersicht'));

0) : ?> -

element('printGDT', ['number' => $gdtSum]) ?>

+

element('printGDT', ['number' => $gdtSumFromEmails]) ?>

+ + +
@@ -48,20 +55,17 @@ $this->assign('title', __('GDT Kontoübersicht')); - - - - + + + + - - - + + + @@ -94,10 +101,11 @@ $this->assign('title', __('GDT Kontoübersicht')); - - - - + + + + + @@ -105,14 +113,16 @@ $this->assign('title', __('GDT Kontoübersicht')); $elopageTransaction = $entry['connect']['elopage_transaction']; $gdtEntry = $entry['connect']['gdt_entry']; ?> - @@ -127,6 +137,12 @@ $this->assign('title', __('GDT Kontoübersicht')); + @@ -136,4 +152,13 @@ $this->assign('title', __('GDT Kontoübersicht')); -Html->css(['gdt.css']) ?> \ No newline at end of file +Html->css(['gdt.css']) ?> +Html->script(['basic', 'popper.min', 'tippy-bundle.umd.min']) ?> + \ No newline at end of file From 8d6c10d2b21c32269602c9c9c699a5034c58a301 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Thu, 14 May 2020 09:30:09 +0000 Subject: [PATCH 03/12] Add showing subtotal in gdt overview --- src/Template/StateBalances/overview_gdt.ctp | 47 +++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/Template/StateBalances/overview_gdt.ctp b/src/Template/StateBalances/overview_gdt.ctp index 485fbb030..f7bb6179e 100644 --- a/src/Template/StateBalances/overview_gdt.ctp +++ b/src/Template/StateBalances/overview_gdt.ctp @@ -28,7 +28,21 @@ $gdtSumFromEmails = 0; foreach($gdtSumPerEmail as $email => $gdt) { $gdtSumFromEmails += $gdt; } + +$ownEuroSum = 0; +$ownGdtSum = 0; +$publisherEuroSum = 0; +$publisherGdtSum = 0; ?> +
@@ -64,11 +78,19 @@ foreach($gdtSumPerEmail as $email => $gdt) {
- + + + + + + +
element('printEuro', ['number' => $entry['amount']]); ?> element('printEuro', ['number' => $entry['amount2']]) ?> @@ -73,6 +77,9 @@ $this->assign('title', __('GDT Kontoübersicht')); element('printGDT', ['number' => $entry['gdt']]) ?>
+
element('printGDT', ['number' => $gdtEntry['gdt']]) ?>
element('printEuro', ['number' => $entry['amount']]); ?> - element('printEuro', ['number' => $entry['amount2']]) ?> + element('printEuro', ['number' => $entry['amount2']]); + $ownEuroSum += $entry['amount2']; + } + ?> Number->format($entry['factor']) ?> @@ -81,6 +103,12 @@ foreach($gdtSumPerEmail as $email => $gdt) {
:element('printEuro', ['number' => $ownEuroSum]) ?>element('printGDT', ['number' => $ownGdtSum]) ?>
@@ -112,6 +140,8 @@ foreach($gdtSumPerEmail as $email => $gdt) { - + + - From 68dcf314cf08d19971c5a26179fa235f5e72ea05 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Tue, 19 May 2020 05:04:19 +0000 Subject: [PATCH 06/12] Add error message if receiver hasn't activated his account yet --- src/Controller/StateBalancesController.php | 1 + .../TransactionSendCoinsController.php | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index 3b02d9c44..440650f50 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -164,6 +164,7 @@ class StateBalancesController extends AppController } $user = $session->read('StateUser'); $requestResult = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'listPerEmailApi'); + //var_dump($requestResult); if('success' === $requestResult['state'] && 'success' === $requestResult['data']['state']) { //var_dump(array_keys($requestResult['data'])); $ownEntries = $requestResult['data']['ownEntries']; diff --git a/src/Controller/TransactionSendCoinsController.php b/src/Controller/TransactionSendCoinsController.php index de278b55e..7204e24c2 100644 --- a/src/Controller/TransactionSendCoinsController.php +++ b/src/Controller/TransactionSendCoinsController.php @@ -170,6 +170,7 @@ class TransactionSendCoinsController extends AppController 'ask' => ['user.pubkeyhex'] ]), '/getUserInfos'); if('success' == $requestAnswear['state'] && 'success' == $requestAnswear['data']['state']) { + // will be allways 64 byte long, even if it is empty $receiverPubKeyHex = $requestAnswear['data']['userData']['pubkeyhex']; } else { $this->addAdminError('TransactionSendCoins', 'create', $requestAnswear, $user['id']); @@ -177,20 +178,30 @@ class TransactionSendCoinsController extends AppController $this->set('timeUsed', microtime(true) - $startTime); return; } - if('' == $receiverPubKeyHex) { + + if(0 == ord($receiverPubKeyHex)) { $stateUserTable = TableRegistry::getTableLocator()->get('StateUsers'); $receiverUser = $stateUserTable ->find('all') ->select(['public_key']) ->contain(false) - ->where(['email' => $receiverEmail])->first(); - //var_dump($receiverUser); + ->where(['email' => $receiverEmail]); + + if(!$receiverUser) { $this->Flash->error(__('Diese E-Mail ist mir nicht bekannt, hat dein Empfänger denn schon ein Gradido-Konto?')); $this->set('timeUsed', microtime(true) - $startTime); return; } - $receiverPubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key)); + + if(isset($receiverUser->public_key)) { + $receiverPubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key)); + } else { + $this->Flash->error(__('Das Konto mit der E-Mail: ' . $receiverEmail . ' wurde noch nicht aktiviert und kann noch keine GDD empfangen!')); + $this->set('timeUsed', microtime(true) - $startTime); + return; + } + } //var_dump($sessionStateUser); From f5fa39b371a0bb655ea9784329846eeaa0e7e345 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Tue, 19 May 2020 06:42:40 +0000 Subject: [PATCH 07/12] Add error handling for gdt requests --- src/Controller/StateBalancesController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index 440650f50..10a625b25 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -56,6 +56,8 @@ class StateBalancesController extends AppController //var_dump($gdtEntries); if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) { $gdtSum = intval($gdtEntries['data']['sum']); + } else { + $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user->id); } //} // @@ -203,6 +205,7 @@ class StateBalancesController extends AppController $this->set('publishers', $publishers); } } else { + $this->addAdminError('StateBalancesController', 'overviewGdt', $requestResult, $user->id); $this->Flash->error(__('Fehler beim GDT Server, bitte abwarten oder den Admin benachrichtigen!')); } From 81b63b311918840eb9fa60290ec08aa432bc1f66 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Tue, 19 May 2020 07:17:43 +0000 Subject: [PATCH 08/12] Forward User with not activated account back to login --- src/Controller/AppController.php | 13 ++++++++----- src/Controller/DashboardController.php | 1 + src/Controller/StateBalancesController.php | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 94bd06099..c0fb8796c 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -160,7 +160,6 @@ class AppController extends Controller $response = $http->get($url . '/login', ['session_id' => $session_id]); $json = $response->getJson(); - if(isset($json) && count($json) > 0) { if($json['state'] === 'success' && intval($json['user']['email_checked']) === 1) { @@ -225,9 +224,11 @@ class AppController extends Controller } } else { if($json['state'] === 'not found' ) { - $this->Flash->error(__('invalid session')); - return $this->redirect(Router::url('/', true) . 'account/', 303); + $this->Flash->error(__('invalid session')); + } else { + $this->Flash->error(__('Konto ist nicht aktiviert!')); } + return $this->redirect(Router::url('/', true) . 'account/', 303); } } } catch(\Exception $e) { @@ -273,12 +274,14 @@ class AppController extends Controller $adminErrorEntity->details = $returnTable['details']; } if(!$adminErrorTable->save($adminErrorEntity)) { - $this->Flash->error(__('Serious error, couldn\'t save to db, please write the admin: ' . $this->getAdminEmailLink())); + $this->Flash->error( + __('Serious error, couldn\'t save to db, please write the admin: ' . $this->getAdminEmailLink()), + ['escape' => false]); } return true; } - public function getAdminEmailLink($text) { + public function getAdminEmailLink($text = '') { $serverAdminEmail = Configure::read('ServerAdminEmail'); return ''. $serverAdminEmail . ''; } diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index cf242b5a0..a52e67a3c 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -40,6 +40,7 @@ class DashboardController extends AppController } $user = $session->read('StateUser'); + //var_dump($user); $serverUser = $this->Auth->user('id'); if($serverUser) { $adminErrorsTable = TableRegistry::getTableLocator()->get('AdminErrors'); diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index 10a625b25..cebfa1e7f 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -49,7 +49,7 @@ class StateBalancesController extends AppController // sendRequestGDT // listPerEmailApi - //var_dump($user); + var_dump($user); $gdtSum = 0; //if('admin' === $user['role']) { $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi'); From aab346942277b4b7e661386120bf996727e55415 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Tue, 19 May 2020 12:00:35 +0000 Subject: [PATCH 09/12] Remove Debugg message --- src/Controller/StateBalancesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index cebfa1e7f..10a625b25 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -49,7 +49,7 @@ class StateBalancesController extends AppController // sendRequestGDT // listPerEmailApi - var_dump($user); + //var_dump($user); $gdtSum = 0; //if('admin' === $user['role']) { $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi'); From fece81e5e711491b008c5d679e4533f0b046deb8 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Mon, 25 May 2020 09:22:55 +0000 Subject: [PATCH 10/12] Update Error Message to know for which user the creation failed. --- src/Model/Transactions/TransactionCreation.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Model/Transactions/TransactionCreation.php b/src/Model/Transactions/TransactionCreation.php index 19985314f..d9caa9f7b 100644 --- a/src/Model/Transactions/TransactionCreation.php +++ b/src/Model/Transactions/TransactionCreation.php @@ -172,11 +172,13 @@ class TransactionCreation extends TransactionBase { ]); $newSum2 = $this->getAmount(); + $receiverEmail = ''; foreach($existingCreations2 as $creation) { $keyHex = bin2hex(stream_get_contents($creation->state_user->public_key)); //echo "\ncompare \n$keyHex\nwith: \n". $this->receiver_pubkey_hex."\n"; if($keyHex == $this->receiver_pubkey_hex) { $newSum2 += $creation->amount; + $receiverEmail = $creation->state_user->email; } //$newSum2 += $creation->amount; } @@ -188,7 +190,10 @@ class TransactionCreation extends TransactionBase { } } else {*/ if($newSum2 > 10000000) { - $this->addError('TransactionCreation::validate', 'Creation more than 1.000 GDD per Month in target_date not allowed'); + $this->addError( + 'TransactionCreation::validate', + 'Creation more than 1.000 GDD per Month for '. $receiverEmail .' in target_date not allowed' + ); return false; //} } From 4e0d44a43eb508bdd5bb1e37712a8d1953f57d01 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 10 Jun 2020 08:16:01 +0000 Subject: [PATCH 11/12] fix some possible errors --- src/Controller/AppController.php | 3 ++- src/Controller/StateBalancesController.php | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index c0fb8796c..073b2af01 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -258,7 +258,7 @@ class AppController extends Controller public function addAdminError($controller, $action, array $returnTable, $state_user_id) { if(!is_array($returnTable)) { - $this->addAdminError('AppController', 'addAdminError', ['state' => 'error', 'msg' => 'returnTable isn\'t array', 'details' => gettype($returnTable)]); + $this->addAdminError('AppController', 'addAdminError', ['state' => 'error', 'msg' => 'returnTable isn\'t array', 'details' => gettype($returnTable)], $state_user_id); return false; } $adminErrorTable = TableRegistry::getTableLocator()->get('AdminErrors'); @@ -277,6 +277,7 @@ class AppController extends Controller $this->Flash->error( __('Serious error, couldn\'t save to db, please write the admin: ' . $this->getAdminEmailLink()), ['escape' => false]); + } return true; } diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index 10a625b25..32f58d3a8 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -57,7 +57,11 @@ class StateBalancesController extends AppController if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) { $gdtSum = intval($gdtEntries['data']['sum']); } else { - $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user->id); + if($user) { + $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id']); + } else { + $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, 0); + } } //} // @@ -205,7 +209,7 @@ class StateBalancesController extends AppController $this->set('publishers', $publishers); } } else { - $this->addAdminError('StateBalancesController', 'overviewGdt', $requestResult, $user->id); + $this->addAdminError('StateBalancesController', 'overviewGdt', $requestResult, $user['id']); $this->Flash->error(__('Fehler beim GDT Server, bitte abwarten oder den Admin benachrichtigen!')); } From 1d431a0b527c766fb6101a9dd5b7b3d7c10d24c7 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Thu, 11 Jun 2020 11:12:52 +0000 Subject: [PATCH 12/12] add optional login server url to use forwarded url for example by using forwarding domain for dynamicDNS --- src/Controller/AppController.php | 18 ++++++++++++++---- src/Controller/StateUsersController.php | 2 +- .../TransactionCreationsController.php | 8 ++++---- .../TransactionSendCoinsController.php | 4 ++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 073b2af01..767aa45a7 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -32,7 +32,8 @@ use Cake\I18n\Time; */ class AppController extends Controller { - + + var $loginServerUrl = ''; /** * Initialization hook method. * @@ -127,6 +128,15 @@ class AppController extends Controller if($this->Auth->user('id')) { $GLOBALS['ServerUser'] = $this->Auth->user(); } + + // login server url + $loginServer = Configure::read('LoginServer'); + if($loginServer && isset($loginServer['url'])) { + $this->loginServerUrl = $loginServer['url'] . '/'; + } else { + $this->loginServerUrl = Router::url('/', true); + } + } @@ -220,7 +230,7 @@ class AppController extends Controller // we haven't get a pubkey? something seems to gone wrong on the login-server $this->Flash->error(__('no pubkey')); //var_dump($json); - return $this->redirect(Router::url('/', true) . 'account/error500/noPubkey', 303); + return $this->redirect($this->loginServerUrl . 'account/error500/noPubkey', 303); } } else { if($json['state'] === 'not found' ) { @@ -228,7 +238,7 @@ class AppController extends Controller } else { $this->Flash->error(__('Konto ist nicht aktiviert!')); } - return $this->redirect(Router::url('/', true) . 'account/', 303); + return $this->redirect($this->loginServerUrl . 'account/', 303); } } } catch(\Exception $e) { @@ -243,7 +253,7 @@ class AppController extends Controller if(isset($loginServer['path'])) { return $this->redirect($loginServer['path'], 303); } else { - return $this->redirect(Router::url('/', true) . 'account/', 303); + return $this->redirect($this->loginServerUrl . 'account/', 303); } } return true; diff --git a/src/Controller/StateUsersController.php b/src/Controller/StateUsersController.php index 1ef92801b..8c53ee4d1 100644 --- a/src/Controller/StateUsersController.php +++ b/src/Controller/StateUsersController.php @@ -109,7 +109,7 @@ class StateUsersController extends AppController if($dataJson['state'] != 'success') { if($dataJson['msg'] == 'session not found') { $session->destroy(); - return $this->redirect(Router::url('/', true) . 'account', 303); + return $this->redirect($this->loginServerUrl . 'account', 303); } } //var_dump($dataJson); diff --git a/src/Controller/TransactionCreationsController.php b/src/Controller/TransactionCreationsController.php index 745b63ef0..856b61989 100644 --- a/src/Controller/TransactionCreationsController.php +++ b/src/Controller/TransactionCreationsController.php @@ -151,7 +151,7 @@ class TransactionCreationsController extends AppController if($json['state'] != 'success') { if($json['msg'] == 'session not found') { $session->destroy(); - return $this->redirect(Router::url('/', true) . 'account', 303); + return $this->redirect($this->loginServerUrl . 'account', 303); } else { $this->addAdminError('TransactionCreations', 'create', $json, $user['id']); $this->Flash->error(__('Login Server Error, please wait for the admin to fix it')); @@ -166,7 +166,7 @@ class TransactionCreationsController extends AppController $session->write('Transactions.pending', $pendingTransactionCount); //echo "pending: " . $pendingTransactionCount; if($mode === 'next') { - return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303); + return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303); } else { $this->Flash->success(__('Transaction submitted for review.')); } @@ -392,7 +392,7 @@ class TransactionCreationsController extends AppController if($json['state'] != 'success') { if($json['msg'] == 'session not found') { $session->destroy(); - return $this->redirect(Router::url('/', true) . 'account', 303); + return $this->redirect($this->loginServerUrl . 'account', 303); } else { $this->addAdminError('TransactionCreations', 'createMulti', $json, $user['id']); $this->Flash->error(__('Login Server Error, please wait for the admin to fix it')); @@ -407,7 +407,7 @@ class TransactionCreationsController extends AppController $session->write('Transactions.pending', $pendingTransactionCount); //echo "pending: " . $pendingTransactionCount; if($mode === 'next') { - return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303); + return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303); } else { $this->Flash->success(__('Transaction submitted for review.')); } diff --git a/src/Controller/TransactionSendCoinsController.php b/src/Controller/TransactionSendCoinsController.php index 7204e24c2..3d5279220 100644 --- a/src/Controller/TransactionSendCoinsController.php +++ b/src/Controller/TransactionSendCoinsController.php @@ -235,7 +235,7 @@ class TransactionSendCoinsController extends AppController if($json['state'] != 'success') { if($json['msg'] == 'session not found') { $session->destroy(); - return $this->redirect(Router::url('/', true) . 'account', 303); + return $this->redirect($this->loginServerUrl . 'account', 303); //$this->Flash->error(__('session not found, please login again')); } else { $this->Flash->error(__('login server return error: ' . json_encode($json))); @@ -250,7 +250,7 @@ class TransactionSendCoinsController extends AppController $session->write('Transactions.pending', $pendingTransactionCount); //echo "pending: " . $pendingTransactionCount; if($mode === 'next') { - return $this->redirect(Router::url('/', true) . 'account/checkTransactions', 303); + return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303); } else { $this->Flash->success(__('Transaction submitted for review.')); }