Skip to content

Commit 9d683b4

Browse files
committed
deleted middleware of rolesuper
1 parent a03d772 commit 9d683b4

35 files changed

+964
-306
lines changed

composer.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
"email": "[email protected]"
1616
}],
1717
"minimum-stability": "dev",
18-
"require": {},
18+
"require": {
19+
"tymon/jwt-auth": "1.0.0-rc.3"
20+
},
1921
"require-dev": {
2022
"phpunit/phpunit": "^7.4@dev",
2123
"mockery/mockery": "^1.0@dev",
22-
"orchestra/testbench": "^3.8@dev",
23-
"orchestra/database": "^3.8@dev",
24-
"illuminate/support": "^5.8@dev",
24+
"orchestra/testbench": "^3.7@dev",
25+
"orchestra/database": "^3.7@dev",
26+
"illuminate/support": "^5.7@dev",
2527
"fzaninotto/faker": "^1.9@dev"
2628
},
2729
"autoload": {
@@ -31,7 +33,7 @@
3133
},
3234
"autoload-dev": {
3335
"psr-4": {
34-
"Bitfumes\\Multiauth\\Tests\\":"tests/"
36+
"Bitfumes\\Multiauth\\Tests\\": "tests/"
3537
}
3638
},
3739
"extra": {
@@ -40,5 +42,10 @@
4042
"Bitfumes\\Multiauth\\MultiauthServiceProvider"
4143
]
4244
}
45+
},
46+
"config": {
47+
"preferred-install": "dist",
48+
"sort-packages": true,
49+
"optimize-autoloader": true
4350
}
4451
}

config/auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
return [
44
'guards' => [
55
'admin' => [
6-
'driver' => 'session',
6+
'driver' => 'jwt',
77
'provider' => 'admins',
88
],
99
],
File renamed without changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Bitfumes\Multiauth\Tests\Feature;
4+
5+
use Bitfumes\Multiauth\Model\Admin;
6+
use Bitfumes\Multiauth\Tests\TestCase;
7+
use Illuminate\Foundation\Testing\DatabaseMigrations;
8+
9+
class AdminValidationTest extends TestCase
10+
{
11+
use DatabaseMigrations;
12+
13+
public function setup()
14+
{
15+
parent::setUp();
16+
$this->withExceptionHandling();
17+
}
18+
19+
/**
20+
* @test
21+
*/
22+
public function admin_mode_need_name()
23+
{
24+
$this->loginSuperAdmin();
25+
$response = $this->post(route('admin.register'), [
26+
'email' => '[email protected]',
27+
'password' => 'secret',
28+
'password_confirmation' => 'secret',
29+
]);
30+
$response->assertSessionHasErrors('name');
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function admin_mode_need_email()
37+
{
38+
$this->loginSuperAdmin();
39+
$response = $this->post(route('admin.register'), [
40+
'name' => 'sarthak',
41+
'password' => 'secret',
42+
'password_confirmation' => 'secret',
43+
]);
44+
$response->assertSessionHasErrors('email');
45+
}
46+
47+
/**
48+
* @test
49+
*/
50+
public function admin_mode_need_password_confirmation()
51+
{
52+
$this->loginSuperAdmin();
53+
$response = $this->post(route('admin.register'), [
54+
'name' => 'sarthak',
55+
'email' => '[email protected]',
56+
'password' => 'secret',
57+
'password_confirmation' => 'differentPassword',
58+
]);
59+
$response->assertSessionHasErrors('password');
60+
}
61+
62+
/**
63+
* @test
64+
*/
65+
public function admin_mode_need_rules()
66+
{
67+
$this->loginSuperAdmin();
68+
$response = $this->post(route('admin.register'), [
69+
'name' => 'sarthak',
70+
'email' => '[email protected]',
71+
'password' => 'secret',
72+
'password_confirmation' => 'secret',
73+
]);
74+
$response->assertSessionHasErrors('role_id');
75+
}
76+
77+
/**
78+
* @test
79+
*/
80+
public function while_update_admin_mode_need_validation()
81+
{
82+
$this->loginSuperAdmin();
83+
$admin = $this->createAdmin();
84+
$response = $this->patch(route('admin.update', $admin->id), []);
85+
$response->assertSessionHasErrors(['role_id', 'email', 'name']);
86+
}
87+
}

oldtests/Feature/AttachRoleTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Bitfumes\Multiauth\Tests\Feature;
4+
5+
use Bitfumes\Multiauth\Model\Role;
6+
use Bitfumes\Multiauth\Tests\TestCase;
7+
use Illuminate\Foundation\Testing\DatabaseMigrations;
8+
9+
class AttachRoleTest extends TestCase
10+
{
11+
use DatabaseMigrations;
12+
public $super;
13+
public $editorRole;
14+
15+
public function setup()
16+
{
17+
parent::setUp();
18+
$this->super = $this->loginSuperAdmin();
19+
$this->editorRole = factory(Role::class)->create(['name' => 'editor']);
20+
}
21+
22+
/**
23+
* @test
24+
*/
25+
public function a_super_admin_can_attach_roles_to_admin()
26+
{
27+
$admin = $this->createAdmin();
28+
$this->get(route('admin.role.create'));
29+
$this->post(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id]));
30+
$this->assertEquals($admin->roles()->pluck('name')[0], 'editor');
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function a_non_super_admin_can_not_attach__roles_to_admin()
37+
{
38+
$this->logInAdmin();
39+
$admin = $this->createAdmin();
40+
$this->post(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id]))
41+
->assertStatus(302)
42+
->assertRedirect('/admin/home');
43+
}
44+
45+
/**
46+
* @test
47+
*/
48+
public function a_super_user_can_detach_role_for_an_admin()
49+
{
50+
$admin = $this->createAdmin();
51+
$this->post(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id]));
52+
$this->assertEquals($admin->roles[0]->id, $this->editorRole->id);
53+
$this->delete(route('admin.attach.roles', ['admin' => $admin->id, 'role' => $this->editorRole->id]));
54+
$this->assertEmpty($admin->fresh()->roles()->count());
55+
}
56+
}

oldtests/Feature/CommandsTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Bitfumes\Multiauth\Tests\Feature;
4+
5+
use Bitfumes\Multiauth\Tests\TestCase;
6+
use Illuminate\Foundation\Testing\DatabaseMigrations;
7+
8+
class CommandsTest extends TestCase
9+
{
10+
use DatabaseMigrations;
11+
12+
/** @test */
13+
public function a_seed_command_can_publish_new_super_admin()
14+
{
15+
$this->artisan('multiauth:seed', ['--role'=>'super']);
16+
$this->assertDatabaseHas('admins', ['email'=>'[email protected]']);
17+
}
18+
}

oldtests/Feature/LoginTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Bitfumes\Multiauth\Tests\Feature;
4+
5+
use Bitfumes\Multiauth\Model\Admin;
6+
use Bitfumes\Multiauth\Tests\TestCase;
7+
use Illuminate\Foundation\Testing\DatabaseMigrations;
8+
9+
class LoginTest extends TestCase
10+
{
11+
use DatabaseMigrations;
12+
13+
/**
14+
* @test
15+
*/
16+
public function a_user_can_see_admin_login_form()
17+
{
18+
$this->get(route('admin.login'))->assertSee('password');
19+
}
20+
21+
/**
22+
* @test
23+
*/
24+
public function a_user_can_login_and_redirected_to_admin_home()
25+
{
26+
$admin = $this->createAdmin();
27+
$this->post(route('admin.login'), ['email' => $admin->email, 'password' => 'secret'])
28+
->assertRedirect(route('admin.home'));
29+
}
30+
31+
/**
32+
* @test
33+
*/
34+
public function logged_in_admin_can_not_see_admin_login_page()
35+
{
36+
$this->logInAdmin();
37+
$this->get(route('admin.login'))->assertRedirect(route('admin.home'));
38+
}
39+
40+
/**
41+
* @test
42+
*/
43+
// public function un_authenticated_admin_can_not_see_admin_home_page()
44+
// {
45+
// $this->withExceptionHandling();
46+
// $this->get('/admin/home')->assertRedirect('/admin');
47+
// }
48+
49+
/**
50+
* @test
51+
*/
52+
public function after_logout_admin_is_redirected_to_admin_login_page()
53+
{
54+
$this->logInAdmin();
55+
$this->post(route('admin.logout'))->assertRedirect(route('admin.login'));
56+
}
57+
}
File renamed without changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace Bitfumes\Multiauth\Tests\Feature;
4+
5+
use Bitfumes\Multiauth\Notifications\AdminResetPasswordNotification;
6+
use Bitfumes\Multiauth\Tests\TestCase;
7+
use Illuminate\Foundation\Testing\DatabaseMigrations;
8+
use Illuminate\Support\Facades\Hash;
9+
use Illuminate\Support\Facades\Notification;
10+
11+
class ResetPasswordTest extends TestCase
12+
{
13+
use DatabaseMigrations;
14+
15+
/**
16+
* @test
17+
*/
18+
public function a_admin_can_see_forgot_password_form()
19+
{
20+
$this->get(route('admin.password.request'))->assertStatus(200);
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function a_password_reset_link_email_can_be_sent()
27+
{
28+
Notification::fake();
29+
$admin = $this->createAdmin();
30+
$this->post(route('admin.password.email'), ['email' => $admin->email]);
31+
Notification::assertSentTo([$admin], AdminResetPasswordNotification::class);
32+
}
33+
34+
/**
35+
* @test
36+
*/
37+
public function an_admin_can_see_reset_password_form()
38+
{
39+
$this->get(route('admin.password.reset', 'anytoken'))->assertStatus(200);
40+
}
41+
42+
/** @test */
43+
public function an_admin_can_change_its_password()
44+
{
45+
Notification::fake();
46+
$admin = $this->createAdmin();
47+
$this->post(route('admin.password.email'), ['email' => $admin->email]);
48+
Notification::assertSentTo([$admin], AdminResetPasswordNotification::class, function ($notification) use ($admin) {
49+
$token = $notification->token;
50+
$this->assertTrue(Hash::check('secret', $admin->password));
51+
$res = $this->post(route('admin.password.request'), [
52+
'email' => $admin->email,
53+
'password' => 'newpassword',
54+
'password_confirmation' => 'newpassword',
55+
'token' => $token,
56+
]);
57+
58+
$this->assertTrue(Hash::check('newpassword', $admin->fresh()->password));
59+
60+
return true;
61+
});
62+
}
63+
64+
/** @test */
65+
public function admin_can_visit_change_password_page()
66+
{
67+
$admin = $this->logInAdmin();
68+
$this->get(route('admin.password.change'))
69+
->assertOk()
70+
->assertSee('Old Password');
71+
}
72+
73+
/** @test */
74+
public function admin_can_change_password_after_login()
75+
{
76+
$admin = $this->logInAdmin();
77+
$this->post(route('admin.password.change'), [
78+
'oldPassword' => 'secret',
79+
'password' => '123456',
80+
'password_confirmation' => '123456'
81+
])
82+
->assertRedirect(route('admin.home'))
83+
->assertSessionHas('message');
84+
$this->assertTrue(Hash::check('123456', $admin->fresh()->password));
85+
}
86+
}

0 commit comments

Comments
 (0)