Merge pull request #1 from gradido/stage1

This commit is contained in:
einhornimmond 2021-02-19 16:03:46 +01:00 committed by GitHub
commit 5ce59b86d0
30 changed files with 710 additions and 408 deletions

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM phpdockerio/php74-fpm
# install php fpm
RUN apt-get update \
&& apt-get -y --no-install-recommends install curl unzip php7.4-curl php7.4-fpm php7.4-mbstring php7.4-intl php7.4-xml php7.4-pdo php7.4-mysql \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
WORKDIR /var/www/cakephp
RUN mkdir logs && mkdir tmp && chmod 777 logs && chmod 777 tmp
COPY ./community_server/ .
COPY ./configs/community_server/app.php ./config/
RUN composer update

View File

@ -42,7 +42,6 @@
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
"check": [
"@test",
"@cs-check"

View File

@ -397,6 +397,11 @@ return [
'host' => 'http://127.0.0.1',
'port' => 1201
],
'API' => [
'allowedCaller' => [''] // insert domains or ips from login-server and gdt if they not at localhost
],
'ServerAdminEmail' => 'info@gradido.net', // email 'from' field for transfer notification emails
'noReplyEmail' => 'no-replay@gradido.net', // email sender for creation notification emails to user
'GroupNode' => false
];

25
config/nginx/fastcgi.conf Normal file
View File

@ -0,0 +1,25 @@
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

88
config/nginx/mime.types Normal file
View File

@ -0,0 +1,88 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
image/svg+xml svg svgz;
image/webp webp;
application/font-woff woff;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.wap.wmlc wmlc;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

86
config/nginx/nginx.conf Normal file
View File

@ -0,0 +1,86 @@
server {
listen 80 ;
listen [::]:80;
server_name 0.0.0.0;
#include /etc/nginx/common/protect.conf;
#include /etc/nginx/common/protect_add_header.conf;
#include /etc/nginx/common/ssl.conf;
root /usr/share/nginx/html/webroot;
index index.php;
location ~* \.(png|jpg|ico|webp)\$ {
expires 30d;
}
location ~* \.(js|css) {
# expires 1d;
expires 1d;
}
location ~ \.php\$ {
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
#fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
location /account {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header Host \$host;
rewrite /account/(.*) /\$1 break;
#proxy_next_upstream error timeout invalid_header http_502 non_idempotent;
proxy_pass http://login-server:1200;
proxy_redirect off;
}
location /login_api {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header Host \$host;
rewrite /login_api/(.*) /\$1 break;
proxy_pass http://login-server:1201;
proxy_redirect off;
}
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
# access_log /var/log/nginx/access.log main;
}

View File

@ -0,0 +1,2 @@
#upload_max_filesize = 100M
#post_max_size = 108M

View File

@ -58,6 +58,7 @@ Router::scope('/', function (RouteBuilder $routes) {
// Skip token check for API URLs.
//die($request->getParam('controller'));
$whitelist = ['JsonRequestHandler', 'ElopageWebhook'];
foreach($whitelist as $entry) {
if($request->getParam('controller') === $entry) {
if($entry == 'ElopageWebhook') {

@ -1 +1 @@
Subproject commit 21d4a0a5e9a19f251e26c0ae07ce74be2fa99bbf
Subproject commit f0b1d113cee2a76e9dbb098b315f4acaf38410d0

View File

@ -1,9 +1,8 @@
CREATE TABLE `community_profiles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`state_user_id` int(10) unsigned NOT NULL,
`profile_img` longblob,
`profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `state_user_id` (`state_user_id`),
CONSTRAINT `community_profiles_ibfk_1` FOREIGN KEY (`state_user_id`) REFERENCES `state_users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `community_profiles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`state_user_id` int(10) unsigned NOT NULL,
`profile_img` longblob,
`profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `state_user_id` (`state_user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

View File

@ -139,13 +139,15 @@ class AppController extends Controller
}
}
protected function requestLogin()
protected function requestLogin($session_id = 0)
{
$session = $this->getRequest()->getSession();
// check login
// disable encryption for cookies
//$this->Cookie->configKey('User', 'encryption', false);
$session_id = intval($this->request->getCookie('GRADIDO_LOGIN', ''));
if(!$session_id) {
$session_id = intval($this->request->getCookie('GRADIDO_LOGIN', ''));
}
$ip = $this->request->clientIp();
if (!$session->check('client_ip')) {
$session->write('client_ip', $ip);
@ -156,8 +158,9 @@ class AppController extends Controller
if ($session_id != 0) {
$userStored = $session->read('StateUser');
$transactionPendings = $session->read('Transactions.pending');
$transactionPendings = $session->read('Transaction.pending');
$transactionExecutings = $session->read('Transaction.executing');
if ($session->read('session_id') != $session_id ||
( $userStored && (!isset($userStored['id']) || !$userStored['email_checked'])) ||
@ -185,7 +188,7 @@ class AppController extends Controller
$transactionPendings = $json['Transaction.pending'];
$transactionExecuting = $json['Transaction.executing'];
//echo "read transaction pending: $transactionPendings<br>";
$session->write('Transactions.pending', $transactionPendings);
$session->write('Transaction.pending', $transactionPendings);
$session->write('Transaction.executing', $transactionExecuting);
$session->write('session_id', $session_id);
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');

View File

@ -248,10 +248,14 @@ class JsonRequestHandlerController extends AppController {
$stateErrorEntity->transaction_type_id = $transaction->getTransactionBody()->getTransactionTypeId();
$stateErrorEntity->message_json = $json;
$stateErrorsTable->save($stateErrorEntity);
} else {
$errorArray['user_error'] = "user with $pub not found";
$json = json_encode($errorArray);
}
return $this->returnJsonEncoded($json);
}
}
}

View File

@ -15,7 +15,7 @@ class ServerUsersController extends AppController
public function initialize()
{
parent::initialize();
//$this->Auth->allow(['add', 'edit']);
$this->Auth->allow(['add', 'edit']);
$this->Auth->deny('index');
}

View File

@ -21,7 +21,7 @@ class StateBalancesController extends AppController
{
parent::initialize();
//$this->Auth->allow(['add', 'edit']);
$this->Auth->allow(['overview', 'overviewGdt']);
$this->Auth->allow(['overview', 'overviewGdt', 'ajaxGetBalance']);
$this->loadComponent('JsonRequestClient');
}
/**
@ -38,6 +38,8 @@ class StateBalancesController extends AppController
$this->set(compact('stateBalances'));
}
public function overview()
{
@ -174,6 +176,155 @@ class StateBalancesController extends AppController
$this->set('timeUsed', microtime(true) - $startTime);
$this->set('gdtSum', $gdtSum);
}
public function ajaxGetBalance($session_id)
{
if(!isset($session_id) || !$session_id) {
return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']);
}
$startTime = microtime(true);
$session = $this->getRequest()->getSession();
$result = $this->requestLogin($session_id);
if ($result !== true) {
return $this->returnJson(['state' => 'error', 'msg' => 'session not found']);
}
$user = $session->read('StateUser');
//var_dump($user);
return $this->returnJson(['state' => 'success', 'balance' => $user['balance']]);
}
public function ajaxListTransactions($session_id, $page, $count)
{
if(!isset($session_id) || !$session_id) {
return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']);
}
$startTime = microtime(true);
$session = $this->getRequest()->getSession();
$result = $this->requestLogin($session_id);
if ($result !== true) {
return $this->returnJson(['state' => 'error', 'msg' => 'session not found']);
}
$user = $session->read('StateUser');
$gdtSum = 0;
$gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi');
if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) {
$gdtSum = intval($gdtEntries['data']['sum']);
} else {
if($user) {
$this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id']);
} else {
$this->addAdminError('StateBalancesController', 'overview', $gdtEntries, 0);
}
}
$creationsTable = TableRegistry::getTableLocator()->get('TransactionCreations');
$creationTransactions = $creationsTable
->find('all')
->where(['state_user_id' => $user['id']])
->contain(['Transactions']);
$transferTable = TableRegistry::getTableLocator()->get('TransactionSendCoins');
$transferTransactions = $transferTable
->find('all')
->where(['OR' => ['state_user_id' => $user['id'], 'receiver_user_id' => $user['id']]])
->contain(['Transactions']);
$involvedUserIds = [];
foreach ($transferTransactions as $sendCoins) {
//var_dump($sendCoins);
if ($sendCoins->state_user_id != $user['id']) {
array_push($involvedUserIds, intval($sendCoins->state_user_id));
} elseif ($sendCoins->receiver_user_id != $user['id']) {
array_push($involvedUserIds, intval($sendCoins->receiver_user_id));
}
}
/*echo "state user from sendCoins: $sendCoins->state_user_id<br>";
echo "receiver user from sendCoins: $sendCoins->receiver_user_id<br>";
echo "user id from logged in user: ".$user['id']. '<br>';
*/
//var_dump($involvedUserIds);
// exchange key with values and drop duplicates
$involvedUser_temp = array_flip($involvedUserIds);
// exchange back
$involvedUserIds = array_flip($involvedUser_temp);
$userTable = TableRegistry::getTableLocator()->get('StateUsers');
$involvedUser = $userTable->find('all', [
'contain' => false,
'where' => ['id IN' => $involvedUserIds],
'fields' => ['id', 'first_name', 'last_name', 'email']
]);
//var_dump($involvedUser->toArray());
$involvedUserIndices = [];
foreach ($involvedUser as $involvedUser) {
$involvedUserIndices[$involvedUser->id] = $involvedUser;
}
// sender or receiver when user has sended money
// group name if creation
// type: gesendet / empfangen / geschöpft
// transaktion nr / id
// date
// balance
$transactions = [];
foreach ($creationTransactions as $creation) {
//var_dump($creation);
array_push($transactions, [
'name' => 'Gradido Akademie',
'type' => 'creation',
'transaction_id' => $creation->transaction_id,
'date' => $creation->transaction->received,
'balance' => $creation->amount,
'memo' => $creation->transaction->memo
]);
}
foreach ($transferTransactions as $sendCoins) {
$type = '';
$otherUser = null;
if ($sendCoins->state_user_id == $user['id']) {
$type = 'send';
if(isset($involvedUserIndices[$sendCoins->receiver_user_id])) {
$otherUser = $involvedUserIndices[$sendCoins->receiver_user_id];
}
} else if ($sendCoins->receiver_user_id == $user['id']) {
$type = 'receive';
if(isset($involvedUserIndices[$sendCoins->state_user_id])) {
$otherUser = $involvedUserIndices[$sendCoins->state_user_id];
}
}
if(null == $otherUser) {
$otherUser = $this->StateBalances->StateUsers->newEntity();
}
array_push($transactions, [
'name' => $otherUser->first_name . ' ' . $otherUser->last_name,
'email' => $otherUser->email,
'type' => $type,
'transaction_id' => $sendCoins->transaction_id,
'date' => $sendCoins->transaction->received,
'balance' => $sendCoins->amount,
'memo' => $sendCoins->transaction->memo
]);
}
uasort($transactions, array($this, 'sortTransactions'));
return $this->returnJson([
'state' => 'success',
'transactions' => $transactions,
'transactionExecutingCount' => $session->read('Transaction.executing'),
'count' => count($transactions),
'gdtSum' => $gdtSum,
'timeUsed' => microtime(true) - $startTime
]);
}
public function overviewGdt()
{

View File

@ -5,6 +5,8 @@ use Cake\Routing\Router;
use Cake\I18n\I18n;
use Cake\I18n\FrozenTime;
use Cake\ORM\TableRegistry;
use Cake\Http\Client;
use Cake\Core\Configure;
use App\Controller\AppController;
use App\Form\UserSearchForm;
@ -43,7 +45,7 @@ class StateUsersController extends AppController
$this->Auth->allow([
'search', 'ajaxCopyLoginToCommunity', 'ajaxCopyCommunityToLogin',
'ajaxDelete', 'ajaxCountTransactions', 'ajaxVerificationEmailResend',
'ajaxGetUserEmailVerificationCode'
'ajaxGetUserEmailVerificationCode', 'ajaxGetCSFRToken'
]);
$this->set(
'naviHierarchy',
@ -433,6 +435,40 @@ class StateUsersController extends AppController
}
return $this->returnJson(['state' => 'error', 'msg' => 'no post request']);
}
public function ajaxGetCSFRToken($session_id)
{
if(!isset($session_id) || $session_id == 0) {
$this->returnJson(['state' => 'error', 'msg' => 'no session id']);
}
$client_ip = $this->request->clientIp();
$loginServer = Configure::read('LoginServer');
$url = $loginServer['host'] . ':' . $loginServer['port'];
$http = new Client();
$response = $http->get($url . '/login', ['session_id' => $session_id]);
$json = $response->getJson();
if (isset($json) && count($json) > 0) {
if ($json['state'] === 'success') {
if($json['clientIP'] == $client_ip) {
return $this->returnJson(['state' => 'success', 'csfr' => $this->request->getParam('_csrfToken')]);
} else {
return $this->returnJson([
'state' => 'error',
'msg' => 'client ip mismatch',
'details' => ['login_server' => $json['clientIP'], 'caller' => $client_ip]]);
}
} else {
return $this->returnJson($json);
}
} else {
return $this->returnJson(['state' => 'error', 'invalid response form logins server']);
}
}
/*
getField(vnode, 'receive'),

View File

@ -247,9 +247,9 @@ class TransactionCreationsController extends AppController
['AND' => [
'disabled' => 0,
'OR' => [
'LOWER(first_name)' => strtolower($requestData['searchText']),
'LOWER(last_name)' => strtolower($requestData['searchText']),
'LOWER(email)' => strtolower($requestData['searchText'])
'LOWER(first_name) LIKE' => '%'.strtolower($requestData['searchText']).'%',
'LOWER(last_name) LIKE' => '%'.strtolower($requestData['searchText']).'%',
'LOWER(email) LIKE' => '%'.strtolower($requestData['searchText']).'%'
]
]
]

View File

@ -23,6 +23,7 @@
</nav>
<div class="stateUsers view large-10 medium-9 columns content">
<h3><?= h($stateUser->first_name) ?> <?= h($stateUser->last_name) ?> &lt;<?= h($stateUser->email) ?>&gt;</h3>
<small>Konto-Adresse: <?= h(bin2hex(stream_get_contents($stateUser->public_key))) ?></small>
<div class="related">
<h4><?= __('State Balance') ?></h4>
<?php if (!empty($stateUser->state_balances)): ?>
@ -47,10 +48,11 @@
<div class="related">
<h4><?= __('Schöpfungen') ?></h4>
<?php if (!empty($stateUser->transaction_creations)): ?>
<table cellpadding="0" cellspacing="0">
<table cellpadding="5">
<tr>
<th scope="col"><?= __('Transaction') ?></th>
<th scope="col"><?= __('Erhalten') ?></th>
<th scope="col"><?= __('Verrechnungs-Datum') ?></th>
<th scope="col"><?= __('Betrag') ?></th>
<th scope="col"><?= __('Verwendungszweck') ?></th>
<th scope="col" class="actions"><?= __('Actions') ?></th>
@ -62,6 +64,7 @@
<tr>
<td><?= $this->Html->link(substr($txHash, 0, 12) . '...', ['controller' => 'Transactions', 'action' => 'view', $transactionCreations->transaction_id], ['title' => $txHash] ) ?></td>
<td><?= h($transactionCreations->transaction->received) ?></td>
<td><?= h($transactionCreations->target_date) ?></td>
<td><?= $this->element('printGradido', ['number' =>$transactionCreations->amount]) ?></td>
<td title="<?= $memo ?>"><?= h(substr($memo, 0, 20). '...') ?></td>
<td class="actions">
@ -75,7 +78,7 @@
<div class="related">
<h4><?= __('Versendete Überweisungen') ?></h4>
<?php if (!empty($stateUser->transaction_send_coins)): ?>
<table cellpadding="0" cellspacing="0">
<table cellpadding="5">
<tr>
<th scope="col"><?= __('Überweisung') ?></th>
<th scope="col"><?= __('Erhalten') ?></th>
@ -109,7 +112,7 @@
<div class="related">
<h4><?= __('Empfangende Überweisungen') ?></h4>
<?php if (!empty($stateUser->transaction_received_coins)): ?>
<table cellpadding="0" cellspacing="0">
<table cellpadding="5">
<tr>
<th scope="col"><?= __('Überweisung') ?></th>
<th scope="col"><?= __('Erhalten') ?></th>

@ -1 +1 @@
Subproject commit 81a461566e46d71533dc3e284fa075d7d68fd020
Subproject commit 9004e6978ac3dafcc635b2ffcf8bc6a156451cca

View File

@ -37,22 +37,31 @@ class TransactionCreationsFixture extends TestFixture
public function init()
{
//(8, 17, 11, 1210000, 0x2d31333636313339343833000000000000000000000000000000000000000000)
// (1, 1, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2020-12-01 00:00:00'),
// (2, 2, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'),
// (3, 3, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2021-02-01 00:00:00');
$this->records = [
[
'id' => 1,
'transaction_id' => 1,
'state_user_id' => 11,
'state_user_id' => 2,
'amount' => 10000000,
'ident_hash' => hex2bin('2d31333636313339343833000000000000000000000000000000000000000000')
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
[
'id' => 8,
'transaction_id' => 17,
'state_user_id' => 11,
'amount' => 1210000,
'ident_hash' => hex2bin('2d31333636313339343833000000000000000000000000000000000000000000')
'id' => 2,
'transaction_id' => 2,
'state_user_id' => 2,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
[
'id' => 3,
'transaction_id' => 3,
'state_user_id' => 2,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
];
parent::init();

View File

@ -38,15 +38,16 @@ class TransactionSendCoinsFixture extends TestFixture
*/
public function init()
{
// (1, 4, 2, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355, 1, 15000000, 15000000);
$this->records = [
[
'id' => 1,
'transaction_id' => 1,
'state_user_id' => 1,
'receiver_public_key' => 'Lorem ipsum dolor sit amet',
'receiver_user_id' => 'Lorem ipsum dolor sit amet',
'amount' => 1,
'sender_final_balance' => 1
'transaction_id' => 4,
'state_user_id' => 2,
'receiver_public_key' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355',
'receiver_user_id' => 1,
'amount' => 150000001,
'sender_final_balance' => 15000000
],
];
parent::init();

View File

@ -35,12 +35,34 @@ class TransactionSignaturesFixture extends TestFixture
*/
public function init()
{
// (1, 1, 0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355),
// (2, 2, 0x01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355),
// (3, 3, 0x2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355),
// (4, 4, 0xcb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102, 0xcccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088);
$this->records = [
[
'id' => 1,
'transaction_id' => 1,
'signature' => 'Lorem ipsum dolor sit amet',
'pubkey' => 'Lorem ipsum dolor sit amet'
'signature' => '0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705',
'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'
],
[
'id' => 2,
'transaction_id' => 2,
'signature' => '0x01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f',
'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'
],
[
'id' => 3,
'transaction_id' => 3,
'signature' => '0x2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602',
'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'
],
[
'id' => 4,
'transaction_id' => 4,
'signature' => '0xcb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102',
'pubkey' => '0xcccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088'
],
];
parent::init();

View File

@ -36,23 +36,42 @@ class TransactionsFixture extends TestFixture
*/
public function init()
{
//(17, 0, 1, 0x0000000000000000000000000000000000000000000000000000000000000000, '', '2019-11-05 15:13:27');
// (1, NULL, 1, 0x7dc55cf3a1a39b441d87d5452c40cad8e7fd8aab573ed1da0bf118129fc77987, 'AGE Dezember 2020', '2021-02-19 13:18:52'),
// (2, NULL, 1, 0xdea38d4dd72af1e0d90621ae8139efbbdb3b44b60be04b0d40cfc157afd2c19c, 'AGE Januar 2021', '2021-02-19 13:25:36'),
// (3, NULL, 1, 0x4e7734ed84dcd8ddc5286b87ff85eb12704092d51f485e7c4dbcb4a68ba296ce, 'AGE Februar 2021', '2021-02-19 13:25:37'),
// (4, NULL, 2, 0x065b5b75b7f4b156fe2b07b54b1a3df0c4eadc40c0f6940c666fed4d75751f8f, 'Ich teile mit dir\r\n \r\nmiau _=', '2021-02-19 13:27:14');
$this->records = [
[
'id' => 1,
'group_id' => 0,
'group_id' => NULL,
'transaction_type_id' => 1,
'tx_hash' => '0x0000000000000000000000000000000000000000000000000000000000000000',
'memo' => '',
'received' => 1571314633
'tx_hash' => '0x7dc55cf3a1a39b441d87d5452c40cad8e7fd8aab573ed1da0bf118129fc77987',
'memo' => 'AGE Dezember 2020',
'received' => '2021-02-19 13:18:52'
],
[
'id' => 17,
'group_id' => 0,
'id' => 2,
'group_id' => NULL,
'transaction_type_id' => 1,
'tx_hash' => '0x0000000000000000000000000000000000000000000000000000000000000000',
'memo' => '',
'received' => 1572966807
'tx_hash' => '0xdea38d4dd72af1e0d90621ae8139efbbdb3b44b60be04b0d40cfc157afd2c19c',
'memo' => 'AGE Januar 2021',
'received' => '2021-02-19 13:25:36'
],
[
'id' => 3,
'group_id' => NULL,
'transaction_type_id' => 1,
'tx_hash' => '0x4e7734ed84dcd8ddc5286b87ff85eb12704092d51f485e7c4dbcb4a68ba296ce',
'memo' => 'AGE Februar 2021',
'received' => '2021-02-19 13:25:37'
],
[
'id' => 4,
'group_id' => NULL,
'transaction_type_id' => 2,
'tx_hash' => '0x065b5b75b7f4b156fe2b07b54b1a3df0c4eadc40c0f6940c666fed4d75751f8f',
'memo' => 'Ich teile mit dir\r\n \r\nmiau _=',
'received' => '2021-02-19 13:27:14'
],
];
parent::init();

View File

@ -1,80 +0,0 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\ElopageBuysController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\ElopageBuysController Test Case
*
* @uses \App\Controller\ElopageBuysController
*/
class ElopageBuysControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.ElopageBuys',
'app.ElopageUsers',
'app.AffiliatePrograms',
'app.Publishers',
'app.Orders',
'app.Products',
];
/**
* Test index method
*
* @return void
*/
public function testIndex()
{
$this->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.');
}
}

View File

@ -1,7 +1,6 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\JsonRequestHandlerController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
@ -70,14 +69,14 @@ class JsonRequestHandlerControllerTest extends TestCase
public function testNotSetTransaction()
{
$this->postAndParse(
$this->postAndParse(
['method' => 'putTransaction'],
['state' => 'error', 'msg' => 'parameter error']
);
}
public function testNotSetMethod()
{
$this->postAndParse(
$this->postAndParse(
['transaction' => $this->transactions['validCreation']],
['state' => 'error', 'msg' => 'parameter error']
);
@ -86,7 +85,7 @@ class JsonRequestHandlerControllerTest extends TestCase
public function testUnknownMethod()
{
//$this->post('/TransactionJsonRequestHandler', ['method' => 'putTransaction', 'transaction' => 'CgpIYWxsbyBXZWx0EgYIyfSG7gVKLwonCiCboKikqwjZfes9xuqgthFH3/cHHaWchkUhWiGhQjB23xCg2pMBELWJ7ZYK']);
$this->postAndParse(
$this->postAndParse(
['method' => 'foobar', 'transaction' => $this->transactions['validCreation']],
['state' => 'error', 'msg' => 'unknown method', 'details' => 'foobar']
);
@ -160,9 +159,14 @@ class JsonRequestHandlerControllerTest extends TestCase
private function postAndParse($params, $expected)
{
//$this->enableCsrfToken();
//$this->enableSecurityToken();
$token = 'my-csrf-token';
$this->cookie('csrfToken', $token);
$this->configRequest([
'headers' => ['Accept' => 'application/json']
'headers' => ['Accept' => 'application/json', 'X-CSRF-Token' => $token]
]);
$this->disableErrorHandlerMiddleware();

View File

@ -0,0 +1,178 @@
<?php
namespace App\Test\TestCase\Controller;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\StateBalancesController Test Case
*
* @uses \App\Controller\StateBalancesController
*/
class StateBalancesControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.TransactionCreations',
'app.Transactions',
'app.StateUsers',
'app.StateErrors',
'app.TransactionSignatures',
'app.TransactionSendCoins',
'app.StateBalances',
'app.TransactionTypes'
];
/**
* Test initialize method
*
* @return void
*/
public function testInitialize()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test index method
*
* @return void
*/
public function testIndex()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test overview method
*
* @return void
*/
public function testOverview()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test ajaxGetBalance method
*
* @return void
*/
public function testAjaxGetBalance()
{
$session_id = rand();
$balance = rand();
$this->session([
'session_id' => $session_id,
'Transaction' => ['pending' => 0, 'executing' => 0],
'StateUser' => [
'id' => 2, // 1 don't work, I don't know why
'email_checked' => 1,
'balance' => $balance
]
]);
//echo "balance: $balance";
$this->getAndParse('/state-balances/ajaxGetBalance/' . $session_id,
['state' => 'success', 'balance' => $balance]
);
}
/**
* Test ajaxListTransactions method
*
* @return void
*/
public function testAjaxListTransactions()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test overviewGdt method
*
* @return void
*/
public function testOverviewGdt()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test sortTransactions method
*
* @return void
*/
public function testSortTransactions()
{
$this->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.');
}
private function getAndParse($path, $expected)
{
$this->configRequest([
'headers' => ['Accept' => 'application/json']
]);
$this->disableErrorHandlerMiddleware();
$this->get($path);
// 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);
}
}

View File

@ -1,78 +0,0 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\UsersController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\UsersController Test Case
*
* @uses \App\Controller\UsersController
*/
class UsersControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.Users',
'app.EmailOptIn',
'app.UserBackups',
'app.UserRoles',
];
/**
* Test index method
*
* @return void
*/
public function testIndex()
{
$this->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.');
}
}

View File

@ -1,97 +0,0 @@
<?php
namespace App\Test\TestCase\Model\Table;
use App\Model\Table\ElopageBuysTable;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
/**
* App\Model\Table\ElopageBuysTable Test Case
*/
class ElopageBuysTableTest extends TestCase
{
/**
* Test subject
*
* @var \App\Model\Table\ElopageBuysTable
*/
public $ElopageBuys;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.ElopageBuys',
'app.ElopageUsers',
'app.AffiliatePrograms',
'app.Publishers',
'app.Orders',
'app.Products',
];
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$config = TableRegistry::getTableLocator()->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.');
}
}

View File

@ -1,95 +0,0 @@
<?php
namespace App\Test\TestCase\Model\Table;
use App\Model\Table\UsersTable;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
/**
* App\Model\Table\UsersTable Test Case
*/
class UsersTableTest extends TestCase
{
/**
* Test subject
*
* @var \App\Model\Table\UsersTable
*/
public $Users;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.Users',
'app.EmailOptIn',
'app.UserBackups',
'app.UserRoles',
];
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$config = TableRegistry::getTableLocator()->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.');
}
}

4
tests/testApi.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
cd ..
sudo -u www-data ./vendor/bin/phpunit --testdox tests/TestCase/Controller/StateBalancesControllerTest
cd tests