|
4 | 4 |
|
5 | 5 | use Mockery as m; |
6 | 6 | use Cake\Chronos\Chronos; |
| 7 | +use Pterodactyl\Models\User; |
7 | 8 | use Pterodactyl\Models\ApiKey; |
8 | 9 | use Illuminate\Auth\AuthManager; |
9 | 10 | use Illuminate\Contracts\Encryption\Encrypter; |
@@ -48,6 +49,7 @@ public function setUp() |
48 | 49 | */ |
49 | 50 | public function testMissingBearerTokenThrowsException() |
50 | 51 | { |
| 52 | + $this->request->shouldReceive('user')->andReturnNull(); |
51 | 53 | $this->request->shouldReceive('bearerToken')->withNoArgs()->once()->andReturnNull(); |
52 | 54 |
|
53 | 55 | try { |
@@ -117,6 +119,25 @@ public function testValidTokenWithUserKey() |
117 | 119 | $this->assertEquals($model, $this->request->attributes->get('api_key')); |
118 | 120 | } |
119 | 121 |
|
| 122 | + /** |
| 123 | + * Test that we can still make it though this middleware if the user is logged in and passing |
| 124 | + * through a cookie. |
| 125 | + */ |
| 126 | + public function testAccessWithoutToken() |
| 127 | + { |
| 128 | + $user = factory(User::class)->make(['id' => 123]); |
| 129 | + |
| 130 | + $this->request->shouldReceive('user')->andReturn($user); |
| 131 | + $this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturnNull(); |
| 132 | + |
| 133 | + $this->getMiddleware()->handle($this->request, $this->getClosureAssertions(), ApiKey::TYPE_ACCOUNT); |
| 134 | + $model = $this->request->attributes->get('api_key'); |
| 135 | + |
| 136 | + $this->assertSame(ApiKey::TYPE_ACCOUNT, $model->key_type); |
| 137 | + $this->assertSame(123, $model->user_id); |
| 138 | + $this->assertNull($model->identifier); |
| 139 | + } |
| 140 | + |
120 | 141 | /** |
121 | 142 | * Test that a valid token identifier with an invalid token attached to it |
122 | 143 | * triggers an exception. |
|
0 commit comments