Source of file ApiKeyPairTest.php
Size: 2,485 Bytes - Last Modified: 2021-12-23T10:20:31+00:00
/var/www/docs.ssmods.com/process/src/tests/ApiKeyPairTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | <?php namespace Sheerwater\HMACRestfulAuthenticator\Tests; use Sheerwater\HMACRestfulAuthenticator\Models\ApiKeyPair; class ApiKeyPairTest extends \SapphireTest { public function testGetCMSFields() { /** @var ApiKeyPair $keyPair */ $keyPair = ApiKeyPair::create(); // Before saving, there is a description on the Title field and no fields for Key and Secret $preSaveFields = $keyPair->getCMSFields(); $this->assertNotEmpty($preSaveFields->dataFieldByName('Title')->getDescription(), "There should be a description on the 'Title' CMS field for an unsaved ApiKeyPair stating that Key & " . "Secret are available after saving"); $this->assertNull($preSaveFields->dataFieldByName('Key'), "'Key' CMS field should not be present for an unsaved ApiKeyPair"); $this->assertNull($preSaveFields->dataFieldByName('Secret', "'Secret' CMS field should not be present for an unsaved ApiKeyPair")); // After saving, there is no description on the Title field, and the Key and Secret fields are readonly $keyPair->write(); $postSaveFields = $keyPair->getCMSFields(); $this->assertEmpty($postSaveFields->dataFieldByName('Title')->getDescription(), "There should be no description on the 'Title' CMS field for a saved ApiKeyPair"); $keyField = $postSaveFields->dataFieldByName('Key'); $this->assertNotNull($keyField, "The 'Key' CMS field should be present for a saved ApiKeyPair"); $this->assertTrue($keyField->isReadonly(), "The 'Key' CMS field should be disabled"); $secretField = $postSaveFields->dataFieldByName('Secret'); $this->assertNotNull($secretField, "The 'Secret' CMS field should be present for a saved ApiKeyPair"); $this->assertTrue($secretField->isReadonly(), "The 'Secret' CMS field should be disabled"); } public function testOnBeforeWrite() { /** @var ApiKeyPair $keyPair */ $keyPair = ApiKeyPair::create(); $keyPair->write(); $keyLen = strlen(hash('md5', '')); $secretLen = strlen(hash('sha1', '')); $this->assertEquals($keyLen, strlen($keyPair->Key), "The autogenerated 'Key' value should be " . $keyLen . " characters long"); $this->assertEquals($secretLen, strlen($keyPair->Secret), "The autogenerated 'Secret' value should be " . $secretLen . " characters long"); } } |