diff --git a/snapporder/api/register.php b/snapporder/api/register.php index a7fc2b8..a94e659 100644 --- a/snapporder/api/register.php +++ b/snapporder/api/register.php @@ -53,7 +53,7 @@ if(strlen($body) === 0) { /* Decrypt body */ $crypt = new CryptoHelper(SNAP_IV, SNAP_KEY); -$body = $crypt->decrypt($body); +$body = $crypt->decrypt(trim($body)); $data = (array) json_decode($body); if($data === NULL) { set_response_code(400); @@ -143,7 +143,7 @@ if( isset($data['purchased']) ) { /* Create user */ $user_id = NULL; try { - $user_id = add_user($user_id); + $user_id = add_user($data); } catch(InsideDatabaseException $e) { set_response_code(500); echo $crypt->json_encode_and_encrypt(array('error' => 'db_error', 'error_message' => $e->getMessage())); diff --git a/snapporder/lib/CryptoHelper.php b/snapporder/lib/CryptoHelper.php index dd97568..02734a9 100644 --- a/snapporder/lib/CryptoHelper.php +++ b/snapporder/lib/CryptoHelper.php @@ -32,6 +32,7 @@ class CryptoHelper public function decrypt($code) { + //return $code; $code = $this->hex2bin($code); $iv = $this->iv; @@ -58,6 +59,7 @@ class CryptoHelper } public function json_encode_and_encrypt($data) { + //return json_encode($data); return $this->encrypt(json_encode($data)); } diff --git a/snapporder/tests/integration.php b/snapporder/tests/integration.php new file mode 100644 index 0000000..acb7e42 --- /dev/null +++ b/snapporder/tests/integration.php @@ -0,0 +1,57 @@ +encrypt($data); + $ch = curl_init('http://inside.dev/snapporder/api/query.php?phone='.urlencode($number)); + //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); + //curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json ')); + + $result = curl_exec($ch); + $crypt = new CryptoHelper(SNAP_IV, SNAP_KEY); + $result = $crypt->decrypt(trim($result)); + $decoded_result = (array) json_decode($result); + + if($decoded_result['phone'] === $number) { + echo "OK"; + } else { + echo "FAIL"; + } + curl_close ($ch); +} +/* Register */ +function test_post_register() { + $crypt = new CryptoHelper(SNAP_IV, SNAP_KEY); + $data = file_get_contents("./testuser.json"); + + $data = $crypt->encrypt($data); + $ch = curl_init('http://inside.dev/snapporder/api/register.php'); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json ')); + + $result = curl_exec($ch); + $result = $crypt->decrypt(trim($result)); + $decoded_result = json_decode($result); + + if(!isset($decoded_result->error)) { + echo "OK"; + var_dump($decoded_result); + } else { + echo "FAIL\n"; + var_dump($decoded_result); + } + /* Register */ + curl_close ($ch); +} +//test_get_query(); +test_post_register(); diff --git a/snapporder/tests/integration.sh b/snapporder/tests/integration.sh index 7cbdc81..7eefc52 100755 --- a/snapporder/tests/integration.sh +++ b/snapporder/tests/integration.sh @@ -1,5 +1,5 @@ #!/bin/sh -HOST="https://inside.neuf.no" +HOST="http://inside.dev" curl -XPOST -H"Content-type: application/json" --data-binary @testuser.json $HOST/snapporder/api/register.php diff --git a/snapporder/tests/testuser.json b/snapporder/tests/testuser.json index eb31ab6..6752243 100644 --- a/snapporder/tests/testuser.json +++ b/snapporder/tests/testuser.json @@ -1,7 +1,7 @@ { "firstname": "Üve", "lastname": "Bårdvigsen", - "email": "aaaadadfz@aaa422asd333a44za.com", + "email": "aaaadadfzooaaa@aaa422asd333a44za.com", "birthdate": "1985-02-05", - "phone": "+4745115787" + "phone": "+4745199787" }