Add nami guard

This commit is contained in:
philipp lang 2021-06-18 23:36:06 +02:00
parent b5f3daff63
commit 56332395d9
8 changed files with 494 additions and 301 deletions

View File

@ -7,13 +7,11 @@
"laravel"
],
"repositories": [
{ "type": "path", "url": "./packages/laravel-nami", "options": {"symlink": true} },
{ "type": "path", "url": "./packages/agnoster-installer", "options": {"symlink": true} }
{ "type": "path", "url": "./packages/laravel-nami", "options": {"symlink": true} }
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"aweos/agnoster-installer": "^1.0",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^7.0.1",
@ -32,7 +30,8 @@
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^9.0",
"orchestra/testbench": "^6.0"
},
"config": {
"optimize-autoloader": true,
@ -57,7 +56,8 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"Tests\\": "tests/",
"Zoomyboy\\LaravelNami\\Tests\\": "packages/laravel-nami/tests/"
}
},
"minimum-stability": "dev",

713
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -37,8 +37,7 @@ return [
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
'driver' => 'nami'
],
'api' => [

View File

@ -1,28 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\User;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/
$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
});

View File

@ -10,6 +10,9 @@
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="NamiUnit">
<directory suffix="Test.php">./packages/laravel-nami/tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">

View File

@ -9,11 +9,7 @@ use Illuminate\Support\Facades\Cache;
class LoginTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_it_stores_login_cookie()
{
$this->withoutExceptionHandling();
@ -23,13 +19,16 @@ class LoginTest extends TestCase
$this->fakeNamiPassword(123, 'secret', [11222]);
$this->post('/login', [
'groupid' => 11222,
'mglnr' => 123,
'password' => 'secret'
]);
$cache = Cache::get('namicookie-123');
$key = session()->get('auth_key');
$cache = Cache::get("namiauth-{$key}");
$this->assertEquals('JSESSIONID', data_get($cache, 'cookie.0.Name'));
$this->assertEquals('123', data_get($cache, 'data.mitgliedsnr'));
$this->assertEquals('secret', data_get($cache, 'credentials.password'));
$this->assertEquals(123, auth()->user()->mglnr);
}
}

View File

@ -17,9 +17,8 @@ class UpdateTest extends TestCase
public function test_it_can_update_a_member()
{
$this->fakeNamiMembers([
[ 'gruppierungId' => 12399, 'vorname' => 'Max', 'id' => 999 ]
]);
$this->withoutExceptionHandling();
$this->login();
$member = Member::factory()
->for(Country::factory())

View File

@ -5,6 +5,7 @@ namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Zoomyboy\LaravelNami\Nami;
use Zoomyboy\LaravelNami\FakesNami;
use Zoomyboy\LaravelNami\NamiUser;
abstract class TestCase extends BaseTestCase
{
@ -17,4 +18,23 @@ abstract class TestCase extends BaseTestCase
$this->fakeNami();
}
public function login() {
$this->fakeNamiMembers([
[ 'gruppierungId' => 12399, 'vorname' => 'Max', 'id' => 999 ]
]);
$this->fakeNamiPassword(999, 'secret', [12399]);
$api = Nami::login(999, 'secret');
$this->be(new NamiUser([
'cookie' => $api->cookie->toArray(),
'credentials' => [
'mglnr' => 999,
'password' => 'secret'
]
]));
}
}