-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Oluwatobi-beebittech/chore/testing
test: added testing to laravel modulr auth package
- Loading branch information
Showing
10 changed files
with
100 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/coverage | ||
/vendor/ | ||
/composer.lock | ||
/composer.lock | ||
/.phpunit.result.cache |
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
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
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,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Laravel Modulr Auth package. | ||
* | ||
* (c) Oluwatobi Akanji <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OluwatobiAkanji\ModulrAuth\Tests\Feature; | ||
|
||
use OluwatobiAkanji\ModulrAuth\Facades\AuthHeader; | ||
use OluwatobiAkanji\ModulrAuth\Tests\TestCase; | ||
|
||
class AuthHeaderTest extends TestCase { | ||
|
||
protected $apiKey; | ||
protected $encodedSignature; | ||
protected $expectedAuthorization; | ||
protected $nonce; | ||
protected $timestamp; | ||
|
||
public function setUp(): void { | ||
parent::setup(); | ||
$this->apiKey = config('modulr.key'); | ||
$this->encodedSignature ='WBMr%2FYdhysbmiIEkdTrf2hP7SfA%3D'; | ||
$this->nonce = '28154b2-9c62b93cc22a-24c9e2-5536d7d'; | ||
$this->timestamp = 'Mon, 25 Jul 2016 16:36:07 GMT'; | ||
$this->expectedAuthorization = "Signature keyId=\"$this->apiKey\",algorithm=\"hmac-sha1\",headers=\"date x-mod-nonce\",signature=\"$this->encodedSignature\""; | ||
} | ||
|
||
public function test_auth_header_facade(): void { | ||
AuthHeader::shouldReceive('getHeaders') | ||
->with($this->nonce, $this->timestamp) | ||
->andReturn(["test"]); | ||
$response = AuthHeader::getHeaders($this->nonce, $this->timestamp); | ||
|
||
$this->assertEquals(["test"], $response); | ||
} | ||
|
||
public function test_auth_header(): void { | ||
$authHeaders = AuthHeader::getHeaders($this->nonce, $this->timestamp); | ||
|
||
$this->assertCount(3, $authHeaders); | ||
$this->assertEquals($authHeaders['Date'], $this->timestamp); | ||
$this->assertEquals($authHeaders['x-mod-nonce'], $this->nonce); | ||
$this->assertEquals($authHeaders['Authorization'], $this->expectedAuthorization); | ||
} | ||
|
||
public function test_auth_header_using_current_time(): void { | ||
$authHeaders = AuthHeader::getHeaders(); | ||
|
||
$this->assertCount(3, $authHeaders); | ||
$this->assertIsString($authHeaders['Date']); | ||
$this->assertIsString($authHeaders['x-mod-nonce']); | ||
$this->assertIsString($authHeaders['Authorization']); | ||
} | ||
|
||
public function test_set_timestamp(): void { | ||
AuthHeader::setTimestamp($this->timestamp); | ||
$authHeaders = AuthHeader::getHeaders(); | ||
|
||
$this->assertCount(3, $authHeaders); | ||
$this->assertEquals($authHeaders['Date'], $this->timestamp); | ||
} | ||
|
||
public function test_set_nonce(): void { | ||
AuthHeader::setNonce($this->nonce); | ||
$authHeaders = AuthHeader::getHeaders(); | ||
|
||
$this->assertCount(3, $authHeaders); | ||
$this->assertEquals($authHeaders['x-mod-nonce'], $this->nonce); | ||
} | ||
} |
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