mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for Tests, implement MakeHash trait (#2469)
* Fixes for Feature and browser tests * Change .env.example variable names, implement hash encoding of db numbers for URIs
This commit is contained in:
parent
dffafc20af
commit
849f6e5439
@ -1,7 +1,7 @@
|
||||
APP_ENV=local
|
||||
APP_DEBUG=true
|
||||
APP_LOCALE=en
|
||||
APP_URL=http://ninja.test:8000
|
||||
APP_URL=http://127.0.0.1:8000
|
||||
APP_KEY=s7epnjtomsdond5zgfqgaqmwhhcjct02
|
||||
APP_CIPHER=AES-256-CBC
|
||||
REQUIRE_HTTPS=false
|
||||
@ -13,8 +13,9 @@ DB_HOST=localhost
|
||||
DB_USERNAME=ninja
|
||||
DB_PASSWORD=ninja
|
||||
|
||||
DB_DATABASE1=ninja1
|
||||
DB_DATABASE2=ninja2
|
||||
DB_CONNECTION=db-ninja-01
|
||||
DB_DATABASE1=db-ninja-01
|
||||
DB_DATABASE2=db-ninja-02
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_PORT=587
|
||||
MAIL_ENCRYPTION=tls
|
||||
|
18
.env.example
18
.env.example
@ -1,19 +1,19 @@
|
||||
APP_NAME=Laravel
|
||||
APP_NAME="Invoice Ninja"
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=homestead
|
||||
DB_USERNAME=homestead
|
||||
DB_PASSWORD=secret
|
||||
DB_CONNECTION=db-ninja-01
|
||||
DB_HOST1=127.0.0.1
|
||||
DB_PORT1=3306
|
||||
DB_DATABASE1=homestead
|
||||
DB_USERNAME1=homestead
|
||||
DB_PASSWORD1=secret
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
LOG_CHANNEL=stack
|
||||
CACHE_DRIVER=file
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
|
@ -5,6 +5,7 @@ namespace App\Jobs\Company;
|
||||
use App\Events\Company\CompanyCreated;
|
||||
use App\Events\UserSignedUp;
|
||||
use App\Jobs\Account\CreateAccount;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Account;
|
||||
@ -15,7 +16,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class CreateCompany
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use Dispatchable;
|
||||
|
||||
protected $request;
|
||||
@ -45,7 +46,7 @@ class CreateCompany
|
||||
$company = new Company();
|
||||
$company->name = $this->request->first_name . ' ' . $this->request->last_name;
|
||||
$company->account_id = $this->account->id;
|
||||
$company->company_key = strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
$company->company_key = $this->createHash();
|
||||
$company->ip = $this->request->ip();
|
||||
$company->save();
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace App\Jobs\User;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserCompany;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Account;
|
||||
@ -11,7 +12,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class CreateUser
|
||||
{
|
||||
|
||||
use MakesHash;
|
||||
use Dispatchable;
|
||||
|
||||
protected $request;
|
||||
@ -45,7 +46,7 @@ class CreateUser
|
||||
$user->account_id = $this->account->id;
|
||||
$user->password = bcrypt($this->request->input('password'));
|
||||
$user->accepted_terms_version = config('ninja.terms_version');
|
||||
$user->confirmation_code = strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
$user->confirmation_code = $this->createDbHash(config('database.default'));
|
||||
$user->db = config('database.default');
|
||||
$user->fill($this->request->all());
|
||||
$user->save();
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Laravel\Telescope\EntryType;
|
||||
use Laravel\Telescope\Telescope;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Telescope\IncomingEntry;
|
||||
use Laravel\Telescope\Contracts\EntriesRepository;
|
||||
use Laravel\Telescope\TelescopeApplicationServiceProvider;
|
||||
|
||||
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Telescope::night();
|
||||
|
||||
Telescope::filter(function (IncomingEntry $entry) {
|
||||
if ($this->app->environment() == 'local') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $entry->isReportableException() ||
|
||||
$entry->isFailedJob() ||
|
||||
$entry->isScheduledTask() ||
|
||||
$entry->hasMonitoredTag();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Telescope gate.
|
||||
*
|
||||
* This gate determines who can access Telescope in non-local environments.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function gate()
|
||||
{
|
||||
Gate::define('viewTelescope', function ($user) {
|
||||
return in_array($user->email, [
|
||||
config('ninja.contact.email'),
|
||||
'turbo124@gmail.com'
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
43
app/Utils/Traits/MakesHash.php
Normal file
43
app/Utils/Traits/MakesHash.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Traits;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use Hashids\Hashids;
|
||||
|
||||
/**
|
||||
* Class MakesHash
|
||||
* @package App\Utils\Traits
|
||||
*/
|
||||
trait MakesHash
|
||||
{
|
||||
/**
|
||||
* Creates a simple alphanumeric Hash
|
||||
* @return string - asd89f7as89df6asf78as6fds
|
||||
*/
|
||||
public function createHash() : string
|
||||
{
|
||||
return strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a simple alphanumeric Hash which is prepended with a encoded database prefix
|
||||
* @param $db - Full database name
|
||||
* @return string 01-asfas8df76a78f6a78dfsdf
|
||||
*/
|
||||
public function createDbHash($db) : string
|
||||
{
|
||||
return getDbCode($db) . '-' . strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $db - Full database name
|
||||
* @return string - hashed and encoded int 01,02,03,04
|
||||
*/
|
||||
public function getDbCode($db) : string
|
||||
{
|
||||
$hashids = new Hashids();
|
||||
|
||||
return $hashids->encode( str_replace( MultiDB::DB_PREFIX, "", $db ) );
|
||||
}
|
||||
}
|
@ -26,7 +26,6 @@
|
||||
"laracasts/presenter": "^0.2.1",
|
||||
"laravel/framework": "5.7.*",
|
||||
"laravel/socialite": "^3.1",
|
||||
"laravel/telescope": "^0.1.1",
|
||||
"laravel/tinker": "^1.0",
|
||||
"nwidart/laravel-modules": "^4.0",
|
||||
"predis/predis": "^1.1",
|
||||
|
113
composer.lock
generated
113
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "8f50fadc77133971d60134045427a805",
|
||||
"content-hash": "f070f7f4ccfe346840e4dfd0e39650a5",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asgrim/ofxparser",
|
||||
@ -1066,68 +1066,6 @@
|
||||
],
|
||||
"time": "2018-10-18T03:39:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/telescope",
|
||||
"version": "v0.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/telescope.git",
|
||||
"reference": "253dde9a80d50e90c7f9d4d6621151acf556d1a1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/telescope/zipball/253dde9a80d50e90c7f9d4d6621151acf556d1a1",
|
||||
"reference": "253dde9a80d50e90c7f9d4d6621151acf556d1a1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"laravel/framework": "~5.7.7",
|
||||
"moontoast/math": "^1.1",
|
||||
"php": "^7.1.3",
|
||||
"symfony/var-dumper": "^4.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"nunomaduro/larastan": "^0.3.4"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Laravel\\Telescope\\TelescopeServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Telescope\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
},
|
||||
{
|
||||
"name": "Mohamed Said",
|
||||
"email": "mohamed@laravel.com"
|
||||
}
|
||||
],
|
||||
"description": "An elegant debug assistant for the Laravel framework.",
|
||||
"keywords": [
|
||||
"debugging",
|
||||
"laravel",
|
||||
"monitoring"
|
||||
],
|
||||
"time": "2018-10-24T11:28:33+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/tinker",
|
||||
"version": "v1.0.8",
|
||||
@ -1416,55 +1354,6 @@
|
||||
],
|
||||
"time": "2017-06-19T01:22:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "moontoast/math",
|
||||
"version": "1.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ramsey/moontoast-math.git",
|
||||
"reference": "c2792a25df5cad4ff3d760dd37078fc5b6fccc79"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ramsey/moontoast-math/zipball/c2792a25df5cad4ff3d760dd37078fc5b6fccc79",
|
||||
"reference": "c2792a25df5cad4ff3d760dd37078fc5b6fccc79",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-bcmath": "*",
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"jakub-onderka/php-parallel-lint": "^0.9.0",
|
||||
"phpunit/phpunit": "^4.7|>=5.0 <5.4",
|
||||
"satooshi/php-coveralls": "^0.6.1",
|
||||
"squizlabs/php_codesniffer": "^2.3"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Moontoast\\Math\\": "src/Moontoast/Math/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ben Ramsey",
|
||||
"email": "ben@benramsey.com",
|
||||
"homepage": "https://benramsey.com"
|
||||
}
|
||||
],
|
||||
"description": "A mathematics library, providing functionality for large numbers",
|
||||
"homepage": "https://github.com/ramsey/moontoast-math",
|
||||
"keywords": [
|
||||
"bcmath",
|
||||
"math"
|
||||
],
|
||||
"time": "2017-02-16T16:54:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "1.34.0",
|
||||
|
@ -177,7 +177,6 @@ return [
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\TelescopeServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
|
||||
],
|
||||
|
@ -39,22 +39,6 @@ return [
|
||||
'prefix' => '',
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => env('DB_STRICT', false),
|
||||
'engine' => 'InnoDB',
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
|
@ -3,10 +3,10 @@
|
||||
namespace Tests\Browser;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\DuskTestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
class CreateAccountTest extends DuskTestCase
|
||||
{
|
||||
@ -27,30 +27,21 @@ class CreateAccountTest extends DuskTestCase
|
||||
*/
|
||||
public function testCreateAValidUser()
|
||||
{
|
||||
/*
|
||||
$response = $this->post('/signup', [
|
||||
'first_name' => $this->faker->firstName(),
|
||||
'last_name' => $this->faker->lastName(),
|
||||
'terms_of_service' => 1,
|
||||
'privacy_policy' => 1,
|
||||
'email' => config('ninja.testvars.username'),
|
||||
'password' => config('ninja.testvars.password')
|
||||
]);
|
||||
DB::beginTransaction();
|
||||
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/signup')
|
||||
->type('first_name',$this->faker->firstName())
|
||||
->type('last_name', $this->faker->lastName())
|
||||
->type('email', $this->faker->email())
|
||||
->type('password', $this->faker->password(7))
|
||||
->check('terms_of_service')
|
||||
->check('privacy_policy')
|
||||
->press(trans('texts.create_account'))
|
||||
->assertPathIs('/dashboard');
|
||||
});
|
||||
|
||||
$response->assertSuccessful();
|
||||
*/
|
||||
|
||||
$this->visit('/signup')
|
||||
->type($this->faker->firstName(), 'first_name')
|
||||
->type($this->faker->lastName(), 'last_name')
|
||||
->type($this->faker->email(), 'email')
|
||||
->type($this->faker->password(7), 'password')
|
||||
->check('terms_of_service')
|
||||
->check('terms_of_service')
|
||||
->press(trans('texts.create_account'))
|
||||
->seePageIs('/dashboard');
|
||||
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class ExampleTest extends DuskTestCase
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/')
|
||||
->assertSee('Laravel');
|
||||
->assertSee('Account');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\Account;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@ -14,6 +15,11 @@ class LoginTest extends TestCase
|
||||
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testLoginFormDisplayed()
|
||||
{
|
||||
$response = $this->get('/login');
|
||||
|
Loading…
x
Reference in New Issue
Block a user