-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from DnD-Montreal/240-Implement-performance-t…
…ests Implement performance tests
- Loading branch information
Showing
7 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\User; | ||
use App\Models\Character; | ||
use Illuminate\Http\Request; | ||
|
||
use Illuminate\Support\Facades\App; | ||
|
||
|
||
use Laravel\Sanctum\HasApiTokens; | ||
|
||
class LocustAuthController extends Controller | ||
{ | ||
use HasApiTokens; | ||
|
||
public function getToken(Request $request) | ||
{ | ||
if ($request->bearerToken() == config('app.key') && App::environment('load')) { | ||
$user = User::where('password', 'DOESNTMATTER')->get(); | ||
$token = $user->first()->createToken('bearer')->plainTextToken; | ||
|
||
return [ | ||
'token' => $token | ||
]; | ||
} | ||
} | ||
|
||
public function deleteCharacters() | ||
{ | ||
if (App::environment('load')) { | ||
$user = User::where('password', 'DOESNTMATTER')->get(); | ||
|
||
if ($user->first()->email == '[email protected]') { | ||
$characters = Character::where('user_id', $user->first()->id); | ||
$characters->delete(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Middleware\ThrottleRequests; | ||
use Illuminate\Support\Facades\App; | ||
|
||
class Throttle extends ThrottleRequests | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1, $prefix = '') | ||
{ | ||
if (App::environment('load')) { | ||
return $next($request); | ||
} else { | ||
return parent::handle($request, $next, $maxAttempts, $decayMinutes, $prefix); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/Feature/Http/Controllers/LocustAuthControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Http\Controllers; | ||
|
||
use Tests\TestCase; | ||
|
||
class LocustAuthControllerTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function test_get_token() | ||
{ | ||
$token = config('app.key'); | ||
|
||
app()->detectEnvironment(function () { | ||
return 'load'; | ||
}); | ||
|
||
$this->withHeaders(['Authorization' => 'Bearer '.$token])->get(route('character.index')); | ||
$response = $this->withHeaders(['Authorization' => 'Bearer '.$token])->get('api/locust'); | ||
|
||
$response->assertStatus(200); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function test_delete_characters_with_locust_api_key() | ||
{ | ||
$token = config('app.key'); | ||
|
||
app()->detectEnvironment(function () { | ||
return 'load'; | ||
}); | ||
|
||
$this->withHeaders(['Authorization' => 'Bearer '.$token])->get(route('character.index')); | ||
$response = $this->withHeaders(['Authorization' => 'Bearer '.$token])->delete('api/locust'); | ||
|
||
$response->assertStatus(200); | ||
} | ||
} |