From 55e0e4b4d8a2cde766820ee4f6cc8c0351f22537 Mon Sep 17 00:00:00 2001 From: Lee Hicks Date: Thu, 28 Dec 2017 11:18:36 -0500 Subject: [PATCH] version bump and cleanup --- .dreamfactory.php | 2 +- CHANGELOG.md | 10 +- README.md | 2 +- composer.json | 8 +- src/Testing/FileServiceTestCase.php | 1 - src/Testing/UserResourceTestCase.php | 470 --------------------------- tests/AdminResourceTest.php | 235 -------------- tests/RoleResourceTest.php | 324 ------------------ tests/SystemServiceTest.php | 46 --- 9 files changed, 16 insertions(+), 1082 deletions(-) delete mode 100644 src/Testing/UserResourceTestCase.php delete mode 100644 tests/AdminResourceTest.php delete mode 100644 tests/RoleResourceTest.php delete mode 100644 tests/SystemServiceTest.php diff --git a/.dreamfactory.php b/.dreamfactory.php index b6a120c5..0756f1e1 100644 --- a/.dreamfactory.php +++ b/.dreamfactory.php @@ -1,7 +1,7 @@ - * Copyright 2012-2017 DreamFactory Software, Inc. + * Copyright 2012-2018 DreamFactory Software, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/CHANGELOG.md b/CHANGELOG.md index 91fe7302..21bcb8ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] + +## [0.14.0] - 2017-12-28 ### Added - DF-1251 Added alternative means (external db) of authentication - New ServiceManager methods and test cases for retrieving service names by service type or group - Added helper function and pub-sub interface +- Added package discovery - Added schema retrieval to some internal types to aid in automatic document generation ### Fixed - DF-1259 Correct OAS3 handling of comma-delimited URL query parameters @@ -32,7 +35,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Moved service request logging into service handling area so all paths to services are logged - DF-1150 Update copyright and support email - Cleanup and simplify routing -- Updated test cases, .gitignore, dependencies +- Updated test cases, .gitignore, and dependencies - Updated homestead config to support --dev option - Cleanup facade usage and documentation - Catch invalid service type in access check @@ -57,7 +60,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Upgraded Swagger to OpenAPI 3.0 specification - DF-1233, DF-1246 Tailor system/environment call for various authentication levels - Updated homestead configuration -- Updated unit testcases +- Updated unit test cases - Sort system/service_type by name ### Fixed - Correcting role access view of api/v2 service listing @@ -615,7 +618,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## 0.1.0 - 2015-10-24 First official release working with the new [dreamfactory](https://github.com/dreamfactorysoftware/dreamfactory) project. -[Unreleased]: https://github.com/dreamfactorysoftware/df-core/compare/0.13.1...HEAD +[Unreleased]: https://github.com/dreamfactorysoftware/df-core/compare/0.14.0...HEAD +[0.14.0]: https://github.com/dreamfactorysoftware/df-core/compare/0.13.1...0.14.0 [0.13.1]: https://github.com/dreamfactorysoftware/df-core/compare/0.13.0...0.13.1 [0.13.0]: https://github.com/dreamfactorysoftware/df-core/compare/0.12.3...0.13.0 [0.12.3]: https://github.com/dreamfactorysoftware/df-core/compare/0.12.2...0.12.3 diff --git a/README.md b/README.md index bbe13af4..d366542d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ For more information, see the [full platform repository](https://github.com/drea Edit your project’s composer.json to require the following package. “require”:{ - "dreamfactory/df-core": "~0.13.0" + "dreamfactory/df-core": "~0.14.0" } Save your composer.json and do a "composer update" to install the package. diff --git a/composer.json b/composer.json index 885ce005..d1e16092 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,12 @@ "email": "leehicks@dreamfactory.com" } ], + "support": { + "email": "dspsupport@dreamfactory.com", + "source": "https://github.com/dreamfactorysoftware/df-core", + "issues": "https://github.com/dreamfactorysoftware/df-core/issues", + "wiki": "https://wiki.dreamfactory.com" + }, "require": { "php": ">=7.0.0", "barryvdh/laravel-cors": "~0.10.0", @@ -50,7 +56,7 @@ }, "extra": { "branch-alias": { - "dev-develop": "0.13.x-dev" + "dev-develop": "0.14.x-dev" }, "laravel": { "providers": [ diff --git a/src/Testing/FileServiceTestCase.php b/src/Testing/FileServiceTestCase.php index 9afc142a..10097455 100644 --- a/src/Testing/FileServiceTestCase.php +++ b/src/Testing/FileServiceTestCase.php @@ -3,7 +3,6 @@ namespace DreamFactory\Core\Testing; use DreamFactory\Core\Enums\Verbs; -use DreamFactory\Core\Enums\HttpStatusCodes; abstract class FileServiceTestCase extends TestCase { diff --git a/src/Testing/UserResourceTestCase.php b/src/Testing/UserResourceTestCase.php deleted file mode 100644 index bd1e65e9..00000000 --- a/src/Testing/UserResourceTestCase.php +++ /dev/null @@ -1,470 +0,0 @@ - 'John Doe', - 'first_name' => 'John', - 'last_name' => 'Doe', - 'email' => 'jdoe@dreamfactory.com', - 'password' => 'test1234', - 'security_question' => 'Make of your first car?', - 'security_answer' => 'mazda', - 'is_active' => true - ]; - - protected $user2 = [ - 'name' => 'Jane Doe', - 'first_name' => 'Jane', - 'last_name' => 'Doe', - 'email' => 'jadoe@dreamfactory.com', - 'password' => 'test1234', - 'is_active' => true, - 'lookup_by_user_id' => [ - [ - 'name' => 'test', - 'value' => '1234', - 'private' => false - ], - [ - 'name' => 'test2', - 'value' => '5678', - 'private' => true - ] - ] - ]; - - protected $user3 = [ - 'name' => 'Dan Doe', - 'first_name' => 'Dan', - 'last_name' => 'Doe', - 'email' => 'ddoe@dreamfactory.com', - 'password' => 'test1234', - 'is_active' => true, - 'lookup_by_user_id' => [ - [ - 'name' => 'test', - 'value' => '1234', - 'private' => false - ], - [ - 'name' => 'test2', - 'value' => '5678', - 'private' => true - ], - [ - 'name' => 'test3', - 'value' => '56789', - 'private' => true - ] - ] - ]; - - public function tearDown() - { - $this->deleteUser(1); - $this->deleteUser(2); - $this->deleteUser(3); - - parent::tearDown(); - } - - /************************************************ - * Testing POST - ************************************************/ - public function testPOSTCreateAdmins() - { - $payload = json_encode([$this->user1, $this->user2], JSON_UNESCAPED_SLASHES); - - $rs = - $this->makeRequest(Verbs::POST, static::RESOURCE, - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], - $payload); - $content = $rs->getContent(); - $data = Arr::get($content, static::$wrapper); - - $this->assertEquals(Arr::get($this->user1, 'email'), Arr::get($data, '0.email')); - $this->assertEquals(Arr::get($this->user2, 'email'), Arr::get($data, '1.email')); - $this->assertEquals(0, count(Arr::get($data, '0.lookup_by_user_id'))); - $this->assertEquals(2, count(Arr::get($data, '1.lookup_by_user_id'))); - $this->assertTrue($this->adminCheck($data)); - } - - public function testPOSTCreateAdmin() - { - $payload = json_encode([$this->user3], JSON_UNESCAPED_SLASHES); - - $rs = $this->makeRequest( - Verbs::POST, - static::RESOURCE, - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], - $payload - ); - $data = $rs->getContent(); - - $this->assertEquals(Arr::get($this->user3, 'email'), Arr::get($data, static::$wrapper . '.0.email')); - $this->assertEquals(3, count(Arr::get($data, static::$wrapper . '.0.lookup_by_user_id'))); - $this->assertEquals('**********', Arr::get($data, static::$wrapper . '.0.lookup_by_user_id.1.value')); - $this->assertEquals('**********', Arr::get($data, static::$wrapper . '.0.lookup_by_user_id.2.value')); - $this->assertTrue($this->adminCheck($data)); - } - - /************************************************ - * Testing PATCH - ************************************************/ - - public function testPATCHById() - { - $user = $this->createUser(1); - - $data = [ - 'name' => 'Julie Doe', - 'first_name' => 'Julie', - 'lookup_by_user_id' => [ - [ - 'name' => 'param1', - 'value' => '1234' - ] - ] - ]; - - $payload = json_encode($data, JSON_UNESCAPED_SLASHES); - - $rs = - $this->makeRequest(Verbs::PATCH, static::RESOURCE . '/' . $user['id'], - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], $payload); - $content = $rs->getContent(); - - $this->assertEquals('Julie Doe', $content['name']); - $this->assertEquals('Julie', $content['first_name']); - $this->assertEquals('param1', Arr::get($content, 'lookup_by_user_id.0.name')); - $this->assertEquals('1234', Arr::get($content, 'lookup_by_user_id.0.value')); - - Arr::set($content, 'lookup_by_user_id.0.name', 'my_param'); - Arr::set($content, 'lookup_by_user_id.1', ['name' => 'param2', 'value' => 'secret', 'private' => true]); - - $rs = $this->makeRequest( - Verbs::PATCH, - static::RESOURCE . '/' . $user['id'], - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], - json_encode($content, JSON_UNESCAPED_SLASHES) - ); - - $content = $rs->getContent(); - - $this->assertEquals('my_param', Arr::get($content, 'lookup_by_user_id.0.name')); - $this->assertEquals('**********', Arr::get($content, 'lookup_by_user_id.1.value')); - $this->assertEquals(1, Arr::get($content, 'lookup_by_user_id.1.private')); - $this->assertTrue($this->adminCheck([$content])); - } - - public function testPATCHByIds() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - $payload = json_encode( - [ - [ - 'is_active' => false, - 'lookup_by_user_id' => [ - [ - 'name' => 'common', - 'value' => 'common name' - ] - ] - ] - ], - JSON_UNESCAPED_SLASHES - ); - - $ids = implode(',', array_column([$user1, $user2, $user3], 'id')); - $rs = - $this->makeRequest(Verbs::PATCH, static::RESOURCE, - [ApiOptions::IDS => $ids, ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], - $payload); - $content = $rs->getContent(); - $data = $content[static::$wrapper]; - - foreach ($data as $user) { - $this->assertEquals(0, $user['is_active']); - } - - $this->assertEquals('common name', Arr::get($data, '0.lookup_by_user_id.0.value')); - $this->assertEquals('common name', Arr::get($data, '1.lookup_by_user_id.2.value')); - $this->assertEquals('common name', Arr::get($data, '2.lookup_by_user_id.3.value')); - $this->assertTrue($this->adminCheck($data)); - } - - public function testPATCHByRecords() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - Arr::set($user1, 'first_name', 'Kevin'); - Arr::set($user2, 'first_name', 'Lloyed'); - Arr::set($user3, 'first_name', 'Jack'); - - $payload = json_encode([$user1, $user2, $user3], JSON_UNESCAPED_SLASHES); - - $rs = - $this->makeRequest(Verbs::PATCH, static::RESOURCE, - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], - $payload); - $content = $rs->getContent(); - - $this->assertEquals($user1['first_name'], Arr::get($content, static::$wrapper . '.0.first_name')); - $this->assertEquals($user2['first_name'], Arr::get($content, static::$wrapper . '.1.first_name')); - $this->assertEquals($user3['first_name'], Arr::get($content, static::$wrapper . '.2.first_name')); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - } - - public function testPATCHPassword() - { - $user = $this->createUser(1); - - Arr::set($user, 'password', '123456'); - - $payload = json_encode($user, JSON_UNESCAPED_SLASHES); - $rs = $this->makeRequest(Verbs::PATCH, static::RESOURCE . '/' . $user['id'], [], $payload); - $content = $rs->getContent(); - - $this->assertTrue(Session::authenticate(['email' => $user['email'], 'password' => '123456'])); - $this->assertTrue($this->adminCheck([$content])); - } - - public function testPATCHSecurityAnswer() - { - $user = $this->createUser(1); - - Arr::set($user, 'security_answer', 'mazda'); - - $payload = json_encode($user, JSON_UNESCAPED_SLASHES); - $rs = - $this->makeRequest(Verbs::PATCH, static::RESOURCE . '/' . $user['id'], - [ApiOptions::FIELDS => 'id,security_answer'], - $payload); - $content = User::find($user['id']); - - $this->assertTrue($this->adminCheck([$content->toArray()])); - $this->assertTrue(Hash::check('mazda', $content->security_answer)); - } - - /************************************************ - * Testing GET - ************************************************/ - - public function testGET() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE); - $content = $rs->getContent(); - - //Total 4 users including the default admin user that was seeded by the seeder. - $this->assertEquals(4, count($content[static::$wrapper])); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - - $ids = implode(',', array_column($content[static::$wrapper], 'id')); - $this->assertEquals(implode(',', array_column([['id' => 1], $user1, $user2, $user3], 'id')), $ids); - } - - public function testGETById() - { - $user = $this->createUser(2); - - $rs = $this->makeRequest( - Verbs::GET, - static::RESOURCE . '/' . $user['id'], - [ApiOptions::RELATED => 'lookup_by_user_id'] - ); - $data = $rs->getContent(); - - $this->assertEquals($user['name'], $data['name']); - $this->assertTrue($this->adminCheck([$data])); - - $this->assertTrue($this->adminCheck([$data])); - $this->assertEquals(count($user['lookup_by_user_id']), count($data['lookup_by_user_id'])); - } - - public function testGETByIds() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - $ids = implode(',', array_column([$user1, $user2, $user3], 'id')); - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [ApiOptions::IDS => $ids]); - $content = $rs->getContent(); - - //Total 4 users including the default admin user that was seeded by the seeder. - $this->assertEquals(3, count($content[static::$wrapper])); - - $idsOut = implode(',', array_column($content[static::$wrapper], 'id')); - $this->assertEquals($ids, $idsOut); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - } - - public function testGETByRecord() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - $payload = json_encode([$user1, $user2, $user3], JSON_UNESCAPED_SLASHES); - - $ids = implode(',', array_column([$user1, $user2, $user3], 'id')); - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [], $payload); - $content = $rs->getContent(); - - //Total 4 users including the default admin user that was seeded by the seeder. - $this->assertEquals(3, count($content[static::$wrapper])); - - $idsOut = implode(',', array_column($content[static::$wrapper], 'id')); - $this->assertEquals($ids, $idsOut); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - } - - public function testGETByFilterFirstNameLastName() - { - $this->createUser(1); - $this->createUser(2); - $this->createUser(3); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [ApiOptions::FILTER => "first_name='Dan'"]); - $content = $rs->getContent(); - $data = $content[static::$wrapper]; - $firstNames = array_column($data, 'first_name'); - - $this->assertTrue(in_array('Dan', $firstNames)); - $this->assertEquals(1, count($data)); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [ApiOptions::FILTER => "last_name='doe'"]); - $content = $rs->getContent(); - $data = $content[static::$wrapper]; - $firstNames = array_column($data, 'first_name'); - $lastNames = array_column($data, 'last_name'); - - $this->assertTrue(in_array('Dan', $firstNames)); - $this->assertTrue(in_array('Doe', $lastNames)); - $this->assertEquals(3, count($data)); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - } - - public function testGETWithLimitOffset() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [ApiOptions::LIMIT => 3]); - $content = $rs->getContent(); - - $this->assertEquals(3, count($content[static::$wrapper])); - - $idsOut = implode(',', array_column($content[static::$wrapper], 'id')); - $this->assertEquals(implode(',', array_column([['id' => 1], $user1, $user2], 'id')), $idsOut); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [ApiOptions::LIMIT => 3, ApiOptions::OFFSET => 1]); - $content = $rs->getContent(); - - $this->assertEquals(3, count($content[static::$wrapper])); - - $idsOut = implode(',', array_column($content[static::$wrapper], 'id')); - $this->assertEquals(implode(',', array_column([$user1, $user2, $user3], 'id')), $idsOut); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE, [ApiOptions::LIMIT => 2, ApiOptions::OFFSET => 2]); - $content = $rs->getContent(); - - $this->assertEquals(2, count($content[static::$wrapper])); - - $idsOut = implode(',', array_column($content[static::$wrapper], 'id')); - $this->assertEquals(implode(',', array_column([$user2, $user3], 'id')), $idsOut); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - } - - public function testGETWithOrder() - { - $user1 = $this->createUser(1); - $user2 = $this->createUser(2); - $user3 = $this->createUser(3); - - $ids = implode(',', array_column([$user1, $user2, $user3], 'id')); - $rs = - $this->makeRequest(Verbs::GET, static::RESOURCE, - [ApiOptions::IDS => $ids, ApiOptions::ORDER => 'first_name']); - $content = $rs->getContent(); - $data = $content[static::$wrapper]; - $firstNames = implode(',', array_column($data, 'first_name')); - - $this->assertEquals('Dan,Jane,John', $firstNames); - - $rs = - $this->makeRequest(Verbs::GET, static::RESOURCE, - [ApiOptions::IDS => $ids, ApiOptions::ORDER => 'first_name DESC']); - $content = $rs->getContent(); - $data = $content[static::$wrapper]; - $firstNames = implode(',', array_column($data, 'first_name')); - - $this->assertEquals('John,Jane,Dan', $firstNames); - - $rs = - $this->makeRequest(Verbs::GET, static::RESOURCE, - [ApiOptions::IDS => $ids, ApiOptions::ORDER => 'last_name,first_name DESC']); - $content = $rs->getContent(); - $data = $content[static::$wrapper]; - $firstNames = implode(',', array_column($data, 'first_name')); - - $this->assertEquals('John,Jane,Dan', $firstNames); - $this->assertTrue($this->adminCheck($content[static::$wrapper])); - } - - /************************************************ - * Helper methods - ************************************************/ - - protected function createUser($num) - { - $user = $this->{'user' . $num}; - $payload = json_encode([$user], JSON_UNESCAPED_SLASHES); - $rs = $this->makeRequest( - Verbs::POST, - static::RESOURCE, - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], - $payload - ); - - $data = $rs->getContent(); - - return Arr::get($data, static::$wrapper . '.0'); - } - - protected function deleteUser($num) - { - $user = $this->{'user' . $num}; - $email = Arr::get($user, 'email'); - User::whereEmail($email)->delete(); - } - - protected function adminCheck($records) - { - return false; - } -} \ No newline at end of file diff --git a/tests/AdminResourceTest.php b/tests/AdminResourceTest.php deleted file mode 100644 index 097d334f..00000000 --- a/tests/AdminResourceTest.php +++ /dev/null @@ -1,235 +0,0 @@ -is_sys_admin) { - return false; - } - } - - return true; - } - - public function testNonAdmin() - { - $user = $this->user1; - $this->makeRequest(Verbs::POST, 'user', [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], [$user]); - - //Using a new instance here. Prev instance is set for user resource. - $this->service = ServiceManager::getService('system'); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE); - $content = $rs->getContent(); - - $this->assertEquals(1, count($content[static::$wrapper])); - $this->assertNotEquals($this->user1['name'], Arr::get($content, static::$wrapper . '.0.name')); - } - - /************************************************ - * Session sub-resource test - ************************************************/ - - public function testSessionNotFound() - { - /** @var \DreamFactory\Core\Contracts\ServiceResponseInterface $rs */ - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE . '/session'); - $this->assertEquals('404', $rs->getStatusCode(), 'Testing session not found'); - } - - public function testUnauthorizedSessionRequest() - { - $user = $this->user1; - $this->makeRequest(Verbs::POST, 'user', [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'lookup_by_user_id'], [$user]); - - Session::authenticate(['email' => $user['email'], 'password' => $user['password']]); - - //Using a new instance here. Prev instance is set for user resource. - $this->service = ServiceManager::getService('system'); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE . '/session'); - $this->assertEquals('401', $rs->getStatusCode(), 'Testing unauthorized session request'); - } - - public function testLogin() - { - $user = $this->createUser(1); - - $payload = ['email' => $user['email'], 'password' => $this->user1['password']]; - - $rs = $this->makeRequest(Verbs::POST, static::RESOURCE . '/session', [], $payload); - $content = $rs->getContent(); - $token = $content['session_token']; - $tokenMap = DB::table('token_map')->where('token', $token)->get()->all(); - - $this->assertEquals($user['first_name'], $content['first_name']); - $this->assertTrue(!empty($token)); - $this->assertTrue(!empty($tokenMap)); - } - - public function testSessionBadPatchRequest() - { - $user = $this->createUser(1); - $payload = ['name' => 'foo']; - - $rs = $this->makeRequest(Verbs::PATCH, static::RESOURCE . '/session/' . $user['id'], [], $payload); - $this->assertEquals('400', $rs->getStatusCode(), 'Testing bad session patch request.'); - } - - public function testLogout() - { - $user = $this->createUser(1); - $payload = ['email' => $user['email'], 'password' => $this->user1['password']]; - $rs = $this->makeRequest(Verbs::POST, static::RESOURCE . '/session', [], $payload); - $content = $rs->getContent(); - $token = $content['session_token']; - $tokenMap = DB::table('token_map')->where('token', $token)->get()->all(); - $this->assertTrue(!empty($token)); - $this->assertTrue(!empty($tokenMap)); - - $rs = $this->makeRequest(Verbs::DELETE, static::RESOURCE . '/session', ['session_token' => $token]); - $content = $rs->getContent(); - $tokenMap = DB::table('token_map')->where('token', $token)->get()->all(); - $this->assertTrue($content['success']); - $this->assertTrue(empty($tokenMap)); - - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE . '/session'); - $this->assertEquals('404', $rs->getStatusCode(), 'Testing logout'); - } - - /************************************************ - * Password sub-resource test - ************************************************/ - - public function testGET() - { - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE . '/password'); - $this->assertEquals('400', $rs->getStatusCode(), 'Testing GET admin/password'); - } - - public function testDELETE() - { - $rs = $this->makeRequest(Verbs::DELETE, static::RESOURCE . '/password'); - $this->assertEquals('400', $rs->getStatusCode(), 'Testing DELETE admin/password'); - } - - public function testPasswordChange() - { - $user = $this->createUser(1); - - $this->makeRequest( - Verbs::POST, - static::RESOURCE . '/session', - [], - ['email' => $user['email'], 'password' => $this->user1['password']] - ); - $rs = $this->makeRequest( - Verbs::POST, - static::RESOURCE . '/password', - [], - ['old_password' => $this->user1['password'], 'new_password' => '123456'] - ); - $content = $rs->getContent(); - $this->assertTrue($content['success']); - - $this->makeRequest(Verbs::DELETE, static::RESOURCE . '/session'); - - $rs = $this->makeRequest( - Verbs::POST, - static::RESOURCE . '/session', - [], - ['email' => $user['email'], 'password' => '123456'] - ); - $content = $rs->getContent(); - $token = $content['session_token']; - $tokenMap = DB::table('token_map')->where('token', $token)->get()->all(); - $this->assertTrue(!empty($token)); - $this->assertTrue(!empty($tokenMap)); - } - - public function testPasswordResetUsingSecurityQuestion() - { - $user = $this->createUser(1); - - $rs = - $this->makeRequest(Verbs::POST, static::RESOURCE . '/password', ['reset' => 'true'], - ['email' => $user['email']]); - $content = $rs->getContent(); - - $this->assertEquals($this->user1['security_question'], $content['security_question']); - - $rs = $this->makeRequest( - Verbs::POST, - static::RESOURCE . '/password', - [], - ['email' => $user['email'], - 'security_answer' => $this->user1['security_answer'], - 'new_password' => '778877' - ] - ); - $content = $rs->getContent(); - $this->assertTrue($content['success']); - - $rs = - $this->makeRequest(Verbs::POST, static::RESOURCE . '/session', [], - ['email' => $user['email'], 'password' => '778877']); - $content = $rs->getContent(); - $token = $content['session_token']; - $tokenMap = DB::table('token_map')->where('token', $token)->get()->all(); - $this->assertTrue(!empty($token)); - $this->assertTrue(!empty($tokenMap)); - } - - public function testPasswordResetUsingConfirmationCode() - { - Arr::set($this->user2, 'email', 'arif@dreamfactory.com'); - $user = $this->createUser(2); - - Config::set('mail.driver', 'array'); - $rs = - $this->makeRequest(Verbs::POST, static::RESOURCE . '/password', ['reset' => 'true'], - ['email' => $user['email']]); - $content = $rs->getContent(); - $this->assertTrue($content['success']); - - /** @var User $userModel */ - $userModel = User::find($user['id']); - $code = $userModel->confirm_code; - - $rs = $this->makeRequest( - Verbs::POST, - static::RESOURCE . '/password', - ['login' => 'true'], - ['email' => $user['email'], 'code' => $code, 'new_password' => '778877'] - ); - $content = $rs->getContent(); - $this->assertTrue($content['success']); - $this->assertTrue(\DreamFactory\Core\Utility\Session::isAuthenticated()); - - $userModel = User::find($user['id']); - $this->assertEquals('y', $userModel->confirm_code); - - $rs = $this->makeRequest(Verbs::POST, static::RESOURCE . '/session', [], - ['email' => $user['email'], 'password' => '778877']); - $content = $rs->getContent(); - $token = $content['session_token']; - $tokenMap = DB::table('token_map')->where('token', $token)->get()->all(); - $this->assertTrue(!empty($token)); - $this->assertTrue(!empty($tokenMap)); - } -} \ No newline at end of file diff --git a/tests/RoleResourceTest.php b/tests/RoleResourceTest.php deleted file mode 100644 index c6015a35..00000000 --- a/tests/RoleResourceTest.php +++ /dev/null @@ -1,324 +0,0 @@ - 'Test role 1', - 'description' => 'A test role', - 'is_active' => true, - 'role_service_access_by_role_id' => [ - [ - 'service_id' => 2, - 'component' => '*', - 'verb_mask' => 31, - 'requestor_mask' => 3 - ] - ], - 'lookup_by_role_id' => [ - [ - 'name' => 'test1_1', - 'value' => '1231', - 'private' => false - ], - [ - 'name' => 'test2_1', - 'value' => '12341', - 'private' => true - ] - ] - - ]; - - protected $role2 = [ - 'name' => 'Test role 2', - 'description' => 'A test role', - 'is_active' => true, - 'role_service_access_by_role_id' => [ - [ - 'service_id' => 2, - 'component' => '*', - 'verb_mask' => 31, - 'requestor_mask' => 3 - ] - ], - 'lookup_by_role_id' => [ - [ - 'name' => 'test1_2', - 'value' => '1232', - 'private' => false - ], - [ - 'name' => 'test2_2', - 'value' => '12342', - 'private' => true - ] - ] - ]; - - protected $role3 = [ - 'name' => 'Test role 3', - 'description' => 'A test role', - 'is_active' => true, - 'role_service_access_by_role_id' => [ - [ - 'service_id' => 2, - 'component' => '*', - 'verb_mask' => 31, - 'requestor_mask' => 3 - ] - ], - 'lookup_by_role_id' => [ - [ - 'name' => 'test1_3', - 'value' => '1233', - 'private' => false - ], - [ - 'name' => 'test2_3', - 'value' => '12343', - 'private' => true - ] - ] - ]; - - protected static $roleIds = []; - - protected $serviceId = 'system'; - - public function testPOSTCreateRoles() - { - /** @var ServiceResponseInterface $response */ - $response = $this->makeRequest(Verbs::POST, self::RESOURCE, [], [$this->role1, $this->role2]); - $content = $response->getContent(); - - $this->assertTrue(isset($content[static::$wrapper])); - - $records = array_get($content, static::$wrapper); - - static::$roleIds = []; - - foreach ($records as $r) { - $this->assertTrue(array_get($r, 'id') > 0); - static::$roleIds[] = array_get($r, 'id'); - } - - $this->assertEquals(HttpStatusCodes::HTTP_CREATED, $response->getStatusCode()); - } - - public function testPOSTCreateRolesWithFieldsAndRelated() - { - $response = $this->makeRequest( - Verbs::POST, - self::RESOURCE, - [ApiOptions::FIELDS => 'name,id', ApiOptions::RELATED => 'lookup_by_role_id'], - [$this->role3] - ); - $content = $response->getContent(); - - static::$roleIds[] = Arr::get($content, static::$wrapper . '.0.id'); - - $this->assertEquals(array_get($this->role3, 'name'), Arr::get($content, static::$wrapper . '.0.name')); - $this->assertEquals( - Arr::get($this->role3, 'lookup_by_role_id.0.name'), - Arr::get($content, static::$wrapper . '.0.lookup_by_role_id.0.name') - ); - } - - public function testPATCHRole() - { - $role1 = $this->getRole(static::$roleIds[0]); - - $role1['name'] = 'Patched Test Role 1'; - $role1['role_service_access_by_role_id'][0]['component'] = 'test'; - $role1['lookup_by_role_id'][0]['name'] = 'patched-test1_1'; - $role1['lookup_by_role_id'][0]['value'] = '897'; - - $rs = $this->makeRequest(Verbs::PATCH, self::RESOURCE, [], [$role1]); - $c = $rs->getContent(); - - $this->assertTrue(Arr::get($c, static::$wrapper . '.0.id') === static::$roleIds[0]); - - $updatedRole = $this->getRole(static::$roleIds[0]); - - $this->assertEquals('Patched Test Role 1', $updatedRole['name']); - $this->assertEquals('test', $updatedRole['role_service_access_by_role_id'][0]['component']); - $this->assertEquals('patched-test1_1', $updatedRole['lookup_by_role_id'][0]['name']); - $this->assertEquals('897', $updatedRole['lookup_by_role_id'][0]['value']); - } - - public function testPATCHRoleWithFieldsAndRelated() - { - $role1 = $this->getRole(static::$roleIds[0]); - - $role1['name'] = 'Patched Test Role 1_2'; - $role1['role_service_access_by_role_id'][0]['component'] = 'test_2'; - $role1['lookup_by_role_id'][0]['name'] = 'patched-test1_1_2'; - $role1['lookup_by_role_id'][0]['value'] = '900'; - - $rs = $this->makeRequest( - Verbs::PATCH, - self::RESOURCE, - [ApiOptions::FIELDS => 'id,name,is_active', ApiOptions::RELATED => 'role_service_access_by_role_id,lookup_by_role_id'], - [$role1] - ); - - $c = $rs->getContent(); - $c = $c[static::$wrapper][0]; - - $this->assertTrue(array_get($c, 'id') === static::$roleIds[0]); - - $updatedRole = $c; - - $this->assertEquals('Patched Test Role 1_2', $updatedRole['name']); - $this->assertEquals('test_2', $updatedRole['role_service_access_by_role_id'][0]['component']); - $this->assertEquals('patched-test1_1_2', $updatedRole['lookup_by_role_id'][0]['name']); - $this->assertEquals('900', $updatedRole['lookup_by_role_id'][0]['value']); - } - - public function testPATCHCreateRelation() - { - $role2 = $this->getRole(static::$roleIds[1]); - - unset($role2['lookup_by_role_id'][0]['id']); - - $rs = $this->makeRequest(Verbs::PATCH, self::RESOURCE, [], [$role2]); - $c = $rs->getContent(); - - $this->assertTrue(Arr::get($c, static::$wrapper . '.0.id') === static::$roleIds[1]); - - $updatedRole = $this->getRole(static::$roleIds[1]); - - $this->assertEquals(2, count($updatedRole['lookup_by_role_id'])); - } - - public function testPATCHDeleteRelation() - { - $role2 = $this->getRole(static::$roleIds[1]); - - $role2['lookup_by_role_id'][0]['role_id'] = null; - - $rs = $this->makeRequest(Verbs::PATCH, self::RESOURCE, [], [$role2]); - $c = $rs->getContent(); - - $this->assertTrue(Arr::get($c, static::$wrapper . '.0.id') === static::$roleIds[1]); - - $updatedRole = $this->getRole(static::$roleIds[1]); - - $this->assertEquals(1, count($updatedRole['lookup_by_role_id'])); - } - - public function testPATCHAdoptRelation() - { - $role1 = $this->getRole(static::$roleIds[0]); - $role2 = $this->getRole(static::$roleIds[1]); - - $role2['lookup_by_role_id'][0]['role_id'] = $role1['lookup_by_role_id'][0]['role_id']; - - $rs = $this->makeRequest(Verbs::PATCH, self::RESOURCE, [], [$role2]); - $c = $rs->getContent(); - - $this->assertTrue(Arr::get($c, static::$wrapper . '.0.id') === static::$roleIds[1]); - - $updatedRole = $this->getRole(static::$roleIds[1]); - $otherRole = $this->getRole(static::$roleIds[0]); - - $this->assertEquals(0, count($updatedRole['lookup_by_role_id'])); - $this->assertEquals(3, count($otherRole['lookup_by_role_id'])); - } - - public function testPATCHMultipleRoles() - { - $role1 = $this->getRole(static::$roleIds[0]); - $role2 = $this->getRole(static::$roleIds[1]); - $role3 = $this->getRole(static::$roleIds[2]); - - $role1['name'] = 'test-multiple-update_1'; - $role1['role_service_access_by_role_id'][0]['component'] = 'updated1'; - $role1['lookup_by_role_id'][1]['name'] = 'test-updated-1'; - - $role2['name'] = 'test-multiple-update_2'; - $role2['role_service_access_by_role_id'][0]['component'] = 'updated2'; - $role2['lookup_by_role_id'][0] = $role1['lookup_by_role_id'][1]; - $role2['lookup_by_role_id'][0]['role_id'] = static::$roleIds[1]; - $role2['lookup_by_role_id'][0]['name'] = 'test-updated-2'; - - $role3['name'] = 'test-multiple-update_3'; - $role3['role_service_access_by_role_id'][0]['component'] = 'updated3'; - $role3['lookup_by_role_id'][1]['name'] = 'test-updated-3'; - - $rs = $this->makeRequest( - Verbs::PATCH, - self::RESOURCE, - [ApiOptions::FIELDS => '*', ApiOptions::RELATED => 'role_service_access_by_role_id,lookup_by_role_id'], - [$role1, $role2, $role3] - ); - $c = $rs->getContent(); - $records = array_get($c, static::$wrapper); - - foreach ($records as $key => $record) { - $this->assertEquals(static::$roleIds[$key], array_get($record, 'id')); - } - - $this->assertEquals(Arr::get($role1, 'name'), Arr::get($records, '0.name')); - $this->assertEquals( - Arr::get($role1, 'role_service_access_by_role_id.0.component'), - Arr::get($records, '0.role_service_access_by_role_id.0.component') - ); - $this->assertEquals(Arr::get($role1, 'lookup_by_role_id.1.name'), - Arr::get($records, '0.lookup_by_role_id.1.name')); - - $this->assertEquals(Arr::get($role2, 'name'), Arr::get($records, '1.name')); - $this->assertEquals( - Arr::get($role2, 'role_service_access_by_role_id.0.component'), - Arr::get($records, '1.role_service_access_by_role_id.0.component') - ); - $this->assertEquals(Arr::get($role2, 'lookup_by_role_id.0.name'), - Arr::get($records, '1.lookup_by_role_id.0.name')); - - $this->assertEquals(Arr::get($role3, 'name'), Arr::get($records, '2.name')); - $this->assertEquals( - Arr::get($role3, 'role_service_access_by_role_id.0.component'), - Arr::get($records, '2.role_service_access_by_role_id.0.component') - ); - $this->assertEquals(Arr::get($role3, 'lookup_by_role_id.1.name'), - Arr::get($records, '2.lookup_by_role_id.1.name')); - } - - public function testDELETERoles() - { - $ids = implode(',', static::$roleIds); - $response = $this->makeRequest(Verbs::DELETE, self::RESOURCE, [ApiOptions::IDS => $ids]); - - $content = $response->getContent(); - $records = array_get($content, static::$wrapper); - - foreach ($records as $key => $record) { - $this->assertEquals(static::$roleIds[$key], array_get($record, 'id')); - } - - static::$roleIds = []; - } - - protected function getRole($id = null) - { - if (!empty($id)) { - $resource = self::RESOURCE . '/' . $id; - } else { - $resource = self::RESOURCE; - } - - $getResponse = - $this->makeRequest(Verbs::GET, $resource, - [ApiOptions::RELATED => 'lookup_by_role_id,role_service_access_by_role_id']); - $role = $getResponse->getContent(); - - return $role; - } -} \ No newline at end of file diff --git a/tests/SystemServiceTest.php b/tests/SystemServiceTest.php deleted file mode 100644 index 899caeeb..00000000 --- a/tests/SystemServiceTest.php +++ /dev/null @@ -1,46 +0,0 @@ -makeRequest(Verbs::GET, static::RESOURCE); - $content = $rs->getContent(); - $services = Arr::get($content, static::$wrapper); - - $first = Arr::get($services, '0.name'); - - $this->assertEquals('system', $first); - } - - public function testGETServiceById() - { - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE . '/1'); - $content = $rs->getContent(); - - $this->assertEquals('system', Arr::get($content, 'name')); - } - - public function testGETServiceByIdWithFields() - { - $rs = $this->makeRequest(Verbs::GET, static::RESOURCE . '/1', [ApiOptions::FIELDS => 'name,label,id']); - $content = $rs->getContent(); - - $this->assertEquals('system', Arr::get($content, 'name')); - $this->assertEquals('System Management', Arr::get($content, 'label')); - $this->assertEquals(1, Arr::get($content, 'id')); - $this->assertEquals(3, count($content)); - } -} \ No newline at end of file