Skip to content

[8.x] Add UncompromisedVerifier facade and UncompromisedVerifierFake #37446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Illuminate/Support/Facades/UncompromisedVerifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Illuminate\Support\Facades;

use Illuminate\Contracts\Validation\UncompromisedVerifier as UncompromisedVerifierContract;
use Illuminate\Support\Testing\Fakes\UncompromisedVerifierFake;

/**
* @method static bool verify(array $data)
*
* @see \Illuminate\Validation\NotPwnedVerifier
* @see \Illuminate\Support\Testing\Fakes\UncompromisedVerifierFake
*/
class UncompromisedVerifier extends Facade
{
/**
* Replace the bound instance with a fake.
*
* @return \Illuminate\Support\Testing\Fakes\UncompromisedVerifierFake
*/
public static function fake()
{
static::swap($fake = new UncompromisedVerifierFake());

return $fake;
}

/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return UncompromisedVerifierContract::class;
}
}
19 changes: 19 additions & 0 deletions src/Illuminate/Support/Testing/Fakes/UncompromisedVerifierFake.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Illuminate\Support\Testing\Fakes;

use Illuminate\Contracts\Validation\UncompromisedVerifier;

class UncompromisedVerifierFake implements UncompromisedVerifier
{
/**
* Verify that the given data has not been compromised in data leaks.
*
* @param array $data
* @return bool
*/
public function verify($data)
{
return true;
}
}
17 changes: 17 additions & 0 deletions tests/Validation/ValidationPasswordRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Container\Container;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\UncompromisedVerifier;
use Illuminate\Translation\ArrayLoader;
use Illuminate\Translation\Translator;
use Illuminate\Validation\Rules\Password;
Expand Down Expand Up @@ -115,6 +116,22 @@ public function testUncompromised()
]);
}

public function testUncompromisedFake()
{
UncompromisedVerifier::fake();

$this->passes(Password::min(2)->uncompromised(), [
'123456',
'password',
'welcome',
'ninja',
'abc123',
'123456789',
'12345678',
'nuno',
]);
}

public function testMessagesOrder()
{
$makeRules = function () {
Expand Down