Skip to content

Commit

Permalink
Merge pull request #21 from leroy-merlin-br/chore/update-mongolid-ver…
Browse files Browse the repository at this point in the history
…sion-3

Update mongolid version 3
  • Loading branch information
ezandonai authored Sep 15, 2022
2 parents b6020b5 + 54029aa commit 9b59242
Show file tree
Hide file tree
Showing 18 changed files with 434 additions and 428 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<p align="center">
<STYLE type="text/css">
P {text-align: center}
</STYLE>
<p>
<a href="https://github.com/leroy-merlin-br/mongolid-passport/actions?query=workflow%3ATests"><img src="https://github.com/leroy-merlin-br/mongolid-passport/workflows/Tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/leroy-merlin-br/mongolid-passport"><img src="https://poser.pugx.org/leroy-merlin-br/mongolid-passport/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/leroy-merlin-br/mongolid-passport"><img src="https://poser.pugx.org/leroy-merlin-br/mongolid-passport/v/stable.svg" alt="Latest Stable Version"></a>
Expand All @@ -16,13 +19,13 @@ Documentation for Passport can be found on the [Laravel website](https://laravel

## Compatibility

| mongolid-passport | laravel-passport | mongolid-laravel | mongolid |
|-------------------|------------------|------------------|------------|
| 11.0.0-beta | 10.1.1 | 3.0.0-beta | 4.0.0-beta |
| 10.x | 10.x | 2.3.x | 2.4.x |
| 9.x | 9.x | 2.2.x | 2.3.x |
| 8.x | 8.x | 2.2.x | 2.2.x |
| 7.x | 7.x | 2.2.x | 2.2.x |
| mongolid-passport | laravel-passport | mongolid-laravel | mongolid |
|-------------------|------------------|------------------|----------|
| 11.0.0 | 10.1.1 | 3.0.0 | 3.1.0 |
| 10.x | 10.x | 2.3.x | 2.4.x |
| 9.x | 9.x | 2.2.x | 2.3.x |
| 8.x | 8.x | 2.2.x | 2.2.x |
| 7.x | 7.x | 2.2.x | 2.2.x |

[Here](docs/upgrade/upgrade-guide.md) you find guides to upgrade versions.

Expand Down
763 changes: 388 additions & 375 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/AuthCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport;

use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class AuthCode extends Model
{
Expand All @@ -13,8 +13,6 @@ class AuthCode extends Model

/**
* Get the client that owns the authentication code.
*
* @return Client|null
*/
public function client()
{
Expand Down
22 changes: 11 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Passport;

use Mongolid\Util\LocalDateTime;
use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class Client extends Model
{
Expand Down Expand Up @@ -54,8 +54,6 @@ class Client extends Model

/**
* Get the user that the client belongs to.
*
* @return \Mongolid\ActiveRecord
*/
public function user()
{
Expand All @@ -70,7 +68,7 @@ public function user()
/**
* Get all of the authentication codes for the client.
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function authCodes()
{
Expand All @@ -84,7 +82,7 @@ public function authCodes()
*
* @param array $query
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function tokens(array $query = [])
{
Expand All @@ -111,19 +109,21 @@ public function getPlainSecretAttribute()
* Set the value of the secret attribute.
*
* @param string|null $value
* @return void
*/
public function setSecretAttribute($value)
public function setSecretAttribute($value): string
{
$this->plainSecret = $value;

if (is_null($value) || ! Passport::$hashesClientSecrets) {
$this->secret = $value;
return $value;
}

return;
if (password_get_info($value)['algoName'] === PASSWORD_BCRYPT) {
return $value;
}

$this->secret = password_hash($value, PASSWORD_BCRYPT);

return password_hash($value, PASSWORD_BCRYPT);
}

/**
Expand Down Expand Up @@ -159,7 +159,7 @@ public function confidential()
/**
* {@inheritdoc}
*/
public function toArray()
public function toArray(): array
{
return [
'id' => (string) $this->_id,
Expand Down
2 changes: 1 addition & 1 deletion src/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function findForUser($clientId, $userId)
*
* @param mixed $userId
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function forUser($userId)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Console/HashCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public function handle()
continue;
}

$client->fill([
'secret' => $client->secret,
], true);
$client->setSecretAttribute($client->secret);
$client->save();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/PurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Carbon;
use Laravel\Passport\Passport;
use MongoDB\BSON\UTCDateTime;
use Mongolid\Cursor\Cursor;
use Mongolid\Cursor\CursorInterface;

class PurgeCommand extends Command
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public function handle()
$this->info($message);
}

protected function purgeTokens(Cursor $tokens)
protected function purgeTokens(CursorInterface $tokens)
{
foreach ($tokens as $token) {
$token->delete();
Expand Down
4 changes: 2 additions & 2 deletions src/HasApiTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait HasApiTokens
/**
* Get all of the user's registered OAuth clients.
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function clients()
{
Expand All @@ -26,7 +26,7 @@ public function clients()
/**
* Get all of the access tokens for the user.
*
* @return \Mongolid\Cursor\Cursor
* @return \Mongolid\Cursor\CursorInterface
*/
public function tokens()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthorizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function parseScopes($authRequest)
* Approve the authorization request.
*
* @param \League\OAuth2\Server\RequestTypes\AuthorizationRequest $authRequest
* @param \MongolidLaravel\MongolidModel $user
* @param \MongolidLaravel\LegacyMongolidModel $user
* @return \Illuminate\Http\Response
*/
protected function approveRequest($authRequest, $user)
Expand Down
4 changes: 1 addition & 3 deletions src/PersonalAccessClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport;

use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class PersonalAccessClient extends Model
{
Expand All @@ -13,8 +13,6 @@ class PersonalAccessClient extends Model

/**
* Get all of the authentication codes for the client.
*
* @return Client|null
*/
public function client()
{
Expand Down
4 changes: 1 addition & 3 deletions src/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Laravel\Passport;

use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class RefreshToken extends Model
{
Expand All @@ -19,8 +19,6 @@ class RefreshToken extends Model

/**
* Get the access token that the refresh token belongs to.
*
* @return \Mongolid\ActiveRecord|null
*/
public function accessToken()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Laravel\Passport;

use Illuminate\Contracts\Auth\Authenticatable;
use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class Token extends Model
{
Expand Down
9 changes: 5 additions & 4 deletions src/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Laravel\Passport;

use MongoDB\BSON\UTCDateTime;
use MongolidLaravel\MongolidModel as Model;
use Mongolid\Cursor\CursorInterface;
use Mongolid\Model\ModelInterface;

class TokenRepository
{
Expand Down Expand Up @@ -57,7 +58,7 @@ public function findForUser($id, $userId)
*
* @param mixed $userId
*
* @return \Mongolid\Cursor\Cursor
* @return CursorInterface
*/
public function forUser($userId)
{
Expand All @@ -69,7 +70,7 @@ public function forUser($userId)
/**
* Get a valid token instance for the given user and client.
*
* @param Model $user
* @param ModelInterface $user
* @param \Laravel\Passport\Client $client
*
* @return \Laravel\Passport\Token|null
Expand Down Expand Up @@ -133,7 +134,7 @@ public function isAccessTokenRevoked($id)
/**
* Find a valid token for the given user and client.
*
* @param Model $user
* @param ModelInterface $user
* @param \Laravel\Passport\Client $client
*
* @return \Laravel\Passport\Token|null
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
use Lcobucci\JWT\Configuration;
use MongolidLaravel\MongolidModel as Model;
use MongolidLaravel\LegacyMongolidModel as Model;

class AccessTokenControllerTest extends PassportTestCase
{
Expand Down
5 changes: 1 addition & 4 deletions tests/Feature/Console/HashCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Passport\Tests\Feature\Console;

use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Support\Str;
use Laravel\Passport\Client;
use Laravel\Passport\Passport;
Expand All @@ -23,13 +22,11 @@ public function test_it_can_properly_hash_client_secrets()
'revoked' => false,
]);
$client->save();
$hasher = $this->app->make(Hasher::class);

Passport::hashClientSecrets();

$this->artisan('passport:hash', ['--force' => true]);

$this->assertTrue($hasher->check($secret, $client->first()->secret));
$this->assertTrue(password_verify($secret, $client->first()->secret));

Passport::$hashesClientSecrets = false;
}
Expand Down
9 changes: 4 additions & 5 deletions tests/Feature/DropDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Passport\Tests\Feature;

use Mongolid\Connection\Pool;
use Mongolid\Connection\Connection;

trait DropDatabase
{
Expand All @@ -13,10 +13,9 @@ trait DropDatabase
*/
public function dropDatabase()
{
$pool = app(Pool::class);
$connection = app(Connection::class);

$pool->getConnection()
->getRawConnection()
->dropDatabase($pool->getConnection()->defaultDatabase);
$connection->getClient()
->dropDatabase($connection->defaultDatabase);
}
}
2 changes: 2 additions & 0 deletions tests/Unit/CheckClientCredentialsForAnyScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function test_request_is_passed_along_if_token_is_valid()
$token = m::mock(Token::class);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['*']);
$token->shouldReceive('getAttribute')->with('client')->andReturn($client);
$token->shouldReceive('getAttribute')->with('scopes')->andReturn(['*']);

$tokenRepository = m::mock(TokenRepository::class);
$tokenRepository->shouldReceive('find')->with('token')->andReturn($token);
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/PersonalAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Laravel\Passport\TokenRepository;
use Mockery as m;
use MongoDB\BSON\ObjectId;
use Mongolid\Cursor\Cursor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;

Expand Down

0 comments on commit 9b59242

Please sign in to comment.