This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for private key authentication
This supports the following scenarios: * Private key only * Private key + API secret * Private key + signature secret
- Loading branch information
Showing
8 changed files
with
247 additions
and
20 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
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,43 @@ | ||
<?php | ||
|
||
namespace Nexmo\Laravel\Tests; | ||
|
||
use Nexmo\Client; | ||
|
||
class TestClientPrivateKeyBasicCredentials extends AbstractTestCase | ||
{ | ||
/** | ||
* Define environment setup. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return void | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('nexmo.private_key', '/path/to/key'); | ||
$app['config']->set('nexmo.application_id', 'application-id-123'); | ||
$app['config']->set('nexmo.api_key', 'my_api_key'); | ||
$app['config']->set('nexmo.api_secret', 'my_secret'); | ||
} | ||
|
||
/** | ||
* Test that our Nexmo client is created with | ||
* a container with key + basic credentials. | ||
* | ||
* @return void | ||
*/ | ||
public function testClientCreatedWithPrivateKeyBasicCredentials() | ||
{ | ||
$client = app(Client::class); | ||
$credentialsObject = $this->getClassProperty(Client::class, 'credentials', $client); | ||
|
||
$credentialsArray = $this->getClassProperty(Client\Credentials\Container::class, 'credentials', $credentialsObject); | ||
$keypairCredentials = $this->getClassProperty(Client\Credentials\Keypair::class, 'credentials', $credentialsArray[Client\Credentials\Keypair::class]); | ||
$basicCredentials = $this->getClassProperty(Client\Credentials\Basic::class, 'credentials', $credentialsArray[Client\Credentials\Basic::class]); | ||
|
||
$this->assertInstanceOf(Client\Credentials\Container::class, $credentialsObject); | ||
$this->assertEquals(['key' => '===FAKE-KEY===', 'application' => 'application-id-123'], $keypairCredentials); | ||
$this->assertEquals(['api_key' => 'my_api_key', 'api_secret' => 'my_secret'], $basicCredentials); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Nexmo\Laravel\Tests; | ||
|
||
use Nexmo\Client; | ||
|
||
class TestClientPrivateKeyCredentials extends AbstractTestCase | ||
{ | ||
/** | ||
* Define environment setup. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return void | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('nexmo.private_key', '/path/to/key'); | ||
$app['config']->set('nexmo.application_id', 'application-id-123'); | ||
} | ||
|
||
/** | ||
* Test that our Nexmo client is created with | ||
* the private key credentials | ||
* | ||
* @return void | ||
*/ | ||
public function testClientCreatedWithPrivateKeyCredentials() | ||
{ | ||
$client = app(Client::class); | ||
$credentialsObject = $this->getClassProperty(Client::class, 'credentials', $client); | ||
$credentialsArray = $this->getClassProperty(Client\Credentials\Keypair::class, 'credentials', $credentialsObject); | ||
|
||
$this->assertInstanceOf(Client\Credentials\Keypair::class, $credentialsObject); | ||
$this->assertEquals(['key' => '===FAKE-KEY===', 'application' => 'application-id-123'], $credentialsArray); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace Nexmo\Laravel\Tests; | ||
|
||
use Nexmo\Client; | ||
|
||
class TestClientPrivateKeySignatureCredentials extends AbstractTestCase | ||
{ | ||
/** | ||
* Define environment setup. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* | ||
* @return void | ||
*/ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('nexmo.private_key', '/path/to/key'); | ||
$app['config']->set('nexmo.application_id', 'application-id-123'); | ||
$app['config']->set('nexmo.api_key', 'my_api_key'); | ||
$app['config']->set('nexmo.signature_secret', 'my_signature'); | ||
} | ||
|
||
/** | ||
* Test that our Nexmo client is created with | ||
* a container with private key + signature credentials | ||
* | ||
* @return void | ||
*/ | ||
public function testClientCreatedWithPrivateKeySignatureCredentials() | ||
{ | ||
$client = app(Client::class); | ||
$credentialsObject = $this->getClassProperty(Client::class, 'credentials', $client); | ||
|
||
$credentialsArray = $this->getClassProperty(Client\Credentials\Container::class, 'credentials', $credentialsObject); | ||
$keypairCredentials = $this->getClassProperty(Client\Credentials\Keypair::class, 'credentials', $credentialsArray[Client\Credentials\Keypair::class]); | ||
$signatureCredentials = $this->getClassProperty(Client\Credentials\SignatureSecret::class, 'credentials', $credentialsArray[Client\Credentials\SignatureSecret::class]); | ||
|
||
$this->assertInstanceOf(Client\Credentials\Container::class, $credentialsObject); | ||
$this->assertEquals(['key' => '===FAKE-KEY===', 'application' => 'application-id-123'], $keypairCredentials); | ||
$this->assertEquals(['api_key' => 'my_api_key', 'signature_secret' => 'my_signature'], $signatureCredentials); | ||
} | ||
} |
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