diff --git a/relaxed.info.yml b/relaxed.info.yml index 517b025..cd2a6ef 100644 --- a/relaxed.info.yml +++ b/relaxed.info.yml @@ -11,3 +11,5 @@ dependencies: - system (>=8.3.x) test_dependencies: - workspace + - key + - encrypt diff --git a/tests/src/Functional/RelaxedEncryptTest.php b/tests/src/Functional/RelaxedEncryptTest.php index e69de29..93e5b71 100644 --- a/tests/src/Functional/RelaxedEncryptTest.php +++ b/tests/src/Functional/RelaxedEncryptTest.php @@ -0,0 +1,72 @@ + 'testing_key_256', + 'label' => 'Testing Key 256 bit', + 'key_type' => "encryption", + 'key_type_settings' => ['key_size' => '256'], + 'key_provider' => 'config', + 'key_provider_settings' => ['key_value' => 'mustbesixteenbitmustbesixteenbit'], + ]); + $key_256->save(); + + // Create an Encrption Profile. + $encryption_profile = EncryptionProfile::create([ + 'id' => 'encryption_profile', + 'label' => 'Encryption profile', + 'encryption_method' => 'test_encryption_method', + 'encryption_key' => 'testing_key_256', + ]); + $encryption_profile->save(); + + // Login as root. + $this->drupalLogin($this->rootUser); + + // Add a replication username and password, enable encryption and set + // encryption profile. + $this->drupalGet('/admin/config/relaxed/settings'); + $page = $this->getSession()->getPage(); + $page->fillField('edit-username', 'replication_user'); + $page->fillField('edit-password', 'replication_password'); + $page->checkField('edit-encrypt'); + $page->selectFieldOption('edit-encrypt-profile', 'encryption_profile'); + $page->pressButton('Save configuration'); + $this->assertSession()->pageTextContains('The configuration options have been saved.'); + + $config = \Drupal::config('relaxed.settings'); + $transformer = \Drupal::service('relaxed.sensitive_data.transformer'); + // Make sure the password is not stored in plain text. + $this->assertNotEquals('replication_password', $config->get('password')); + // Make sure the decrypted password matches the one entered. + $this->assertEquals('replication_password', $transformer->get($config->get('password'))); + } + +}