├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── config
└── domain_verifier.php
├── database
└── migrations
│ └── 2019_08_01_000001_create_domain_verifications_table.php
├── phpcs.xml
├── phpunit.xml
├── resources
└── views
│ ├── mail.blade.php
│ ├── verification_failed.blade.php
│ └── verification_succeeded.blade.php
├── src
├── Contracts
│ ├── Models
│ │ └── DomainVerifiable.php
│ ├── Repositories
│ │ └── VerificationRepository.php
│ └── Strategies
│ │ └── VerifierStrategy.php
├── DomainVerificationFacade.php
├── DomainVerifierServiceProvider.php
├── Enums
│ └── VerifierStrategy.php
├── Factories
│ └── VerifierFactory.php
├── Http
│ ├── Controller
│ │ └── DomainVerifierController.php
│ └── routes.php
├── Mail
│ └── ActivationMail.php
├── Models
│ └── DomainVerification.php
├── Repositories
│ └── DomainVerification.php
├── Results
│ └── VerifyResult.php
├── Strategies
│ ├── BaseStrategy.php
│ ├── DNSRecord.php
│ ├── HTMLFile.php
│ ├── HTMLMeta.php
│ └── SendingMail.php
├── Supports
│ └── URL.php
├── Traits
│ └── DomainVerifiable.php
└── VerifierFactoryFacade.php
└── tests
├── .gitkeep
├── Strategies
├── DNSRecordTest.php
├── HTMLFileTest.php
├── HTMLMetaTest.php
└── StrategyTestCase.php
├── Supports
└── URLTest.php
└── TestCase.php
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies:
2 | /vendor
3 | composer.phar
4 | composer.lock
5 |
6 | # IDE/editors:
7 | .idea
8 | .vscode
9 | .phpunit.result.cache
10 |
11 | # OS:
12 | .DS_Store
13 | Thumbs.db
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Sun* Research
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # sun-asterisk/laravel-domain-verify
2 |
3 | Verify domain ownership for the Laravel application. We provide three ways to verify the domain ownership (like Google):
4 |
5 | - [x] Via domain's DNS record
6 | - [x] Via HTML tag
7 | - [x] Via HTML file
8 | - [x] Via Adminstrator's email address: `admin@domain.example`, `webmaster@domain.example`.
9 |
10 | ## Installation
11 |
12 | First, install Domain Verifier via the Composer package manager:
13 |
14 | ```bash
15 | # install this package:
16 | composer require sun-asterisk/laravel-domain-verify
17 |
18 | # create config/domain_verifier.php and:
19 | php artisan vendor:publish --provider="SunAsterisk\DomainVerifier\DomainVerifierServiceProvider"
20 |
21 | # migrate database:
22 | php artisan migrate
23 | ```
24 |
25 | ## Usage
26 |
27 | Integrate with your model.
28 |
29 | ```php
30 | = 5.6.0`
50 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sun-asterisk/laravel-domain-verify",
3 | "description": "Verify domain ownership for Laravel application",
4 | "type": "library",
5 | "license": "MIT",
6 | "require": {
7 | "php": "^7.4|^8.0",
8 | "illuminate/config": "~5.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0",
9 | "illuminate/database": "~5.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0",
10 | "illuminate/hashing": "~5.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0",
11 | "illuminate/support": "~5.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0",
12 | "nesbot/carbon": "~1.0|~2.0",
13 | "spatie/dns": "^2.5"
14 | },
15 | "require-dev": {
16 | "mockery/mockery": "^1.2",
17 | "orchestra/testbench": "^5.3",
18 | "phpunit/phpunit": "^7.5|^8.0",
19 | "sun-asterisk/coding-standard": "^0.2.1"
20 | },
21 | "autoload": {
22 | "psr-4": {
23 | "SunAsterisk\\DomainVerifier\\": "src/"
24 | }
25 | },
26 | "autoload-dev": {
27 | "psr-4": {
28 | "SunAsterisk\\DomainVerifier\\Tests\\": "tests/"
29 | }
30 | },
31 | "config": {
32 | "sort-packages": true,
33 | "allow-plugins": {
34 | "dealerdirect/phpcodesniffer-composer-installer": true
35 | }
36 | },
37 | "prefer-stable": true,
38 | "extra": {
39 | "laravel": {
40 | "providers": [
41 | "SunAsterisk\\DomainVerifier\\DomainVerifierServiceProvider"
42 | ],
43 | "aliases": {
44 | "DomainVerification": "SunAsterisk\\DomainVerifier\\DomainVerificationFacade",
45 | "VerifierFactory": "SunAsterisk\\DomainVerifier\\VerifierFactoryFacade"
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/config/domain_verifier.php:
--------------------------------------------------------------------------------
1 | env('DOMAIN_VERIFICATION_NAME', 'domain-verification'),
5 | 'base_url' => env('DOMAIN_VERIFICATION_BASE_URL', 'http://localhost'),
6 |
7 | 'mail' => [
8 | 'from' => env('DOMAIN_VERIFY_MAIL_FROM', 'noreply@example.localhost'),
9 | 'subject' => env('DOMAIN_VERIFY_MAIL_SUBJECT', 'Domain Verification'),
10 | 'view' => env('DOMAIN_VERIFY_MAIL_VIEW', 'laravel-domain-verify::mail'),
11 | ],
12 |
13 | 'page' => [
14 | 'verification_succeeded' => env(
15 | 'DOMAIN_VERIFY_VERIFICATION_SUCCEEDED_VIEW',
16 | 'laravel-domain-verify::verification_succeeded'
17 | ),
18 | 'verification_failed' => env(
19 | 'DOMAIN_VERIFY_VERIFICATION_FAILED_VIEW',
20 | 'laravel-domain-verify::verification_failed'
21 | ),
22 | ],
23 | ];
24 |
--------------------------------------------------------------------------------
/database/migrations/2019_08_01_000001_create_domain_verifications_table.php:
--------------------------------------------------------------------------------
1 | increments('id');
18 | $table->string('verifiable_type')->index();
19 | $table->integer('verifiable_id')->index();
20 | $table->string('url')->index();
21 | $table->string('token')->index();
22 | $table->string('activation_token')->index();
23 | $table->enum('status', ['pending', 'verified'])->default('pending')->index();
24 | $table->timestamp('email_sent_at')->nullable();
25 | $table->timestamp('verified_at')->nullable();
26 | $table->timestamps();
27 | });
28 | }
29 |
30 | /**
31 | * Reverse the migrations.
32 | *
33 | * @return void
34 | */
35 | public function down()
36 | {
37 | Schema::dropIfExists('domain_verifications');
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | app
4 | config
5 | database
6 | resources
7 | routes
8 | tests
9 |
10 | vendor/
11 |
12 |
13 |
14 |
15 | database/factories
16 |
17 |
18 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 | ./tests
15 |
16 |
17 |
18 |
19 | ./src
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/resources/views/mail.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Open the link below to confirm your ownership on domain {{ $domainName }}.
8 |
9 | {{ $activationUrl }}
10 |
11 |
12 |
--------------------------------------------------------------------------------
/resources/views/verification_failed.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Verification failed!
6 |
157 |
158 |
159 |
160 | Verification failed because invalid or expired activation token.
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/resources/views/verification_succeeded.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Verification succeeded!
6 |
157 |
158 |
159 |
160 | Your domain ownership is verified successfully! Thank you for using our service.
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/src/Contracts/Models/DomainVerifiable.php:
--------------------------------------------------------------------------------
1 | app->runningInConsole()) {
20 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
21 |
22 | $this->publishes([
23 | __DIR__.'/../database/migrations' => database_path('migrations'),
24 | ], 'migrations');
25 |
26 | $this->publishes([
27 | __DIR__.'/../config/domain_verifier.php' => config_path('domain_verifier.php'),
28 | ], 'config');
29 | $this->publishes([
30 | __DIR__.'/../resources/assets' => public_path('vendor/domain-verify'),
31 | ], 'public');
32 | }
33 |
34 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-domain-verify');
35 | $this->loadRoutesFrom(__DIR__.'/Http/routes.php');
36 | }
37 |
38 | /**
39 | * Register the service provider.
40 | *
41 | * @return void
42 | */
43 | public function register()
44 | {
45 | $this->app->singleton(DomainVerification::class, function (Application $app) {
46 | $connection = $app->make('db')->connection();
47 | $table = 'domain_verifications';
48 | $hasher = $app->make('hash');
49 | $hashKey = $app->make('config')->get('app.key');
50 |
51 | return new DomainVerification($connection, $table, $hasher, $hashKey);
52 | });
53 |
54 | $this->app->singleton(VerifierFactory::class, function () {
55 | return new VerifierFactory();
56 | });
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Enums/VerifierStrategy.php:
--------------------------------------------------------------------------------
1 | token;
19 |
20 | $headers = [
21 | 'Content-type' => 'text/plain',
22 | 'Content-Disposition' => sprintf('attachment; filename="%s"', $fileName),
23 | 'Content-Length' => strlen($content),
24 | ];
25 |
26 | return response()->make($content, 200, $headers);
27 | }
28 |
29 | public function verify($token)
30 | {
31 | $viewSucceeded = config('domain_verifier.page.verification_succeeded');
32 | $viewFailed = config('domain_verifier.page.verification_failed');
33 |
34 | $verifier = VerifierFactory::strategy('sending-mail');
35 | try {
36 | $result = $verifier->verifyByActivationToken($token);
37 |
38 | if ($result->isVerified()) {
39 | $verifiable = $result->getVerifiable();
40 | $record = $result->getRecord();
41 |
42 | return view($viewSucceeded);
43 | }
44 |
45 | return view($viewFailed);
46 | } catch (\Exception $exception) {
47 | Log::error($exception);
48 | return view($viewFailed);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/Http/routes.php:
--------------------------------------------------------------------------------
1 | 'SunAsterisk\DomainVerifier\Http\Controller\DomainVerifierController@getHtmlFile',
7 | 'as' => 'domain_verify.get_html_file',
8 | ]);
9 |
10 | Route::get('/domain-verify/activate/{token}', [
11 | 'uses' => 'SunAsterisk\DomainVerifier\Http\Controller\DomainVerifierController@verify',
12 | 'as' => 'domain_verify.verify',
13 | ]);
14 |
--------------------------------------------------------------------------------
/src/Mail/ActivationMail.php:
--------------------------------------------------------------------------------
1 | verifiable = $verifiable;
40 | $this->verification = $verification;
41 | $this->url = $url;
42 | $this->domainName = $domainName;
43 | $this->activationToken = $activationToken;
44 | $this->emailTo = $emailTo;
45 | }
46 |
47 | public function build()
48 | {
49 | $mailFrom = config('domain_verifier.mail.from');
50 | $mailTo = $this->emailTo.'@'.$this->domainName;
51 | $mailSubject = config('domain_verifier.mail.subject');
52 | $mailView = config('domain_verifier.mail.view');
53 | $baseUrl = config('domain_verifier.base_url');
54 |
55 | $activationUrl = $baseUrl.'/domain-verify/activate/'.$this->activationToken;
56 |
57 | return $this
58 | ->from($mailFrom)
59 | ->to($mailTo)
60 | ->subject($mailSubject)
61 | ->view($mailView)
62 | ->with([
63 | 'url' => $this->url,
64 | 'domainName' => $this->domainName,
65 | 'activationToken' => $this->activationToken,
66 | 'activationUrl' => $activationUrl,
67 | 'verifiable' => $this->verifiable,
68 | ]);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/Models/DomainVerification.php:
--------------------------------------------------------------------------------
1 | morphTo();
29 | }
30 |
31 | /**
32 | * Set verified domain
33 | *
34 | * @return DomainVerification
35 | */
36 | public function setVerified()
37 | {
38 | $this->update([
39 | 'verified_at' => now(),
40 | 'status' => 'verified',
41 | ]);
42 |
43 | return $this;
44 | }
45 |
46 | /**
47 | * Unverify domain
48 | *
49 | * @return DomainVerification
50 | */
51 | public function setNotVerified()
52 | {
53 | $this->update([
54 | 'verified_at' => null,
55 | 'status' => 'pending',
56 | ]);
57 |
58 | return $this;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Repositories/DomainVerification.php:
--------------------------------------------------------------------------------
1 | connection = $connection;
29 | $this->table = $table;
30 | $this->hasher = $hasher;
31 | $this->hashKey = $hashKey;
32 | }
33 |
34 | /**
35 | * Undocumented function
36 | *
37 | * @param string $url
38 | * @param \SunAsterisk\DomainVerifier\Contracts\Models\DomainVerifiable $verifiable
39 | * @return \SunAsterisk\DomainVerifier\Models\DomainVerification
40 | */
41 | public function firstOrCreate(string $url, DomainVerifiable $verifiable): DomainVerificationModel
42 | {
43 | return $verifiable->domainVerifications()->firstOrCreate(
44 | ['url' => $url],
45 | [
46 | 'status' => 'pending',
47 | 'token' => $this->generateToken(),
48 | 'activation_token' => $this->generateToken(),
49 | ]
50 | );
51 | }
52 |
53 | public function findByActivationToken(string $activationToken): ?DomainVerificationModel
54 | {
55 | return DomainVerificationModel::where('activation_token', $activationToken)->first();
56 | }
57 |
58 | /**
59 | * Create a new randoom token
60 | *
61 | * @return string
62 | */
63 | protected function generateToken()
64 | {
65 | return hash_hmac('sha256', Str::random(48), $this->hashKey);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/Results/VerifyResult.php:
--------------------------------------------------------------------------------
1 | domainVerifiable = $domainVerifiable;
17 | $this->url = $url;
18 | $this->record = $record;
19 | }
20 |
21 | public function getVerifiable()
22 | {
23 | return $this->domainVerifiable;
24 | }
25 |
26 | public function getRecord()
27 | {
28 | return $this->record;
29 | }
30 |
31 | public function isVerified()
32 | {
33 | return $this->record->status === 'verified';
34 | }
35 |
36 | public function getStatus()
37 | {
38 | return $this->record->status;
39 | }
40 |
41 | public function getUrl()
42 | {
43 | return $this->url;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Strategies/BaseStrategy.php:
--------------------------------------------------------------------------------
1 | token;
28 | }
29 |
30 | public function getDomainName(string $url): string
31 | {
32 | return URL::getDomainName($url);
33 | }
34 |
35 | public function getRecord(string $url, DomainVerifiable $domainVerifiable): DomainVerification
36 | {
37 | $record = DomainVerificationFacade::firstOrCreate($url, $domainVerifiable);
38 |
39 | return $record->token;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Strategies/DNSRecord.php:
--------------------------------------------------------------------------------
1 | tokenExists($url, $record->token)) {
24 | $record->setVerified();
25 | } else {
26 | $record->setNotVerified();
27 | }
28 |
29 | return new VerifyResult($domainVerifiable, $url, $record);
30 | }
31 |
32 | protected function getTxtRecordValues($url)
33 | {
34 | $dns = new Dns($url);
35 | $txtRecords = $dns->getRecords('TXT');
36 |
37 | if (preg_match_all('/"([^"]+)"/', $txtRecords, $m)) {
38 | return $m[1];
39 | }
40 |
41 | return [];
42 | }
43 |
44 | protected function tokenExists($url, $token)
45 | {
46 | $verificationName = config('domain_verifier.verification_name');
47 | $txtRecordValues = $this->getTxtRecordValues($url);
48 | $verificationValue = "$verificationName=$token";
49 |
50 | return in_array($verificationValue, $txtRecordValues);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Strategies/HTMLFile.php:
--------------------------------------------------------------------------------
1 | token;
22 | $domainToken = substr($this->getHtmlFileToken($url), 0, strlen($verificationToken));
23 |
24 | if ($domainToken === $verificationToken) {
25 | $record->setVerified();
26 | } else {
27 | $record->setNotVerified();
28 | }
29 |
30 | return new VerifyResult($domainVerifiable, $url, $record);
31 | }
32 |
33 | public function getHtmlFileUrl(string $url, DomainVerifiable $domainVerifiable): string
34 | {
35 | $record = DomainVerificationFacade::firstOrCreate($url, $domainVerifiable);
36 |
37 | $baseUrl = config('domain_verifier.base_url');
38 |
39 | return $baseUrl.'/domain-verify/html-file/'.$record->id;
40 | }
41 |
42 | protected function fileGetContents($url)
43 | {
44 | return file_get_contents($url);
45 | }
46 |
47 | protected function getHtmlFileToken($url)
48 | {
49 | $verificationName = config('domain_verifier.verification_name');
50 | $urlFile = $url.'/'.$verificationName.'.html';
51 |
52 | return $this->fileGetContents($urlFile);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Strategies/HTMLMeta.php:
--------------------------------------------------------------------------------
1 | getMetaTags($url);
21 | $domainToken = $this->getMetaTagToken($metaTags);
22 | $record = DomainVerificationFacade::firstOrCreate($url, $domainVerifiable);
23 |
24 | if ($record->token === $domainToken) {
25 | $record->setVerified();
26 | } else {
27 | $record->setNotVerified();
28 | }
29 |
30 | return new VerifyResult($domainVerifiable, $url, $record);
31 | }
32 |
33 | protected function getMetaTags($url)
34 | {
35 | return get_meta_tags($url);
36 | }
37 |
38 | protected function getMetaTagToken(array $metaTags)
39 | {
40 | $verificationName = config('domain_verifier.verification_name');
41 | if (!isset($metaTags[$verificationName])) {
42 | return '';
43 | }
44 |
45 | return $metaTags[$verificationName];
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Strategies/SendingMail.php:
--------------------------------------------------------------------------------
1 | setVerified();
35 | $domainVerifiable = $record->verifiable;
36 |
37 | return new VerifyResult($domainVerifiable, $record->url, $record);
38 | }
39 |
40 | throw new \Exception('Activation token doesn\'t match to any verifiable object.');
41 | }
42 |
43 | public function sendMail(string $url, DomainVerifiable $domainVerifiable, string $emailTo): void
44 | {
45 | $allowedEmailTo = ['admin', 'webmaster'];
46 | if (!in_array($emailTo, $allowedEmailTo)) {
47 | throw new \Exception('This mailbox name is not allowed.');
48 | }
49 |
50 | $domainName = URL::getDomainName($url);
51 | $record = DomainVerificationFacade::firstOrCreate($url, $domainVerifiable);
52 | $domainVerifiable = $record->verifiable;
53 |
54 | Mail::send(
55 | new ActivationMail($domainVerifiable, $record, $url, $domainName, $record->activation_token, $emailTo)
56 | );
57 |
58 | $record->update(['email_sent_at' => Carbon::now()]);
59 | }
60 |
61 | public function setVerified(string $url, DomainVerifiable $domainVerifiable): VerifyResult
62 | {
63 | $record = DomainVerificationFacade::firstOrCreate($url, $domainVerifiable);
64 | $record->setVerified();
65 |
66 | return new VerifyResult($domainVerifiable, $url, $record);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Supports/URL.php:
--------------------------------------------------------------------------------
1 | morphMany(DomainVerification::class, 'verifiable');
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/VerifierFactoryFacade.php:
--------------------------------------------------------------------------------
1 | url = 'https://domain.local';
20 |
21 | $this->token = (new DNSRecord())->getToken($this->url, $this->verifiable);
22 | }
23 |
24 | public function testItCanCheckValidToken()
25 | {
26 | $result = $this->verifyWith($this->token);
27 | $this->assertInstanceOf(VerifyResult::class, $result);
28 | $this->assertTrue($result->isVerified());
29 | $this->assertEquals('verified', $result->getStatus());
30 | }
31 |
32 | public function testItCanCheckInvalidToken()
33 | {
34 | $result = $this->verifyWith('some wrong token');
35 | $this->assertFalse($result->isVerified());
36 | $this->assertEquals('pending', $result->getStatus());
37 | }
38 |
39 | protected function verifyWith(string $token): VerifyResult
40 | {
41 | $this->verifier = Mockery::mock(DNSRecord::class)
42 | ->makePartial()
43 | ->shouldAllowMockingProtectedMethods()
44 | ->allows(['getTxtRecordValues' => [self::VERIFICATION_NAME.'='.$token]]);
45 |
46 | return $this->verifier->verify($this->url, $this->verifiable);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/Strategies/HTMLFileTest.php:
--------------------------------------------------------------------------------
1 | url = 'https://domain.local';
20 |
21 | $this->token = (new HTMLFile())->getToken($this->url, $this->verifiable);
22 | }
23 |
24 | public function testItCanCheckValidToken()
25 | {
26 | $result = $this->verifyWith($this->token);
27 | $this->assertInstanceOf(VerifyResult::class, $result);
28 | $this->assertTrue($result->isVerified());
29 | $this->assertEquals('verified', $result->getStatus());
30 | }
31 |
32 | public function testItCanCheckInvalidToken()
33 | {
34 | $result = $this->verifyWith('some wrong token');
35 | $this->assertFalse($result->isVerified());
36 | $this->assertEquals('pending', $result->getStatus());
37 | }
38 |
39 | protected function verifyWith(string $token): VerifyResult
40 | {
41 | $this->verifier = Mockery::mock(HTMLFile::class)
42 | ->makePartial()
43 | ->shouldAllowMockingProtectedMethods()
44 | ->allows(['fileGetContents' => $token]);
45 |
46 | return $this->verifier->verify($this->url, $this->verifiable);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/Strategies/HTMLMetaTest.php:
--------------------------------------------------------------------------------
1 | url = 'https://domain.local';
20 |
21 | $this->token = (new HTMLMeta())->getToken($this->url, $this->verifiable);
22 | }
23 |
24 | public function testItCanCheckValidToken()
25 | {
26 | $result = $this->verifyWith($this->token);
27 | $this->assertInstanceOf(VerifyResult::class, $result);
28 | $this->assertTrue($result->isVerified());
29 | $this->assertEquals('verified', $result->getStatus());
30 | }
31 |
32 | public function testItCanCheckInvalidToken()
33 | {
34 | $result = $this->verifyWith('some wrong token');
35 | $this->assertFalse($result->isVerified());
36 | $this->assertEquals('pending', $result->getStatus());
37 | }
38 |
39 | protected function verifyWith(string $token): VerifyResult
40 | {
41 | $this->verifier = Mockery::mock(HTMLMeta::class)
42 | ->makePartial()
43 | ->shouldAllowMockingProtectedMethods()
44 | ->allows(['getMetaTags' => [self::VERIFICATION_NAME => $token]]);
45 |
46 | return $this->verifier->verify($this->url, $this->verifiable);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/Strategies/StrategyTestCase.php:
--------------------------------------------------------------------------------
1 | verifiable = Mockery::mock(DomainVerifiableInterface::class)
18 | ->makePartial()->allows()
19 | ->getKey()
20 | ->andReturns('1')
21 | ->getMock();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Supports/URLTest.php:
--------------------------------------------------------------------------------
1 | httpsURL);
17 | $normalizedHttpURL = URL::normalize($this->httpURL);
18 | $normalizedHttpURLWithPort = URL::normalize($this->httpURLWithPort);
19 |
20 | $this->assertSame('https://demo-example.domain.local', $normalizedHttpsURL);
21 | $this->assertSame('http://demo-example.domain.local', $normalizedHttpURL);
22 | $this->assertSame('http://demo-example.domain.local:8000', $normalizedHttpURLWithPort);
23 | }
24 |
25 | public function testItCanGetDomainName()
26 | {
27 | $domainHttpsURL = URL::getDomainName($this->httpsURL);
28 | $domainHttpURL = URL::getDomainName($this->httpURL);
29 | $domainHttpURLWithPort = URL::getDomainName($this->httpURLWithPort);
30 |
31 | $this->assertSame('demo-example.domain.local', $domainHttpsURL);
32 | $this->assertSame('demo-example.domain.local', $domainHttpURL);
33 | $this->assertSame('demo-example.domain.local', $domainHttpURLWithPort);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 |