Zuul jobs refactoring

* Added new Role to set up the Laravel Test Env
* Fixed broken unit tests
* added php unit run to job openstackid-unittests

Change-Id: Ibfaf44b32bb6a1cdbe0c693af44b024a01dc6adf
This commit is contained in:
smarcet 2020-01-27 21:10:42 -03:00
parent 95b04ac9ae
commit 3fc5056149
35 changed files with 657 additions and 884 deletions

View File

@ -60,6 +60,4 @@ abstract class AsymmetricKeyApiController extends APICRUDController
];
}
}

View File

@ -0,0 +1,18 @@
<?php namespace App\ModelSerializers\OAuth2;
/**
* Copyright 2020 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class ClientPublicKeySerializer extends AsymmetricKeySerializer
{
}

View File

@ -11,7 +11,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\libs\Auth\Models\UserRegistrationRequest;
use App\ModelSerializers\Auth\PrivateUserSerializer;
use App\ModelSerializers\Auth\PublicGroupSerializer;
use App\ModelSerializers\Auth\PublicUserSerializer;
@ -25,20 +24,10 @@ use App\ModelSerializers\OAuth2\ClientSerializer;
use App\ModelSerializers\OAuth2\RefreshTokenSerializer;
use App\ModelSerializers\OAuth2\ResourceServerSerializer;
use App\ModelSerializers\OAuth2\ServerPrivateKeySerializer;
use Auth\Group;
use Auth\User;
use Illuminate\Support\Facades\App;
use Models\OAuth2\AccessToken;
use Models\OAuth2\Api;
use Models\OAuth2\ApiEndpoint;
use Models\OAuth2\ApiScope;
use Models\OAuth2\ApiScopeGroup;
use Models\OAuth2\Client;
use Models\OAuth2\RefreshToken;
use Models\OAuth2\ResourceServer;
use Models\OAuth2\ServerPrivateKey;
use OAuth2\IResourceServerContext;
use ReflectionClass;
use App\ModelSerializers\OAuth2\ClientPublicKeySerializer;
/**
* Class SerializerRegistry
* @package App\ModelSerializers
@ -107,6 +96,7 @@ final class SerializerRegistry
$this->registry["RefreshToken"] = RefreshTokenSerializer::class;
$this->registry["ApiScopeGroup"] = ApiScopeGroupSerializer::class;
$this->registry["ServerPrivateKey"] = ServerPrivateKeySerializer::class;
$this->registry["ClientPublicKey"] = ClientPublicKeySerializer::class;
}
/**

View File

@ -226,9 +226,9 @@ class ApiEndpoint extends BaseEntity {
}
/**
* @return string
* @return string|null
*/
public function getDescription(): string
public function getDescription(): ?string
{
return $this->description;
}

View File

@ -103,6 +103,12 @@ class Client extends BaseEntity implements IClient
*/
private $max_access_token_issuance_basis;
/**
* @ORM\Column(name="max_auth_codes_issuance_basis", type="integer")
* @var int
*/
private $max_auth_codes_issuance_basis;
/**
* @ORM\Column(name="max_refresh_token_issuance_qty", type="integer")
* @var int
@ -375,6 +381,7 @@ class Client extends BaseEntity implements IClient
$this->require_auth_time = false;
$this->default_max_age = 0;
$this->max_auth_codes_issuance_qty = 0;
$this->max_auth_codes_issuance_basis = 0;
$this->max_access_token_issuance_basis = 0;
$this->max_access_token_issuance_qty = 0;
$this->max_refresh_token_issuance_basis = 0;

View File

@ -15,6 +15,8 @@ use Exception;
use Illuminate\Support\Facades\Log;
use jwe\IJWE;
use jwk\exceptions\InvalidJWKAlgorithm;
use jwk\exceptions\JWKInvalidSpecException;
use jws\exceptions\JWSInvalidJWKException;
use jws\IJWS;
use OAuth2\Exceptions\AccessDeniedException;
use OAuth2\Exceptions\ConsentRequiredException;
@ -633,6 +635,14 @@ abstract class InteractiveGrantType extends AbstractGrantType
try {
$this->processUserHint($request);
}
catch (JWSInvalidJWKException $ex){
Log::warning($ex);
throw $ex;
}
catch (JWKInvalidSpecException $ex){
Log::warning($ex);
throw $ex;
}
catch (Exception $ex){
Log::warning($ex);
return true;

View File

@ -47,7 +47,7 @@ final class Version20190729150610 extends AbstractMigration
EntityManager::flush();
ApiScopeSeeder::seedScopes([
\SeedUtils::seedScopes([
[
'name' => IUserScopes::Registration,
'short_description' => 'Allows to request user registrations.',
@ -59,7 +59,7 @@ final class Version20190729150610 extends AbstractMigration
], 'user-registration');
ApiEndpointSeeder::seedApiEndpoints('user-registration', [
\SeedUtils::seedApiEndpoints('user-registration', [
[
'name' => 'request-user-registration',
'active' => true,

View File

@ -25,7 +25,7 @@ class Version20190829142736 extends AbstractMigration
*/
public function up(Schema $schema)
{
\ApiScopeSeeder::seedScopes([
\SeedUtils::seedScopes([
[
'name' => IUserScopes::ReadAll,
'short_description' => 'Allows access to users info',
@ -36,7 +36,7 @@ class Version20190829142736 extends AbstractMigration
],
], 'users');
\ApiEndpointSeeder::seedApiEndpoints('users', [
\SeedUtils::seedApiEndpoints('users', [
// get users
[
'name' => 'get-users',

View File

@ -11,11 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Models\OAuth2\Api;
use Models\OAuth2\ApiEndpoint;
use Models\OAuth2\ApiScope;
use Illuminate\Database\Seeder;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Illuminate\Support\Facades\DB;
/**
* Class ApiEndpointSeeder
@ -32,41 +28,10 @@ class ApiEndpointSeeder extends Seeder
$this->seedRegistrationEndpoints();
}
/**
* @param string $api_name
* @param array $endpoints_info
*/
public static function seedApiEndpoints($api_name, array $endpoints_info){
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => $api_name]);
if(is_null($api)) return;
foreach($endpoints_info as $endpoint_info){
$endpoint = new ApiEndpoint();
$endpoint->setName($endpoint_info['name']);
$endpoint->setRoute($endpoint_info['route']);
$endpoint->setHttpMethod($endpoint_info['http_method']);
$endpoint->setStatus(true);
$endpoint->setAllowCors(true);
$endpoint->setAllowCredentials(true);
$endpoint->setApi($api);
foreach($endpoint_info['scopes'] as $scope_name){
$scope = EntityManager::getRepository(ApiScope::class)->findOneBy(['name' => $scope_name]);
if(is_null($scope)) continue;
$endpoint->addScope($scope);
}
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
private function seedUsersEndpoints()
{
self::seedApiEndpoints('users', [
SeedUtils::seedApiEndpoints('users', [
// get user info
[
'name' => 'get-user-info',
@ -114,7 +79,7 @@ class ApiEndpointSeeder extends Seeder
}
private function seedRegistrationEndpoints(){
self::seedApiEndpoints('user-registration', [
SeedUtils::seedApiEndpoints('user-registration', [
[
'name' => 'request-user-registration',
'active' => true,
@ -124,7 +89,6 @@ class ApiEndpointSeeder extends Seeder
\App\libs\OAuth2\IUserScopes::Registration
],
],
]);
}

View File

@ -32,38 +32,10 @@ class ApiScopeSeeder extends Seeder {
$this->seedRegistrationScopes();
}
public static function seedScopes(array $scopes_definitions, string $api_name = null){
$api = null;
if(!is_null($api_name))
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => $api_name]);
foreach ($scopes_definitions as $scope_info) {
$scope = new ApiScope();
$scope->setName($scope_info['name']);
$scope->setShortDescription($scope_info['short_description']);
$scope->setDescription($scope_info['description']);
$scope->setActive(true);
if(isset($scope_info['system']))
$scope->setSystem($scope_info['system']);
if(isset($scope_info['default']))
$scope->setDefault($scope_info['default']);
if(isset($scope_info['groups']))
$scope->setAssignedByGroups($scope_info['groups']);
if(!is_null($api))
$scope->setApi($api);
EntityManager::persist($scope);
}
EntityManager::flush();
}
private function seedUsersScopes(){
self::seedScopes([
SeedUtils::seedScopes([
[
'name' => IUserScopes::Profile,
'short_description' => 'Allows access to your profile info.',
@ -95,7 +67,7 @@ class ApiScopeSeeder extends Seeder {
]
], 'users');
self::seedScopes(
SeedUtils::seedScopes(
[
[
'name' => OAuth2Protocol::OpenIdConnect_Scope,
@ -116,7 +88,7 @@ class ApiScopeSeeder extends Seeder {
}
private function seedRegistrationScopes(){
self::seedScopes([
SeedUtils::seedScopes([
[
'name' => IUserScopes::Registration,
'short_description' => 'Allows to request user registrations.',

View File

@ -11,14 +11,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Models\OpenId\ServerExtension;
use Illuminate\Database\Seeder;
use OpenId\Extensions\Implementations\OpenIdAXExtension;
use OpenId\Extensions\Implementations\OpenIdSREGExtension;
use OpenId\Extensions\Implementations\OpenIdOAuth2Extension;
use OpenId\Extensions\Implementations\OpenIdSREGExtension_1_0;
use Illuminate\Support\Facades\DB;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class OpenIdExtensionsSeeder
*/
@ -64,23 +62,10 @@ class OpenIdExtensionsSeeder extends Seeder {
];
foreach ($extensions as $extension){
self::createServerExtension($extension);
SeedUtils::createServerExtension($extension);
}
}
public static function createServerExtension(array $payload){
$ext = new ServerExtension();
$ext->setName(trim($payload['name']));
$ext->setNamespace(trim($payload['namespace']));
$ext->setActive(boolval($payload['active']));
$ext->setExtensionClass(trim($payload['extension_class']));
$ext->setDescription(trim($payload['description']));
$ext->setViewName(trim($payload['view_name']));
EntityManager::persist($ext);
EntityManager::flush();
}
}

View File

@ -0,0 +1,103 @@
<?php
/**
* Copyright 2020 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Models\OpenId\ServerExtension;
use Models\OAuth2\ApiEndpoint;
use Models\OAuth2\ApiScope;
use Models\OAuth2\Api;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class SeedUtils
*/
final class SeedUtils
{
/**
* @param string $api_name
* @param array $endpoints_info
*/
public static function seedApiEndpoints($api_name, array $endpoints_info){
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => $api_name]);
if(is_null($api)) return;
foreach($endpoints_info as $endpoint_info){
$endpoint = new ApiEndpoint();
$endpoint->setName($endpoint_info['name']);
$endpoint->setRoute($endpoint_info['route']);
$endpoint->setHttpMethod($endpoint_info['http_method']);
$endpoint->setStatus(true);
$endpoint->setAllowCors(true);
$endpoint->setAllowCredentials(true);
$endpoint->setApi($api);
foreach($endpoint_info['scopes'] as $scope_name){
$scope = EntityManager::getRepository(ApiScope::class)->findOneBy(['name' => $scope_name]);
if(is_null($scope)) continue;
$endpoint->addScope($scope);
}
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
/**
* @param array $scopes_definitions
* @param string|null $api_name
*/
public static function seedScopes(array $scopes_definitions, string $api_name = null){
$api = null;
if(!is_null($api_name))
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => $api_name]);
foreach ($scopes_definitions as $scope_info) {
$scope = new ApiScope();
$scope->setName($scope_info['name']);
$scope->setShortDescription($scope_info['short_description']);
$scope->setDescription($scope_info['description']);
$scope->setActive(true);
if(isset($scope_info['system']))
$scope->setSystem($scope_info['system']);
if(isset($scope_info['default']))
$scope->setDefault($scope_info['default']);
if(isset($scope_info['groups']))
$scope->setAssignedByGroups($scope_info['groups']);
if(!is_null($api))
$scope->setApi($api);
EntityManager::persist($scope);
}
EntityManager::flush();
}
public static function createServerExtension(array $payload){
$ext = new ServerExtension();
$ext->setName(trim($payload['name']));
$ext->setNamespace(trim($payload['namespace']));
$ext->setActive(boolval($payload['active']));
$ext->setExtensionClass(trim($payload['extension_class']));
$ext->setDescription(trim($payload['description']));
$ext->setViewName(trim($payload['view_name']));
EntityManager::persist($ext);
EntityManager::flush();
}
}

View File

@ -229,11 +229,11 @@ PPK;
private function createTestUsers(){
$group_repository = EntityManager::getRepository(Group::class);
$oauth2_admin_group = $group_repository->findOneBy(['slug' => IOAuth2User::OAuth2ServerAdminGroup]);
$opendid_admin_group = $group_repository->findOneBy(['slug' => IOpenIdUser::OpenIdServerAdminGroup,]);
$oauth2_admin_group = $group_repository->findOneBy(['slug' => IOAuth2User::OAuth2ServerAdminGroup]);
$opendid_admin_group = $group_repository->findOneBy(['slug' => IOpenIdUser::OpenIdServerAdminGroup,]);
$system_scopes_admin_group = $group_repository->findOneBy(['slug' => IOAuth2User::OAuth2SystemScopeAdminGroup]);
$super_admin_group = $group_repository->findOneBy(['slug' => IGroupSlugs::SuperAdminGroup]);
$raw_users_group = $group_repository->findOneBy(['slug' => IGroupSlugs::RawUsersGroup]);
$super_admin_group = $group_repository->findOneBy(['slug' => IGroupSlugs::SuperAdminGroup]);
$raw_users_group = $group_repository->findOneBy(['slug' => IGroupSlugs::RawUsersGroup]);
$user_payloads = [
[
@ -254,7 +254,113 @@ PPK;
'email_verified' => true,
'groups' => [
$super_admin_group
]
],
'identifier' => '1',
],
[
'first_name' => 'Márton',
'last_name' => 'Kiss',
'email' => 'mkiss@tipit.net',
'password' => '1qaz2wsx',
'password_enc' => \Auth\AuthHelper::AlgSHA1_V2_4,
'gender' => 'male',
'address1' => 'Av. Siempre Viva 111',
'address2' => 'Av. Siempre Viva 111',
'city' => 'Lanus Este',
'state' => 'Buenos Aires',
'post_code' => '1824',
'country' => 'AR',
'language' => 'ESP',
'active' => true,
'email_verified' => true,
'groups' => [
$super_admin_group
],
'identifier' => '2',
],
[
'first_name' => '付',
'last_name' => '金刚',
'email' => 'fujg573@tipit.net',
'password' => '1qaz2wsx',
'password_enc' => \Auth\AuthHelper::AlgSHA1_V2_4,
'gender' => 'male',
'address1' => 'Av. Siempre Viva 111',
'address2' => 'Av. Siempre Viva 111',
'city' => 'Lanus Este',
'state' => 'Buenos Aires',
'post_code' => '1824',
'country' => 'AR',
'language' => 'ESP',
'active' => true,
'email_verified' => true,
'groups' => [
$super_admin_group
],
'identifier' => '3',
],
[
'first_name' => 'Bharath',
'last_name' => 'Kumar M R',
'email' => 'mrbharathee@tipit.net',
'password' => '1qaz2wsx',
'password_enc' => \Auth\AuthHelper::AlgSHA1_V2_4,
'gender' => 'male',
'address1' => 'Av. Siempre Viva 111',
'address2' => 'Av. Siempre Viva 111',
'city' => 'Lanus Este',
'state' => 'Buenos Aires',
'post_code' => '1824',
'country' => 'AR',
'language' => 'ESP',
'active' => true,
'email_verified' => true,
'groups' => [
$super_admin_group
],
'identifier' => '4',
],
[
'first_name' => '大塚',
'last_name' => '元央',
'email' => 'yuanying@tipit.net',
'password' => '1qaz2wsx',
'password_enc' => \Auth\AuthHelper::AlgSHA1_V2_4,
'gender' => 'male',
'address1' => 'Av. Siempre Viva 111',
'address2' => 'Av. Siempre Viva 111',
'city' => 'Lanus Este',
'state' => 'Buenos Aires',
'post_code' => '1824',
'country' => 'AR',
'language' => 'ESP',
'active' => true,
'email_verified' => true,
'groups' => [
$super_admin_group
],
'identifier' => '5',
],
[
'first_name' => 'Ian Y.',
'last_name' => 'Choi',
'email' => 'ianyrchoi@gmail.com',
'password' => '1qaz2wsx',
'password_enc' => \Auth\AuthHelper::AlgSHA1_V2_4,
'gender' => 'male',
'address1' => 'Av. Siempre Viva 111',
'address2' => 'Av. Siempre Viva 111',
'city' => 'Lanus Este',
'state' => 'Buenos Aires',
'post_code' => '1824',
'country' => 'AR',
'language' => 'ESP',
'active' => true,
'email_verified' => true,
'groups' => [
$super_admin_group
],
'identifier' => '6',
]
];
@ -301,188 +407,6 @@ PPK;
$this->createTestUsers();
/*
$member = Member::find(1);
$member->groups()->attach([1,2,3]);
Member::create(
array(
'ID' => 2,
'FirstName' => 'Sebastian',
'Surname' => 'Marcet',
'Email' => 'sebastian+1@tipit.net',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 3,
'FirstName' => 'Sebastian',
'Surname' => 'Marcet',
'Email' => 'sebastian+2@tipit.net',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 4,
'FirstName' => 'Márton',
'Surname' => 'Kiss',
'Email' => 'mkiss@tipit.net',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 5,
'FirstName' => '付',
'Surname' => '金刚',
'Email' => 'fujg573@tipit.net',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 6,
'FirstName' => 'Bharath',
'Surname' => 'Kumar M R',
'Email' => 'mrbharathee@tipit.com',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 7,
'FirstName' => '大塚',
'Surname' => '元央',
'Email' => 'yuanying@tipit.com',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 8,
'FirstName' => ' Sebastian German ',
'Surname' => 'Marcet Gomez ',
'Email' => 'smarcet@gmail.com',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
Member::create(
array(
'ID' => 9,
'FirstName' => 'Ian Y.',
'Surname' => 'Choi',
'Email' => 'ianyrchoi@gmail.com',
'Password' => '1qaz2wsx',
'PasswordEncryption' => 'none',
'Salt' => 'none',
'Gender' => 'male',
'Address' => 'Av. Siempre Viva 111',
'Suburb' => 'Lanus Este',
'State' => 'Buenos Aires',
'City' => 'Lanus',
'Postcode' => '1824',
'Country' => 'AR',
'Locale' => 'ESP',
'Active' => 1,
'EmailVerified' => 1,
)
);
*/
$this->seedServerConfiguration();
$this->seedServerExtensions();
$this->seedTestResourceServers();
@ -497,19 +421,19 @@ PPK;
$this->seedPublicCloudScopes();
$this->seedPrivateCloudScopes();
$this->seedConsultantScopes();
/*
//endpoints
$this->seedResourceServerEndpoints();
$this->seedApiEndpoints();
$this->seedUsersEndpoints();
$this->seedUserRegistrationEndpoints();
/*
$this->seedApiEndpointEndpoints();
$this->seedScopeEndpoints();
$this->seedPublicCloudsEndpoints();
$this->seedPrivateCloudsEndpoints();
$this->seedConsultantsEndpoints();
*/
$this->seedUsersEndpoints();
$this->seedUserRegistrationEndpoints();
//clients
$this->seedTestUsersAndClients();
}
@ -1559,221 +1483,213 @@ PPK;
private function seedResourceServerEndpoints(){
$current_realm = Config::get('app.url');
$resource_server = Api::where('name','=','resource-server')->first();
ApiEndpoint::create(
SeedUtils::seedApiEndpoints('resource-server', [
array(
'name' => 'create-resource-server',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [
sprintf('%s/resource-server/write', $current_realm)
],
),
array(
'name' => 'get-resource-server',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers/{id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [
sprintf('%s/resource-server/read',$current_realm)
]
),
array(
'name' => 'resource-server-regenerate-secret',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers/{id}/client-secret',
'http_method' => 'PUT'
)
);
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [
sprintf('%s/resource-server/write',$current_realm),
sprintf('%s/resource-server/regenerate.secret',$current_realm)
]
),
array(
'name' => 'resource-server-get-page',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [
sprintf('%s/resource-server/read',$current_realm),
sprintf('%s/resource-server/read.page',$current_realm)
]
),
array(
'name' => 'resource-server-delete',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers/{id}',
'http_method' => 'DELETE'
)
);
ApiEndpoint::create(
'http_method' => 'DELETE',
'scopes' => [
sprintf('%s/resource-server/delete',$current_realm)
]
),
array(
'name' => 'resource-server-update',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers',
'http_method' => 'PUT'
)
);
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [
sprintf('%s/resource-server/write',$current_realm)
]
),
array(
'name' => 'resource-server-update-status',
'active' => true,
'api_id' => $resource_server->id,
'route' => '/api/v1/resource-servers/{id}/status/{active}',
'http_method' => 'PUT'
'http_method' => 'PUT',
'scopes' => [
sprintf('%s/resource-server/write',$current_realm)
]
)
);
//attach scopes to endpoints
//resource server api scopes
$resource_server_read_scope = ApiScope::where('name','=',sprintf('%s/resource-server/read',$current_realm))->first();
$resource_server_write_scope = ApiScope::where('name','=',sprintf('%s/resource-server/write',$current_realm))->first();
$resource_server_read_page_scope = ApiScope::where('name','=',sprintf('%s/resource-server/read.page',$current_realm))->first();
$resource_server_regenerate_secret_scope = ApiScope::where('name','=',sprintf('%s/resource-server/regenerate.secret',$current_realm))->first();
$resource_server_delete_scope = ApiScope::where('name','=',sprintf('%s/resource-server/delete',$current_realm))->first();
$resource_server_update_scope = ApiScope::where('name','=',sprintf('%s/resource-server/update',$current_realm))->first();
$resource_server_update_status_scope = ApiScope::where('name','=',sprintf('%s/resource-server/update.status',$current_realm))->first();
// create needs write access
$resource_server_api_create = ApiEndpoint::where('name','=','create-resource-server')->first();
$resource_server_api_create->scopes()->attach($resource_server_write_scope->id);
//get needs read access
$resource_server_api_get = ApiEndpoint::where('name','=','get-resource-server')->first();
$resource_server_api_get->scopes()->attach($resource_server_read_scope->id);
// get page needs read access or read page access
$resource_server_api_get_page = ApiEndpoint::where('name','=','resource-server-get-page')->first();
$resource_server_api_get_page->scopes()->attach($resource_server_read_scope->id);
$resource_server_api_get_page->scopes()->attach($resource_server_read_page_scope->id);
//regenerate secret needs write access or specific access
$resource_server_api_regenerate = ApiEndpoint::where('name','=','resource-server-regenerate-secret')->first();
$resource_server_api_regenerate->scopes()->attach($resource_server_write_scope->id);
$resource_server_api_regenerate->scopes()->attach($resource_server_regenerate_secret_scope->id);
//deletes needs delete access
$resource_server_api_delete = ApiEndpoint::where('name','=','resource-server-delete')->first();
$resource_server_api_delete->scopes()->attach($resource_server_delete_scope->id);
//update needs update access
$resource_server_api_update = ApiEndpoint::where('name','=','resource-server-update')->first();
$resource_server_api_update->scopes()->attach($resource_server_update_scope->id);
//update status needs update access or specific access
$resource_server_api_update_status = ApiEndpoint::where('name','=','resource-server-update-status')->first();
$resource_server_api_update_status->scopes()->attach($resource_server_update_scope->id);
$resource_server_api_update_status->scopes()->attach($resource_server_update_status_scope->id);
]);
}
private function seedApiEndpoints(){
$current_realm = Config::get('app.url');
$api_api = Api::where('name','=','api')->first();
ApiEndpoint::create(
SeedUtils::seedApiEndpoints('api', [
array(
'name' => 'get-api',
'active' => true,
'api_id' => $api_api->id,
'route' => '/api/v1/api/{id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [
sprintf('%s/api/read', $current_realm)
]
),
array(
'name' => 'delete-api',
'active' => true,
'api_id' => $api_api->id,
'route' => '/api/v1/api/{id}',
'http_method' => 'DELETE'
)
);
ApiEndpoint::create(
'http_method' => 'DELETE',
'scopes' => [
sprintf('%s/api/delete',$current_realm)
]
),
array(
'name' => 'create-api',
'active' => true,
'api_id' => $api_api->id,
'route' => '/api/v1/api',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [
sprintf('%s/api/write',$current_realm)
]
),
array(
'name' => 'update-api',
'active' => true,
'api_id' => $api_api->id,
'route' => '/api/v1/api',
'http_method' => 'PUT'
)
);
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [
sprintf('%s/api/update',$current_realm)
]
),
array(
'name' => 'update-api-status',
'active' => true,
'api_id' => $api_api->id,
'route' => '/api/v1/api/status/{id}/{active}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [
sprintf('%s/api/update.status',$current_realm)
]
),
array(
'name' => 'api-get-page',
'active' => true,
'api_id' => $api_api->id,
'route' => '/api/v1/api/{page_nbr}/{page_size}',
'http_method' => 'GET'
'http_method' => 'GET',
'scopes' => [
sprintf('%s/api/read', $current_realm),
sprintf('%s/api/read.page',$current_realm)
]
)
);
]);
//endpoint api scopes
$api_read_scope = ApiScope::where('name','=',sprintf('%s/api/read',$current_realm))->first();
$api_write_scope = ApiScope::where('name','=',sprintf('%s/api/write',$current_realm))->first();
$api_read_page_scope = ApiScope::where('name','=',sprintf('%s/api/read.page',$current_realm))->first();
$api_delete_scope = ApiScope::where('name','=',sprintf('%s/api/delete',$current_realm))->first();
$api_update_scope = ApiScope::where('name','=',sprintf('%s/api/update',$current_realm))->first();
$api_update_status_scope = ApiScope::where('name','=',sprintf('%s/api/update.status',$current_realm))->first();
$endpoint_api_get = ApiEndpoint::where('name','=','get-api')->first();
$endpoint_api_get->scopes()->attach($api_read_scope->id);
$endpoint_api_get_page = ApiEndpoint::where('name','=','api-get-page')->first();
$endpoint_api_get_page->scopes()->attach($api_read_scope->id);
$endpoint_api_get_page->scopes()->attach($api_read_page_scope->id);
$endpoint_api_delete = ApiEndpoint::where('name','=','delete-api')->first();
$endpoint_api_delete->scopes()->attach($api_delete_scope->id);
$endpoint_api_create = ApiEndpoint::where('name','=','create-api')->first();
$endpoint_api_create->scopes()->attach($api_write_scope->id);
$endpoint_api_update = ApiEndpoint::where('name','=','update-api')->first();
$endpoint_api_update->scopes()->attach($api_update_scope->id);
$endpoint_api_update_status = ApiEndpoint::where('name','=','update-api-status')->first();
$endpoint_api_update_status->scopes()->attach($api_update_scope->id);
$endpoint_api_update_status->scopes()->attach($api_update_status_scope->id);
}
private function seedUsersEndpoints(){
$api_repository = EntityManager::getRepository(Api::class);
$endpoint_repository = EntityManager::getRepository(ApiEndpoint::class);
$users = $api_repository->findOneBy(['name' => 'users']);
$api_scope_payloads = [
array(
'name' => 'get-user-info',
'active' => true,
'api' => $users,
'route' => '/api/v1/users/me',
'http_method' => 'GET'
),
array(
'name' => 'get-user-claims-get',
'active' => true,
'api' => $users,
'route' => '/api/v1/users/info',
'http_method' => 'GET'
),
array(
'name' => 'get-user-claims-post',
'active' => true,
'api' => $users,
'route' => '/api/v1/users/info',
'http_method' => 'POST'
)
];
foreach($api_scope_payloads as $payload) {
EntityManager::persist(ApiEndpointFactory::build($payload));
}
EntityManager::flush();
$api_scope_repository = EntityManager::getRepository(ApiScope::class);
$profile_scope = $api_scope_repository->findOneBy(['name' => 'profile']);
$email_scope = $api_scope_repository->findOneBy(['name' => 'email']);
$address_scope = $api_scope_repository->findOneBy(['name' => 'address']);
foreach($api_scope_payloads as $payload) {
$endpoint = $endpoint_repository->findOneBy(['name' => $payload['name']]);
$endpoint->addScope($address_scope);
$endpoint->addScope($email_scope);
$endpoint->addScope($profile_scope);
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
private function seedUserRegistrationEndpoints(){
$api_repository = EntityManager::getRepository(Api::class);
$endpoint_repository = EntityManager::getRepository(ApiEndpoint::class);
$api = $api_repository->findOneBy(['name' => 'user-registration']);
$api_scope_payloads = [
array(
'name' => 'request-user-registration',
'active' => true,
'api' => $api,
'route' => '/api/v1/user-registration-requests',
'http_method' => 'POST'
),
];
foreach($api_scope_payloads as $payload) {
EntityManager::persist(ApiEndpointFactory::build($payload));
}
EntityManager::flush();
$api_scope_repository = EntityManager::getRepository(ApiScope::class);
$scope = $api_scope_repository->findOneBy(['name' => IUserScopes::Registration]);
foreach($api_scope_payloads as $payload) {
$endpoint = $endpoint_repository->findOneBy(['name' => $payload['name']]);
$endpoint->addScope($scope);
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
/*
private function seedApiEndpointEndpoints(){
$current_realm = Config::get('app.url');
@ -1997,89 +1913,6 @@ PPK;
$endpoint_api_scope_update_status->scopes()->attach($api_scope_update_status_scope->id);
}
private function seedUsersEndpoints(){
$api_repository = EntityManager::getRepository(Api::class);
$endpoint_repository = EntityManager::getRepository(ApiEndpoint::class);
$users = $api_repository->findOneBy(['name' => 'users']);
$api_scope_payloads = [
array(
'name' => 'get-user-info',
'active' => true,
'api' => $users,
'route' => '/api/v1/users/me',
'http_method' => 'GET'
),
array(
'name' => 'get-user-claims-get',
'active' => true,
'api' => $users,
'route' => '/api/v1/users/info',
'http_method' => 'GET'
),
array(
'name' => 'get-user-claims-post',
'active' => true,
'api' => $users,
'route' => '/api/v1/users/info',
'http_method' => 'POST'
)
];
foreach($api_scope_payloads as $payload) {
EntityManager::persist(ApiEndpointFactory::build($payload));
}
EntityManager::flush();
$api_scope_repository = EntityManager::getRepository(ApiScope::class);
$profile_scope = $api_scope_repository->findOneBy(['name' => 'profile']);
$email_scope = $api_scope_repository->findOneBy(['name' => 'email']);
$address_scope = $api_scope_repository->findOneBy(['name' => 'address']);
foreach($api_scope_payloads as $payload) {
$endpoint = $endpoint_repository->findOneBy(['name' => $payload['name']]);
$endpoint->addScope($address_scope);
$endpoint->addScope($email_scope);
$endpoint->addScope($profile_scope);
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
private function seedUserRegistrationEndpoints(){
$api_repository = EntityManager::getRepository(Api::class);
$endpoint_repository = EntityManager::getRepository(ApiEndpoint::class);
$api = $api_repository->findOneBy(['name' => 'user-registration']);
$api_scope_payloads = [
array(
'name' => 'request-user-registration',
'active' => true,
'api' => $api,
'route' => '/api/v1/user-registration-requests',
'http_method' => 'POST'
),
];
foreach($api_scope_payloads as $payload) {
EntityManager::persist(ApiEndpointFactory::build($payload));
}
EntityManager::flush();
$api_scope_repository = EntityManager::getRepository(ApiScope::class);
$scope = $api_scope_repository->findOneBy(['name' => IUserScopes::Registration]);
foreach($api_scope_payloads as $payload) {
$endpoint = $endpoint_repository->findOneBy(['name' => $payload['name']]);
$endpoint->addScope($scope);
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
private function seedPublicCloudsEndpoints(){
$public_clouds = Api::where('name','=','public-clouds')->first();
$current_realm = Config::get('app.url');
@ -2222,5 +2055,7 @@ PPK;
$endpoint = ApiEndpoint::where('name','=','get-consultant-offices')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
}
*/
}

View File

@ -37,43 +37,8 @@
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
- shell:
cmd: |
set -e
set -x
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install mysql-server redis zip unzip
sudo service mysql start
sudo mysql -e "CREATE USER 'openstackid_test_user'@'%' IDENTIFIED BY '1qaz2wsx'"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS openstackid_test"
sudo mysql -e "GRANT ALL ON openstackid_test.* TO 'openstackid_test_user'@'%';"
sudo mysql -e "FLUSH PRIVILEGES"
cat >.env <<EOF
APP_ENV=local
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=openstackid_test
DB_USERNAME=openstackid_test_user
DB_PASSWORD=1qaz2wsx
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
EOF
cat >.env.testing <<EOF
APP_ENV=testing
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=openstackid_test
DB_USERNAME=openstackid_test_user
DB_PASSWORD=1qaz2wsx
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
EOF
executable: /bin/bash
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
- include_role:
name: setup-test-laravel-env
- include_role:
name: bindep

View File

@ -37,43 +37,8 @@
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
- shell:
cmd: |
set -e
set -x
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install mysql-server redis zip unzip
sudo service mysql start
sudo mysql -e "CREATE USER 'openstackid_test_user'@'%' IDENTIFIED BY '1qaz2wsx'"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS openstackid_test"
sudo mysql -e "GRANT ALL ON openstackid_test.* TO 'openstackid_test_user'@'%';"
sudo mysql -e "FLUSH PRIVILEGES"
cat >.env <<EOF
APP_ENV=local
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=openstackid_test
DB_USERNAME=openstackid_test_user
DB_PASSWORD=1qaz2wsx
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
EOF
cat >.env.testing <<EOF
APP_ENV=testing
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=openstackid_test
DB_USERNAME=openstackid_test_user
DB_PASSWORD=1qaz2wsx
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
EOF
executable: /bin/bash
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
- include_role:
name: setup-test-laravel-env
- include_role:
name: bindep

View File

@ -37,43 +37,8 @@
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
- shell:
cmd: |
set -e
set -x
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install mysql-server redis zip unzip
sudo service mysql start
sudo mysql -e "CREATE USER 'openstackid_test_user'@'%' IDENTIFIED BY '1qaz2wsx'"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS openstackid_test"
sudo mysql -e "GRANT ALL ON openstackid_test.* TO 'openstackid_test_user'@'%';"
sudo mysql -e "FLUSH PRIVILEGES"
cat >.env <<EOF
APP_ENV=local
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=openstackid_test
DB_USERNAME=openstackid_test_user
DB_PASSWORD=1qaz2wsx
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
EOF
cat >.env.testing <<EOF
APP_ENV=testing
APP_DEBUG=true
DB_HOST=localhost
DB_DATABASE=openstackid_test
DB_USERNAME=openstackid_test_user
DB_PASSWORD=1qaz2wsx
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
EOF
executable: /bin/bash
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
- include_role:
name: setup-test-laravel-env
- include_role:
name: bindep
@ -94,5 +59,12 @@
set -x
curl -s https://getcomposer.org/installer | /usr/bin/php
/usr/bin/php composer.phar install --prefer-dist --ignore-platform-reqs
/usr/bin/php artisan doctrine:clear:metadata:cache;
/usr/bin/php artisan doctrine:clear:query:cache;
/usr/bin/php artisan doctrine:clear:result:cache;
/usr/bin/php artisan doctrine:generate:proxies;
/usr/bin/php artisan view:clear;
/usr/bin/php artisan view:cache;
./vendor/bin/phpunit
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'

View File

@ -0,0 +1,8 @@
Set up laravel test env
**Role Variables**
.. zuul:rolevar:: devstack_base_dir
:default: /opt/stack
The devstack base directory.

View File

@ -0,0 +1,8 @@
db_user: openstackid_test_user
db_password: 1qaz2wsx
db_name: openstackid_test
db_max_connections : 200
app_key: base64:4vh0op/S1dAsXKQ2bbdCfWRyCI9r8NNIdPXyZWt9PX4=
app_debug: true
redis_port: 6379
server_name: local.openstackid.openstack.org

View File

@ -0,0 +1,61 @@
- name: Set Laravel Test Env
shell:
cmd: |
set -e
set -x
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install mysql-server redis zip unzip
echo "max_connections = {{ db_max_connections }}" >> /etc/mysql/mysql.conf.d/mysqld.cnf;
sudo service mysql start
sudo mysql -e "CREATE USER '{{ db_user }}'@'%' IDENTIFIED BY '{{ db_password }}'"
sudo mysql -e "CREATE DATABASE IF NOT EXISTS {{ db_name }}"
sudo mysql -e "GRANT ALL ON {{ db_name }}.* TO '{{ db_user }}'@'%';"
sudo mysql -e "FLUSH PRIVILEGES"
cat >.env <<EOF
APP_ENV=local
APP_DEBUG={{ app_debug }}
APP_KEY={{ app_key }}
DB_HOST=localhost
DB_DATABASE={{ db_name }}
DB_USERNAME={{ db_user }}
DB_PASSWORD={{ db_password }}
REDIS_HOST=127.0.0.1
REDIS_PORT={{ redis_port }}
REDIS_DB=0
EOF
cat >.env.testing <<EOF
APP_ENV=testing
APP_KEY={{ app_key }}
APP_DEBUG={{ app_debug }}
REMOTE_ADDR=192.1.1.1
APP_URL=https://{{ server_name }}
DB_HOST=localhost
DB_DATABASE={{ db_name }}
DB_USERNAME={{ db_user }}
DB_PASSWORD={{ db_password }}
REDIS_HOST=127.0.0.1
REDIS_PORT={{ redis_port }}
REDIS_DB=0
MAIL_DRIVER=log
CORS_ALLOWED_HEADERS="origin, content-type, accept, authorization, x-requested-with"
CORS_ALLOWED_METHODS="GET, POST, OPTIONS, PUT, DELETE"
CORS_USE_PRE_FLIGHT_CACHING=false
CORS_MAX_AGE=3200
CORS_EXPOSED_HEADERS=
CURL_TIMEOUT=3600
CURL_ALLOWS_REDIRECT=false
CURL_VERIFY_SSL_CERT=false
SSL_ENABLED=true
DB_LOG_ENABLED=true
ACCESS_TOKEN_CACHE_LIFETIME=300
API_RESPONSE_CACHE_LIFETIME=600
LOG_LEVEL=debug
APP_LOG=daily
SERVER_NAME={{ server_name }}
EOF
executable: /bin/bash
chdir: '{{ ansible_user_dir }}/workspace'
environment: '{{ zuul | zuul_legacy_vars }}'
become: yes

View File

@ -15,6 +15,7 @@ use Models\OAuth2\ApiEndpoint;
use Models\OAuth2\Api;
use Models\OAuth2\ApiScope;
use Tests\BrowserKitTestCase;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class ApiEndpointTest
*/
@ -35,10 +36,10 @@ final class ApiEndpointTest extends BrowserKitTestCase {
*/
public function testGetById(){
$api_endpoint = ApiEndpoint::where('name','=','get-api')->first();
$api_endpoint = EntityManager::getRepository(ApiEndpoint::class)->findOneBy(['name' => 'get-api']);
$this->assertTrue(!is_null($api_endpoint));
$response = $this->action("GET", "Api\ApiEndpointController@get",
$response = $this->action("GET", "Api\\ApiEndpointController@get",
$parameters = array('id' =>$api_endpoint->id),
[],
[],
@ -56,21 +57,21 @@ final class ApiEndpointTest extends BrowserKitTestCase {
* @covers get api endpoint by list (paginated)
*/
public function testGetByPage(){
$response = $this->action("GET", "Api\ApiEndpointController@getByPage",
$parameters = array('offset' => 1,'limit'=>10),
$response = $this->action("GET", "Api\ApiEndpointController@getAll",
$parameters = ['page' => 1,'per_page'=>10],
[],
[],
[]);
$content = $response->getContent();
$list = json_decode($content);
$this->assertTrue(isset($list->total_items) && intval($list->total_items)>0);
$this->assertTrue(isset($list->total) && intval($list->total)>0);
$this->assertResponseStatus(200);
}
public function testCreate(){
$api = Api::where('name','=','api-endpoint')->first();
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => 'api-endpoint']);
$this->assertTrue(!is_null($api));
$data = array(
@ -94,15 +95,15 @@ final class ApiEndpointTest extends BrowserKitTestCase {
$json_response = json_decode($content);
$this->assertResponseStatus(201);
$this->assertTrue(isset($json_response->api_endpoint_id) && !empty($json_response->api_endpoint_id));
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
}
public function testUpdate(){
$api = Api::where('name','=','api-endpoint')->first();
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' =>'api']);
$this->assertTrue(!is_null($api));
$data = array(
$data = [
'name' => 'test-api-endpoint',
'description' => 'test api endpoint, allows test api endpoints.',
'active' => true,
@ -111,7 +112,7 @@ final class ApiEndpointTest extends BrowserKitTestCase {
'api_id' => $api->id,
'allow_cors' => true,
'rate_limit' => 60,
);
];
$response = $this->action("POST", "Api\ApiEndpointController@create",
$data,
@ -123,30 +124,36 @@ final class ApiEndpointTest extends BrowserKitTestCase {
$json_response = json_decode($content);
$this->assertResponseStatus(201);
$this->assertTrue(isset($json_response->api_endpoint_id) && !empty($json_response->api_endpoint_id));
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
//update recently created
$data_updated = array(
'id' => $json_response->api_endpoint_id,
'id' => $json_response->id,
'name' => 'test-api-endpoint-update',
'description' => 'test api endpoint, allows test api endpoints.',
'active' => true,
'route' => '/api/v1/api-endpoint/test',
'http_method' => 'POST',
'api_id' => $api->id,
'allow_cors' => true,
'rate_limit' => 60,
);
$response = $this->action("PUT", "Api\ApiEndpointController@update",$parameters = $data_updated, [],
$response = $this->action("PUT", "Api\ApiEndpointController@update", $parameters = $data_updated, [],
[],
[]);
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue($json_response ==="ok");
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
}
public function testUpdateStatus(){
$api = Api::where('name','=','api-endpoint')->first();
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => 'api-endpoint']);
$this->assertTrue(!is_null($api));
$data = array(
'name' => 'test-api-endpoint',
@ -163,15 +170,14 @@ final class ApiEndpointTest extends BrowserKitTestCase {
$this->assertResponseStatus(201);
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue(isset($json_response->api_endpoint_id) && !empty($json_response->api_endpoint_id));
$new_id = $json_response->api_endpoint_id;
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
$new_id = $json_response->id;
//update status
$response = $this->action('DELETE',"Api\ApiEndpointController@deactivate", array('id' => $new_id) );
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue($json_response==='ok');
$response = $this->action("GET", "Api\ApiEndpointController@get",array('id' => $new_id));
$this->assertResponseStatus(200);
@ -182,7 +188,7 @@ final class ApiEndpointTest extends BrowserKitTestCase {
public function testDeleteExisting(){
$api_endpoint = ApiEndpoint::where('name','=','update-api-endpoint-status')->first();
$api_endpoint = EntityManager::getRepository(ApiEndpoint::class)->findOneBy(['name' => 'update-api-status']);
$this->assertTrue(!is_null($api_endpoint));
@ -208,9 +214,10 @@ final class ApiEndpointTest extends BrowserKitTestCase {
public function testAddRequiredScope(){
$api_endpoint = ApiEndpoint::where('name','=','update-api-endpoint-status')->first();
$api_endpoint = EntityManager::getRepository(ApiEndpoint::class)->findOneBy(['name' => 'update-api-status']);
$this->assertTrue(!is_null($api_endpoint));
$scope = ApiScope::where('name','=',sprintf('%s/api-endpoint/read',$this->current_realm))->first();
$scope = EntityManager::getRepository(ApiScope::class)->findOneBy(['name' => sprintf('%s/api/read', $this->current_realm)]);
$this->assertTrue(!is_null($scope));
$response = $this->action("PUT", "Api\ApiEndpointController@addRequiredScope",array(
@ -219,9 +226,8 @@ final class ApiEndpointTest extends BrowserKitTestCase {
[],
[]);
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$content = $response->getContent();
$this->assertTrue(json_decode($content)==='ok');
$response = $this->action("GET", "Api\ApiEndpointController@get",
$parameters = array('id' =>$api_endpoint->id),
@ -231,27 +237,27 @@ final class ApiEndpointTest extends BrowserKitTestCase {
$content = $response->getContent();
$response_api_endpoint = json_decode($content);
$this->assertTrue(is_array($response_api_endpoint->scopes) && count($response_api_endpoint->scopes)>2);
$this->assertTrue(is_array($response_api_endpoint->scopes) && count($response_api_endpoint->scopes) > 1);
$this->assertResponseStatus(200);
}
public function testRemoveRequiredScope(){
$api_endpoint = ApiEndpoint::where('name','=','update-api-endpoint-status')->first();
$api_endpoint = EntityManager::getRepository(ApiEndpoint::class)->findOneBy(['name' => 'update-api-status']);
$this->assertTrue(!is_null($api_endpoint));
$scope = ApiScope::where('name','=',sprintf('%s/api-endpoint/update',$this->current_realm))->first();
$scope = EntityManager::getRepository(ApiScope::class)->findOneBy(['name' => sprintf('%s/api/update.status', $this->current_realm)]);
$this->assertTrue(!is_null($scope));
$response = $this->action("DELETE", "Api\ApiEndpointController@removeRequiredScope",array(
$response = $this->action("DELETE", "Api\ApiEndpointController@removeRequiredScope", array(
'id' => $api_endpoint->id,
'scope_id' => $scope->id), [],
[],
[]);
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$content = $response->getContent();
$response = json_decode($content);
$this->assertTrue($response==='ok');
$response = $this->action("GET", "Api\ApiEndpointController@get",
$parameters = array('id' =>$api_endpoint->id),
@ -261,7 +267,7 @@ final class ApiEndpointTest extends BrowserKitTestCase {
$content = $response->getContent();
$response_api_endpoint = json_decode($content);
$this->assertTrue(is_array($response_api_endpoint->scopes) && count($response_api_endpoint->scopes)==1);
$this->assertTrue(is_array($response_api_endpoint->scopes) && count($response_api_endpoint->scopes) == 0);
$this->assertResponseStatus(200);
}

View File

@ -14,6 +14,7 @@
use Models\OAuth2\ApiScope;
use Models\OAuth2\Api;
use Tests\BrowserKitTestCase;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class ApiScopeTest
*/
@ -34,7 +35,8 @@ final class ApiScopeTest extends BrowserKitTestCase {
*/
public function testGetById(){
$scope = ApiScope::where('name','=', sprintf('%s/api-scope/read',$this->current_realm))->first();
$scope = EntityManager::getRepository(ApiScope::class)->findOneBy(['name' => sprintf('%s/api-scope/read',$this->current_realm)]);
$this->assertTrue(!is_null($scope));
$response = $this->action("GET", "Api\ApiScopeController@get",
@ -73,7 +75,7 @@ final class ApiScopeTest extends BrowserKitTestCase {
*/
public function testCreate(){
$api = Api::where('name','=','api-endpoint')->first();
$api = EntityManager::getRepository(Api::class)->findOneBy(['name' => 'api-endpoint']);
$this->assertTrue(!is_null($api));
@ -98,7 +100,7 @@ final class ApiScopeTest extends BrowserKitTestCase {
$json_response = json_decode($content);
$this->assertResponseStatus(201);
$this->assertTrue(isset($json_response->scope_id) && !empty($json_response->scope_id));
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
}
/**
@ -107,7 +109,7 @@ final class ApiScopeTest extends BrowserKitTestCase {
*/
public function testDeleteExisting(){
$scope = ApiScope::where('name','=', sprintf('%s/api-scope/read',$this->current_realm))->first();
$scope = EntityManager::getRepository(ApiScope::class)->findOneBy(['name' => sprintf('%s/api-scope/read',$this->current_realm)]);
$this->assertTrue(!is_null($scope));

View File

@ -93,8 +93,7 @@ final class ApiTest extends BrowserKitTestCase {
public function testDelete(){
$repository = EntityManager::getRepository(ResourceServer::class);
$resource_server = $repository->findOneBy(['host'=> $this->current_host]);
$resource_server = EntityManager::getRepository(ResourceServer::class)->findOneBy(['host' => $this->current_host]);
$data = array(
'name' => 'test-api',
@ -113,9 +112,9 @@ final class ApiTest extends BrowserKitTestCase {
$json_response = json_decode($content);
$this->assertResponseStatus(201);
$this->assertTrue(isset($json_response->api_id) && !empty($json_response->api_id));
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
$new_id = $json_response->api_id;
$new_id = $json_response->id;
$response = $this->action("DELETE", "Api\ApiController@delete",$parameters = array('id' => $new_id),
[],
[],
@ -136,7 +135,7 @@ final class ApiTest extends BrowserKitTestCase {
public function testUpdate(){
$resource_server = ResourceServer::where('host','=',$this->current_host)->first();
$resource_server = EntityManager::getRepository(ResourceServer::class)->findOneBy(['host' => $this->current_host]);
$data = array(
'name' => 'test-api',
@ -155,9 +154,9 @@ final class ApiTest extends BrowserKitTestCase {
$json_response = json_decode($content);
$this->assertResponseStatus(201);
$this->assertTrue(isset($json_response->api_id) && !empty($json_response->api_id));
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
$new_id = $json_response->api_id;
$new_id = $json_response->id;
//update it
$data_update = array(
@ -174,7 +173,7 @@ final class ApiTest extends BrowserKitTestCase {
$json_response = json_decode($content);
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$response = $this->action("GET", "Api\ApiController@get",
@ -193,14 +192,14 @@ final class ApiTest extends BrowserKitTestCase {
public function testUpdateStatus(){
$resource_server = ResourceServer::where('host','=',$this->current_host)->first();
$resource_server = EntityManager::getRepository(ResourceServer::class)->findOneBy(['host' => $this->current_host]);
$data = array(
$data = [
'name' => 'test-api',
'description' => 'test api',
'active' => true,
'resource_server_id' => $resource_server->id,
);
];
$response = $this->action("POST", "Api\ApiController@create",$data);
$this->assertResponseStatus(201);
@ -208,20 +207,18 @@ final class ApiTest extends BrowserKitTestCase {
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue(isset($json_response->api_id) && !empty($json_response->api_id));
$this->assertTrue(isset($json_response->id) && !empty($json_response->id));
$new_id = $json_response->api_id;
$new_id = $json_response->id;
//update status
$response = $this->action("PUT", "Api\ApiController@activate",array('id' => $new_id));
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue($json_response==='ok');
$response = $this->action("GET", "Api\ApiController@get",$parameters = array('id' => $new_id));
@ -233,7 +230,7 @@ final class ApiTest extends BrowserKitTestCase {
public function testDeleteExisting(){
$resource_server_api = Api::where('name','=','resource-server')->first();
$resource_server_api = EntityManager::getRepository(Api::class)->findOneBy(['name'=>'resource-server']);
$id = $resource_server_api->id;
@ -242,7 +239,6 @@ final class ApiTest extends BrowserKitTestCase {
[],
[]);
$this->assertResponseStatus(204);
$response = $this->action("GET", "Api\ApiController@get",

View File

@ -16,6 +16,7 @@ use Auth\User;
use Models\OAuth2\Client;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Config;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class ClientApiTest
*/
@ -33,14 +34,16 @@ class ClientApiTest extends \Tests\BrowserKitTestCase {
$parts = parse_url($this->current_realm);
$this->current_host = $parts['host'];
$user = User::where('identifier', '=', 'sebastian.marcet')->first();
$user = EntityManager::getRepository(User::class)->findOneBy(['identifier' => 'sebastian.marcet']);
$this->be($user);
Session::start();
}
public function testGetById(){
$client = Client::where('app_name','=','oauth2_test_app')->first();
$client = EntityManager::getRepository(Client::class)->findOneBy(['app_name' => 'oauth2_test_app']);
$response = $this->action("GET", "Api\\ClientApiController@get",
$parameters = array('id' => $client->id),
[],
@ -56,8 +59,8 @@ class ClientApiTest extends \Tests\BrowserKitTestCase {
public function testGetByPage(){
$response = $this->action("GET", "Api\\ClientApiController@getByPage",
$parameters = array('offset' => 1,'limit'=>10),
$response = $this->action("GET", "Api\\ClientApiController@getAll",
$parameters = array('page' => 1,'per_page'=>10),
[],
[],
[]);
@ -65,12 +68,12 @@ class ClientApiTest extends \Tests\BrowserKitTestCase {
$content = $response->getContent();
$this->assertResponseStatus(200);
$list = json_decode($content);
$this->assertTrue(isset($list->total_items) && intval($list->total_items)>0);
$this->assertTrue(isset($list->total) && intval($list->total)>0);
}
public function testCreate(){
$user = User::where('identifier','=','sebastian.marcet')->first();
$user = EntityManager::getRepository(User::class)->findOneBy(['identifier' => 'sebastian.marcet']);
$data = array(
'user_id' => $user->id,

View File

@ -15,11 +15,13 @@ use jwk\JSONWebKeyTypes;
use jwk\JSONWebKeyPublicKeyUseValues;
use Models\OAuth2\Client;
use jwa\JSONWebSignatureAndEncryptionAlgorithms;
use Tests\TestCase;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Tests\BrowserKitTestCase;
use Auth\User;
/**
* Class ClientPublicKeyApiTest
*/
class ClientPublicKeyApiTest extends TestCase {
class ClientPublicKeyApiTest extends BrowserKitTestCase {
private $current_realm;
@ -32,12 +34,16 @@ class ClientPublicKeyApiTest extends TestCase {
$this->current_realm = Config::get('app.url');
$parts = parse_url($this->current_realm);
$this->current_host = $parts['host'];
//already logged user
$user_repository = EntityManager::getRepository(User::class);
$user = $user_repository->findOneBy(["identifier" => 'sebastian.marcet']);
$this->be($user, 'web');
}
public function testCreate(){
$client_id = 'Jiz87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.client';
$client = Client::where('client_id','=', $client_id)->first();
$client = EntityManager::getRepository(Client::class)->findOneBy(['client_id' => $client_id]);
$data = array
(
@ -51,7 +57,7 @@ class ClientPublicKeyApiTest extends TestCase {
'alg' => JSONWebSignatureAndEncryptionAlgorithms::RS512
);
$response = $this->action("POST", "Api\ClientPublicKeyApiController@create",
$response = $this->action("POST", "Api\\ClientPublicKeyApiController@_create",
$wildcards = array('id' => $client->id),
$data,
[],

View File

@ -63,7 +63,7 @@ abstract class OAuth2ProtectedApiTest extends OpenStackIDBaseTest {
'client_id' => $this->client_id,
'redirect_uri' => 'https://www.test.com/oauth2',
'response_type' => OAuth2Protocol::OAuth2Protocol_ResponseType_Code,
'scope' => implode(' ',$scope),
'scope' => implode(' ', $scope),
OAuth2Protocol::OAuth2Protocol_AccessType => OAuth2Protocol::OAuth2Protocol_AccessType_Offline,
);
@ -84,12 +84,11 @@ abstract class OAuth2ProtectedApiTest extends OpenStackIDBaseTest {
$output = [];
parse_str($query, $output);
$params = array
(
$params = [
'code' => $output['code'],
'redirect_uri' => 'https://www.test.com/oauth2',
'grant_type' => OAuth2Protocol::OAuth2Protocol_GrantType_AuthCode,
);
];
$response = $this->action
(

View File

@ -121,7 +121,6 @@ final class OAuth2ProtocolTest extends OpenStackIDBaseTest
$this->assertResponseStatus(400);
}
/**

View File

@ -11,12 +11,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use OAuth2ProtectedApiTest;
use App\libs\OAuth2\IUserScopes;
/**
* Class OAuth2UserRegistrationServiceApiTest
* @package Tests
*/
final class OAuth2UserRegistrationServiceApiTest extends \OAuth2ProtectedApiTest
final class OAuth2UserRegistrationServiceApiTest extends OAuth2ProtectedApiTest
{
@ -40,7 +41,7 @@ final class OAuth2UserRegistrationServiceApiTest extends \OAuth2ProtectedApiTest
$response = $this->action
(
"POST",
"Api\OAuth2\OAuth2UserRegistrationRequestApiController@register",
"Api\\OAuth2\\OAuth2UserRegistrationRequestApiController@register",
$params,
[],
[],
@ -59,26 +60,12 @@ final class OAuth2UserRegistrationServiceApiTest extends \OAuth2ProtectedApiTest
'redirect_uri' => 'https://www.test.com/oauth2'
];
$response = $this->action
(
"GET",
"Auth\PasswordSetController@showPasswordSetForm",
$params,
[],
[],
[],
[],
null
);
$this->assertResponseStatus(200);
}
protected function getScopes()
{
$scope = [
'request-user-registration'
IUserScopes::Registration,
];
return $scope;

View File

@ -2684,8 +2684,8 @@ final class OIDCProtocolTest extends OpenStackIDBaseTest
$this->assertResponseStatus(302);
$url = $response->getTargetUrl();
$comps = @parse_url($url);
$url = $response->getTargetUrl();
$comps = @parse_url($url);
$fragment = $comps['fragment'];
$this->assertTrue(!empty($fragment));
@ -2721,7 +2721,6 @@ final class OIDCProtocolTest extends OpenStackIDBaseTest
$jwt = BasicJWTFactory::build($payload);
$this->assertTrue($jwt instanceof IJWS);
$jwk = OctetSequenceJWKFactory::build
(
new OctetSequenceJWKSpecification
@ -2743,8 +2742,7 @@ final class OIDCProtocolTest extends OpenStackIDBaseTest
$id_token_hint = $jwt->toCompactSerialization();
$params = array
(
$params = [
'client_id' => $client_id,
'redirect_uri' => 'https://www.test.com/oauth2',
'response_type' => 'id_token code',
@ -2752,7 +2750,7 @@ final class OIDCProtocolTest extends OpenStackIDBaseTest
OAuth2Protocol::OAuth2Protocol_Prompt => OAuth2Protocol::OAuth2Protocol_Prompt_None,
OAuth2Protocol::OAuth2Protocol_IDTokenHint => $id_token_hint,
OAuth2Protocol::OAuth2Protocol_Nonce => 'ctqg5FeNoYnZ',
);
];
$response = $this->action("POST", "OAuth2\OAuth2ProviderController@auth",
$params,

View File

@ -1274,7 +1274,6 @@ final class OpenIdProtocolTest extends OpenStackIDBaseTest
$params = $this->prepareCheckAuthenticationParams($openid_response);
$params['openid.assoc_handle'] = "FAKE";
$response = $this->action("POST", "OpenId\OpenIdProviderController@endpoint", $params);
$openid_response = $this->getOpenIdResponseLineBreak($response->getContent());
$this->assertResponseStatus(400);
}
}

View File

@ -16,6 +16,7 @@ use Illuminate\Support\Facades\Config;
use Auth\User;
use Illuminate\Support\Facades\Session;
use Tests\BrowserKitTestCase;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class ResourceServerApiTest
* Test ResourceServer REST API
@ -34,7 +35,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$this->current_realm = Config::get('app.url');
$parts = parse_url($this->current_realm);
$this->current_host = $parts['host'];
$user = User::where('identifier', '=', 'sebastian.marcet')->first();
$user = EntityManager::getRepository(User::class)->findOneBy(['identifier' => 'sebastian.marcet']);
$this->be($user);
Session::start();
}
@ -42,7 +43,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
public function testGetById()
{
$resource_server = ResourceServer::where('host', '=', $this->current_host)->first();
$resource_server = EntityManager::getRepository(ResourceServer::class)->findOneBy(['host' => $this->current_host]);
$response = $this->action("GET", "Api\\ApiResourceServerController@get",
$parameters = array('id' => $resource_server->id),
@ -60,8 +61,8 @@ final class ResourceServerApiTest extends BrowserKitTestCase
public function testGetByPage()
{
$response = $this->action("GET", "Api\\ApiResourceServerController@getByPage",
$parameters = array('page_nbr' => 1, 'page_size' => 10),
$response = $this->action("GET", "Api\\ApiResourceServerController@getAll",
$parameters = array('page' => 1, 'per_page' => 10),
[],
[],
[]);
@ -69,8 +70,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$this->assertResponseStatus(200);
$content = $response->getContent();
$list = json_decode($content);
$this->assertTrue(isset($list->total_items) && intval($list->total_items) > 0);
$this->assertTrue(isset($list->total) && intval($list->total) > 0);
}
public function testCreate()
@ -91,8 +91,8 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$this->assertResponseStatus(201);
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue(isset($json_response->resource_server_id));
$this->assertTrue(!empty($json_response->resource_server_id));
$this->assertTrue(isset($json_response->id));
$this->assertTrue(!empty($json_response->id));
}
@ -106,7 +106,6 @@ final class ResourceServerApiTest extends BrowserKitTestCase
'active' => true,
);
$response = $this->action("POST", "Api\\ApiResourceServerController@create",
$data,
[],
@ -117,9 +116,15 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$json_response = json_decode($content);
$new_id = $json_response->resource_server_id;
$new_id = $json_response->id;
$response = $this->action("GET", "Api\\ApiResourceServerController@get", $parameters = array('id' => $new_id),
$response = $this->action(
"GET",
"Api\\ApiResourceServerController@get",
$parameters = [
'id' => $new_id,
'expand' => 'client',
],
[],
[],
[]);
@ -129,7 +134,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$json_response = json_decode($content);
$client_secret = $json_response->client_secret;
$client_secret = $json_response->client->client_secret;
$response = $this->action("PUT", "Api\\ApiResourceServerController@regenerateClientSecret",
$parameters = array('id' => $new_id),
@ -142,12 +147,12 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$json_response = json_decode($content);
$new_secret = $json_response->new_secret;
$new_secret = $json_response->client_secret;
$this->assertTrue(!empty($new_secret));
$this->assertTrue($new_secret !== $client_secret);
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
}
@ -172,7 +177,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$json_response = json_decode($content);
$new_id = $json_response->resource_server_id;
$new_id = $json_response->id;
$response = $this->action("DELETE", "Api\\ApiResourceServerController@delete", $parameters = array('id' => $new_id),
[],
@ -193,13 +198,12 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$this->assertResponseStatus(404);
$this->assertTrue($json_response->error === 'resource server not found');
}
public function testDeleteExistingOne()
{
$resource_server = ResourceServer::where('host', '=', $this->current_host)->first();
$resource_server = EntityManager::getRepository(ResourceServer::class)->findOneBy(['host' => $this->current_host]);
$new_id = $resource_server->id;
@ -240,7 +244,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$json_response = json_decode($content);
$new_id = $json_response->resource_server_id;
$new_id = $json_response->id;
$data_update = array(
'id' => $new_id,
@ -257,7 +261,7 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$json_response = json_decode($content);
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$response = $this->action("GET", "Api\\ApiResourceServerController@get", $parameters = array('id' => $new_id),
[],
@ -287,12 +291,11 @@ final class ResourceServerApiTest extends BrowserKitTestCase
$this->assertResponseStatus(201);
$content = $response->getContent();
$json_response = json_decode($content);
$new_id = $json_response->resource_server_id;
$new_id = $json_response->id;
$response = $this->action("DELETE", "Api\\ApiResourceServerController@deactivate", array('id' => $new_id));
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
$content = $response->getContent();
$json_response = json_decode($content);
$this->assertTrue($json_response === 'ok');
$response = $this->action("GET", "Api\\ApiResourceServerController@get", $parameters = array('id' => $new_id));
$this->assertResponseStatus(200);
$content = $response->getContent();

View File

@ -16,8 +16,8 @@ use Utils\Services\IAuthService;
use OpenId\Repositories\IOpenIdTrustedSiteRepository;
use OpenId\Models\IOpenIdUser;
use Auth\User;
use Repositories\EloquentOpenIdTrustedSiteRepository;
use Tests\BrowserKitTestCase;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class TrustedSitesServiceTest
*/
@ -35,13 +35,12 @@ final class TrustedSitesServiceTest extends BrowserKitTestCase {
public function testBehaviorAdd(){
$repo_mock = Mockery::mock(EloquentOpenIdTrustedSiteRepository::class);
$repo_mock = Mockery::mock(\App\Repositories\DoctrineOpenIdTrustedSiteRepository::class);
$repo_mock->shouldReceive('add')->andReturn(true)->once();
$this->app->instance(IOpenIdTrustedSiteRepository::class, $repo_mock);
$mock_user = Mockery::mock(IOpenIdUser::class);
$mock_user->shouldReceive('getId')->andReturn(1);
$mock_user = Mockery::mock(User::class);
$mock_user->shouldReceive('addTrustedSite');
$service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
$res = $service->addTrustedSite($mock_user,
@ -54,8 +53,9 @@ final class TrustedSitesServiceTest extends BrowserKitTestCase {
public function testAdd(){
$service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
$user = User::where('identifier','=','sebastian.marcet')->first();
$res = $service->addTrustedSite($user,
$user = EntityManager::getRepository(User::class)->findOneBy(['identifier' => 'sebastian.marcet']);
$res = $service->addTrustedSite($user,
$realm = 'https://www.test.com',
IAuthService::AuthorizationResponse_AllowForever,
$data = []);
@ -69,9 +69,9 @@ final class TrustedSitesServiceTest extends BrowserKitTestCase {
$service = $this->app[OpenIdServiceCatalog::TrustedSitesService];
$user = User::where('identifier','=','sebastian.marcet')->first();
$user = EntityManager::getRepository(User::class)->findOneBy(['identifier' => 'sebastian.marcet']);
$res = $service->addTrustedSite($user, $realm, IAuthService::AuthorizationResponse_AllowForever, $data = array('email','profile','address'));
$res = $service->addTrustedSite($user, $realm, IAuthService::AuthorizationResponse_AllowForever, $data = array('email','profile','address'));
$this->assertTrue(!is_null($res));

View File

@ -12,8 +12,9 @@
* limitations under the License.
**/
use Auth\UserNameGeneratorService;
use Auth\Repositories\IMemberRepository;
use Tests\BrowserKitTestCase;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Auth\User;
/**
* Class UserGeneratorServiceTest
*/
@ -27,25 +28,24 @@ final class UserGeneratorServiceTest extends BrowserKitTestCase {
public function testBuildUsers()
{
$member_repository = App::make(IMemberRepository::class);
$user_name_service_generator = new UserNameGeneratorService();
$member1 = $member_repository->getByEmail("mkiss@tipit.net");
$member2 = $member_repository->getByEmail("fujg573@tipit.net");
$member3 = $member_repository->getByEmail("mrbharathee@tipit.com");
$member4 = $member_repository->getByEmail("yuanying@tipit.com");
$member1 = EntityManager::getRepository(User::class)->findOneBy( ['email' => "mkiss@tipit.net"]);
$member2 = EntityManager::getRepository(User::class)->findOneBy( ['email' => "fujg573@tipit.net"]);
$member3 = EntityManager::getRepository(User::class)->findOneBy( ['email' => "mrbharathee@tipit.net"]);
$member4 = EntityManager::getRepository(User::class)->findOneBy( ['email' => "yuanying@tipit.net"]);
$user_name_1 = $user_name_service_generator->generate($member1);
$this->assertTrue($user_name_1 === 'marton.kiss');
$member1 = $user_name_service_generator->generate($member1);
$this->assertTrue($member1->getIdentifier() === 'marton.kiss');
$user_name_2 = $user_name_service_generator->generate($member2);
$this->assertTrue($user_name_2 === 'fujg573');
$member2 = $user_name_service_generator->generate($member2);
$this->assertTrue($member2->getIdentifier() === 'fujg573');
$user_name_3 = $user_name_service_generator->generate($member3);
$this->assertTrue($user_name_3 === 'bharath.kumar.m.r');
$member3 = $user_name_service_generator->generate($member3);
$this->assertTrue($member3->getIdentifier() === 'bharath.kumar.m.r');
$user_name_4 = $user_name_service_generator->generate($member4);
$this->assertTrue($user_name_4 === 'yuanying');
$member4 = $user_name_service_generator->generate($member4);
$this->assertTrue($member4->getIdentifier() === 'yuanying');
}

View File

@ -1,43 +0,0 @@
<?php
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Auth\Repositories\IMemberRepository;
use OpenId\Services\IUserService;
use Tests\BrowserKitTestCase;
/**
* Class UserServiceTest
*/
final class UserServiceTest extends BrowserKitTestCase
{
protected function prepareForTests()
{
parent::prepareForTests();
}
public function testBuildUsers()
{
$member_repository = App::make(IMemberRepository::class);
$user_service = App::make(IUserService::class);
$member1 = $member_repository->getByEmail("sebastian@tipit.net");
$member2 = $member_repository->getByEmail("sebastian+1@tipit.net");
$member3 = $member_repository->getByEmail("sebastian+2@tipit.net");
$user2 = $user_service->buildUser($member2);
$user3 = $user_service->buildUser($member3);
$this->assertTrue($user2->identifier === 'sebastian.marcet.1');
$this->assertTrue($user3->identifier === 'sebastian.marcet.2');
}
}

View File

@ -1,45 +0,0 @@
<?php
use Auth\User;
use Models\Member;
use OpenId\Services\OpenIdServiceCatalog;
use Illuminate\Support\Facades\App;
use Auth\UserNameGeneratorService;
use Tests\BrowserKitTestCase;
/**
* Class UserTest
*/
class UserTest extends BrowserKitTestCase
{
public function testMember()
{
$member = Member::findOrFail(1);
$this->assertTrue($member->FirstName == 'Sebastian');
}
public function testLockUser()
{
$member = Member::findOrFail(1);
$this->assertTrue($member->FirstName == 'Sebastian');
$user = User::where('identifier','=','sebastian.marcet')->first();
$service = App::make(OpenIdServiceCatalog::UserService);
$service->lockUser($user->id);
}
public function testUserNameGeneration(){
$generator = new UserNameGeneratorService();
$member6 = Member::findOrFail(6);
$member7 = Member::findOrFail(7);
$member8 = Member::findOrFail(8);
$member9 = Member::findOrFail(9);
$id6 = $generator->generate($member6);
$this->assertTrue( $id6 == 'bharath.kumar.m.r');
$id7 = $generator->generate($member7);
$this->assertTrue( $id7 == 'yuanying');
$id8 = $generator->generate($member8);
$this->assertTrue( $id8 == 'sebastian.german.marcet.gomez');
$id9 = $generator->generate($member9);
$this->assertTrue( $id9 == 'ian.y.choi');
}
}

View File

@ -1,8 +1,9 @@
<?php
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\TableNode;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Models\OAuth2\Client;
use Illuminate\Support\Facades\Session;
/**
* Defines application features from the specific context.
*/
@ -34,7 +35,8 @@ class FeatureContext extends LaravelContext
*/
public function exitsClientId($client_id)
{
$client = Client::where('client_id', '=', $client_id)->first();
$client = EntityManager::getRepository(Client::class)->findOneBy(['client_id' => $client_id]);
if(is_null($client))
throw new Exception(sprintf('client id %s does not exist', $client_id));
}