public function testDecrypt() { $encrypted_key = 'hu8gZ19fINO3HrPUQkHgqdZ5qaLcKFg4kRgUISFOhQWiAWVYbyo53gE6JQ61gZ64tvclc0RtVghPZCGLvQSJvmQxFwdxzXF7mqvJdepFXhIdwJ6PMIE701kGmdjNoSoXFiOACb73c70DZQmzLA4sVulwcTtJcMWsRgpiC4PayrNWun9x0bWsvsDNNZ2YPZL8yf0paeyfLPsMONfqakSUrJfprYFtjbEkWcgx0hluvZpHj3Nl6AU3TFBJS6b8qFrp99qVsS7wBKAUNSUrDBzGjYNy'; $decrypted_key = 'FOGdGgtmjWZufLyyCe91QG1njTKrylvn8wv0RaLmoCd7sEhDKAjJ6iHGXJPRrfdm2Mtw2nlpBjbukKBU'; $credentials_param = Parameter::make(['id' => 'cloud_credentials', 'sensitive' => true, 'value' => ['access_key' => 'test-key', 'secret_key' => $encrypted_key]]); $params = ParametersCollection::make(['StackName' => 'test-stack', 'cloud_credentials' => $credentials_param]); $unencrypted_values = ['test-stack', 'cloud_credentials', true, 'test-key']; foreach ($unencrypted_values as $value) { Crypt::shouldReceive('decrypt')->once()->with($value)->andThrow(new \Illuminate\Contracts\Encryption\DecryptException('Invalid data.')); } Crypt::shouldReceive('decrypt')->once()->with($encrypted_key)->andReturn($decrypted_key); $decrypted_params = $params->decrypted()->toArray(); $this->assertEquals(array_get($decrypted_params, 'cloud_credentials.value.secret_key'), $decrypted_key); }