Esempio n. 1
0
 public function testUpload()
 {
     $user = \Tests\KnownTestCase::user();
     $result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'photo/edit', ['title' => 'A Photo upload', 'body' => "Uploading a pretty picture via the api", 'photo' => \Idno\Core\WebserviceFile::createFromCurlString("@" . dirname(__FILE__) . "/" . self::$file . ";filename=Photo.jpg;type=image/jpeg")], ['Accept: application/json', 'X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/photo/edit', $user->getAPIkey(), true))]);
     print_r($result);
     $content = json_decode($result['content']);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue(!empty($content));
     $this->assertTrue(!empty($content->location));
     $this->assertTrue($response == 200);
 }
Esempio n. 2
0
 public function testAuthenticated()
 {
     $user = \Tests\KnownTestCase::user();
     $result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'status/edit', ['body' => "Making a nice test post via the api"], ['Accept: application/json', 'X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/status/edit', $user->getAPIkey(), true))]);
     print_r($result);
     $content = json_decode($result['content']);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue(!empty($content));
     $this->assertTrue(!empty($content->location));
     $this->assertTrue($response == 200);
 }
Esempio n. 3
0
 public function testAdminGatekeeper()
 {
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . 'admin/', [], []);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue($response == 403);
     $user = \Tests\KnownTestCase::user();
     $this->assertTrue(is_object(\Idno\Core\Idno::site()->session()->logUserOn($user)));
     // Try normal user
     \Idno\Core\Idno::site()->session()->logUserOff();
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . 'admin/', [], ['X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/admin/', $user->getAPIkey(), true))]);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue($response == 403);
     // Try admin
     $user = \Tests\KnownTestCase::admin();
     $this->assertTrue(is_object(\Idno\Core\Idno::site()->session()->logUserOn($user)));
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . 'admin/', [], ['X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/admin/', $user->getAPIkey(), true))]);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue($response == 200);
     \Idno\Core\Idno::site()->session()->logUserOff();
 }