You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. $host = "https://api.vdm.rthoni.com/";
  3. $key = "demo42";
  4. header("Content-Type: text/plain");
  5. $token = "";
  6. function error($http)
  7. {
  8. echo "[ KO ] ";
  9. var_dump($http);
  10. die();
  11. }
  12. function check_error($http)
  13. {
  14. if ($http->responseCode != 200)
  15. error($http);
  16. return json_decode($http->body);
  17. }
  18. function api_post($url, $param)
  19. {
  20. global $host;
  21. global $key;
  22. global $token;
  23. $http = http_post_fields($host . $url, $param, array(), array("headers" =>
  24. array("Api-Key" => $key, "Authorization" => $token)));
  25. return check_error(http_parse_message($http));
  26. }
  27. function api_get($url, $param)
  28. {
  29. global $host;
  30. global $key;
  31. global $token;
  32. $f = true;
  33. foreach ($param as $k => $v)
  34. {
  35. if ($f)
  36. {
  37. $f = false;
  38. $url .= "?";
  39. }
  40. else
  41. $url .= "&";
  42. $url .= urlencode($k) . "=" . urlencode($v);
  43. }
  44. $http = http_get($host . $url, array("headers" =>
  45. array("Api-Key" => $key, "Authorization" => $token)));
  46. return check_error(http_parse_message($http));
  47. }
  48. function add_status($status, $long, $lat, $r)
  49. {
  50. $params = array("status" => $status);
  51. if ($long !== null)
  52. $params["longitude"] = $long;
  53. if ($lat !== null)
  54. $params["latitude"] = $lat;
  55. $s = api_post("status", $params);
  56. if ($s->user_id != $r->id)
  57. die("[ KO ] Users ids don't match");
  58. if (($long !== null && $s->longitude != $long)
  59. || ($long === null && $s->longitude != null))
  60. die("[ KO ] Longitudes don't match");
  61. if (($lat !== null && $s->latitude != $lat)
  62. || ($lat === null && $s->latitude != null))
  63. die("[ KO ] Latitudes don't match");
  64. echo "[ OK ] Status added\n";
  65. }
  66. function mk_status($status, $long, $lat)
  67. {
  68. return array("status" => $status,
  69. "long" => $long,
  70. "lat" => $lat);
  71. }
  72. $username = "check_" . rand();
  73. $password = md5(rand());
  74. $user_pass = array("username" => $username, "password" => $password);
  75. $r = api_post("user", $user_pass);
  76. echo "[ OK ] User " . $r->username . " (" . $r->id . ") created\n";
  77. $l = api_post("user/login", $user_pass);
  78. if ($l->username != $r->username)
  79. die("[ KO ] Usernames don't match");
  80. if ($l->id != $r->id)
  81. die("[ KO ] Users ids don't match");
  82. $token = $r->token;
  83. echo "[ OK ] User " . $r->username . " (" . $r->id . ") logged in\n";
  84. $status = array(mk_status("check status null null", null, null),
  85. mk_status("check status 42 null", 42, null),
  86. mk_status("check status null 42", null, 42),
  87. mk_status("check status 42.42 42", 42.42, 42));
  88. foreach ($status as $st)
  89. add_status($st['status'], $st['long'], $st['lat'], $r);
  90. $f = api_get("status/feed", array());
  91. if (count($f) != count($status))
  92. die("[ KO ] Did not found " . count($status).
  93. " status (Was the database cleared?)\n");
  94. echo "[ OK ] All the status were added\n";
  95. api_post("status/" . $f[0]->id . "/confirm", array("confirmation" => 1));
  96. echo "[ OK ] Status confirmed once\n";
  97. api_post("status/" . $f[0]->id . "/confirm", array("confirmation" => 0));
  98. echo "[ OK ] Status confirmed tiwce\n";
  99. ?>