Skip to content

Commit

Permalink
Merge pull request #7 from BRACKETS-by-TRIAD/release-v2.0
Browse files Browse the repository at this point in the history
Added route auth guard and also fixed tests
  • Loading branch information
dejwCake authored Jan 18, 2019
2 parents b5ef31b + c9dc585 commit cc69f56
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"require": {
"php" : "^7.0",
"illuminate/support": "5.5.*|5.6.*|5.7.*",
"brackets/admin-auth": "^3.0",
"spatie/laravel-medialibrary": "^6.0"
},
"require-dev": {
Expand All @@ -57,7 +58,7 @@
]
},
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "2.0-dev"
}
}
}
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

Route::middleware(['web'])->group(function () {
Route::middleware(['web', 'auth:' . config('admin-auth.defaults.guard'), 'admin'])->group(function () {
Route::namespace('Brackets\Media\Http\Controllers')->group(function () {
Route::post('upload', 'FileUploadController@upload')->name('brackets/media::upload');
Route::get('view', 'FileViewController@view')->name('brackets/media::view');
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/HasMediaCollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ public function not_authorized_user_can_get_public_media()
/** @test */
public function not_authorized_user_cannot_get_protected_media()
{
$this->disableAuthorization();
$this->assertCount(0, $this->testModelWithCollections->getMedia('documents'));

$request = $this->getRequest([
Expand All @@ -461,7 +462,7 @@ public function not_authorized_user_cannot_get_protected_media()

$this->assertCount(1, $media);

$response = $this->call('GET', $media->first()->getUrl());
$response = $this->json('GET', $media->first()->getUrl());

$response->assertStatus(403);
}
Expand Down
47 changes: 39 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Exceptions\Handler;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Gate;
Expand All @@ -15,6 +16,8 @@

abstract class TestCase extends Orchestra
{
use RefreshDatabase;

/** @var \Brackets\Media\Test\TestModel */
protected $testModel;

Expand Down Expand Up @@ -62,7 +65,8 @@ protected function getPackageProviders($app)
{
return [
\Spatie\MediaLibrary\MediaLibraryServiceProvider::class,
\Brackets\Media\MediaServiceProvider::class
\Brackets\Media\MediaServiceProvider::class,
\Brackets\AdminAuth\AdminAuthServiceProvider::class
];
}

Expand All @@ -73,12 +77,28 @@ protected function getEnvironmentSetUp($app)
{
$this->initializeDirectory($this->getTempDirectory());

$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
if (env('DB_CONNECTION') === 'pgsql') {
$app['config']->set('database.default', 'pgsql');
$app['config']->set('database.connections.pgsql', [
'driver' => 'pgsql',
'host' => 'testing',
'port' => '5432',
'database' => 'homestead',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]);
} else {
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}

// FIXME these config setting needs to have a look
$app['config']->set('filesystems.disks.media', [
Expand Down Expand Up @@ -119,6 +139,16 @@ protected function getEnvironmentSetUp($app)
});

$app['config']->set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm');

$app['config']->set('admin-auth.defaults.guard', 'admin');
$app['config']->set('auth.guards.admin', [
'driver' => 'session',
'provider' => 'admin_users',
]);
$app['config']->set('auth.providers.admin_users', [
'driver' => 'eloquent',
'model' => \Brackets\AdminAuth\Models\AdminUser::class,
]);
}

/**
Expand Down Expand Up @@ -178,7 +208,8 @@ public function getTestFilesDirectory($suffix = '')

public function disableAuthorization()
{
$this->actingAs(new User);
$this->actingAs(new User, 'admin');
Gate::define('admin', function ($user) { return true; });
Gate::define('admin.upload', function ($user) { return true; });
}

Expand Down

0 comments on commit cc69f56

Please sign in to comment.