/** * Test regular key reading */ public function testReadSuccess() { $extra = '123'; file_put_contents($this->filename, Fixtures::key() . $extra, LOCK_EX); $subject = new KeyReader($this->filename); $this->assertEquals(Fixtures::key(), $subject->read()); }
/** * Test encrypt with base64 encoding */ public function testEncryptBase64() { $this->keyReader->expects($this->once())->method('read')->willReturn(Fixtures::key()); $encryptor = new AesEncryptor($this->keyReader, false); $ciphertext = $encryptor->encrypt(Fixtures::PLAIN_TEXT); $this->assertNotEmpty($ciphertext); $this->assertNotEmpty(base64_decode($ciphertext)); }
/** * Provide some cases of invalid configurations. * * @return array */ public function provideInvalidConfiguration() { return [["Cryptor names should be unique. 'foo' name is duplicated", ['cryptors' => ['rsa' => ['foo' => []], 'aes' => ['foo' => ['key_size' => Fixtures::bits(), 'key_path' => $this->existentKeyFile, 'binary_output' => true]]]]], ['The child node "key_size" at path "gtt_crypt.cryptors.aes.foo" must be configured', ['cryptors' => ['rsa' => ['foo' => []], 'aes' => ['foo' => []]]]], [sprintf('Installed version of defuse/php-encryption package provide only %d bits key size', Fixtures::bits()), ['cryptors' => ['rsa' => ['foo' => []], 'aes' => ['foo' => ['key_size' => 999]]]]], ['The child node "key_path" at path "gtt_crypt.cryptors.aes.foo" must be configured', ['cryptors' => ['rsa' => ['foo' => []], 'aes' => ['foo' => ['key_size' => Fixtures::bits()]]]]], ['The child node "binary_output" at path "gtt_crypt.cryptors.aes.foo" must be configured', ['cryptors' => ['rsa' => ['foo' => []], 'aes' => ['foo' => ['key_size' => Fixtures::bits(), 'key_path' => $this->existentKeyFile]]]]]]; }
/** * Data provider for decryption test * * @return array */ public function provideDecrypt() { return [[false, Fixtures::ciphertext(), Fixtures::PLAIN_TEXT], [true, base64_decode(Fixtures::ciphertext()), Fixtures::PLAIN_TEXT]]; }