generated from rawilk/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content Security Policy Support (#16)
- Loading branch information
Showing
3 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rawilk\Webauthn\Support\WebauthnAssets; | ||
|
||
beforeEach(function () { | ||
$this->assets = new WebauthnAssets; | ||
}); | ||
|
||
it('outputs the script source', function () { | ||
$this->assertStringContainsString( | ||
'<script src="/webauthn/assets/webauthn.js?', | ||
$this->assets->javaScript(), | ||
); | ||
}); | ||
|
||
it('outputs a comment when app is in debug mode', function () { | ||
config()->set('app.debug', true); | ||
|
||
$this->assertStringContainsString( | ||
'<!-- WebAuthn Scripts -->', | ||
$this->assets->javaScript(), | ||
); | ||
}); | ||
|
||
it('does not output a comment when not in debug mode', function () { | ||
config()->set('app.debug', false); | ||
|
||
$this->assertStringNotContainsString( | ||
'<!-- WebAuthn Scripts -->', | ||
$this->assets->javaScript(), | ||
); | ||
}); | ||
|
||
it('can use a custom asset url', function () { | ||
config()->set('webauthn.asset_url', 'https://example.com'); | ||
|
||
$this->assertStringContainsString( | ||
'<script src="https://example.com/webauthn/assets/webauthn.js?', | ||
$this->assets->javaScript(), | ||
); | ||
}); | ||
|
||
it('accepts an asset url as an argument', function () { | ||
$this->assertStringContainsString( | ||
'<script src="https://example.com/webauthn/assets/webauthn.js?', | ||
$this->assets->javaScript(['asset_url' => 'https://example.com']), | ||
); | ||
}); | ||
|
||
it('can output a nonce on the script tag', function () { | ||
$nonce = Str::random(32); | ||
|
||
$this->assertStringContainsString( | ||
"nonce=\"{$nonce}\"", | ||
$this->assets->javaScript(['nonce' => $nonce]), | ||
); | ||
}); |