Adds test with encryption, fixes stupid bug

This commit is contained in:
nikolark committed 2014-07-10 19:26:45 +02:00
1 parent 6ffc0d2042
commit 0f1140939c
5 files changed
+64 -5

No files matched your search

+2 -2
View File
@@ -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()));
+2
View File
@@ -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));
}
+57
View File
@@ -0,0 +1,57 @@
<?php
require_once("../lib/CryptoHelper.php");
require_once("../lib/functions.php");
require_once("../config.php");
/* Query */
function test_get_query() {
$number = "+4745115787";
//$data = file_get_contents("./testuser.json");
//$data = $crypt->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();
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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"
}