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);
 }
Esempio n. 2
0
 /**
  * @param Stack $stack
  * @param Collection $remote_stacks
  * @return Collection
  */
 private function getOutputs(Stack $stack, Collection $remote_stacks = null)
 {
     $remote_stacks = $remote_stacks ? $remote_stacks : Collection::make([$stack]);
     $params = Collection::make();
     foreach ($remote_stacks as $remote_stack) {
         if (!$remote_stack->provisioned) {
             throw new CloudFormerException('Cannot use non-provisioned remote stack ' . $remote_stack->name);
         }
         $cfn_params = new ParametersCollection(['StackName' => $remote_stack->name]);
         $response = $this->cfn($stack)->describeStacks($cfn_params->all());
         foreach (array_get(head($response->get('Stacks')), 'Outputs', []) as $output) {
             $key = snake_case($output['OutputKey']);
             $value = $output['OutputValue'];
             if (starts_with($value, ['[']) && ends_with($value, [']'])) {
                 $value = explode(',', trim($value, '[]'));
             }
             $param = ['id' => $key, 'value' => $value];
             $params->put($key, Parameter::make($param));
         }
     }
     return $params;
 }