Skip to content

Commit 0b43b1e

Browse files
Adding text and fixing permission yaml key
1 parent c460bcc commit 0b43b1e

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

encrypt.permissions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
'administer encrypt':
1+
administer encrypt:
22
title: 'Administer encryption settings'
33
description: 'Change encryption settings (does not let them view encrypted data).'

src/Tests/EncryptService.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Definition of Drupal\encrypt\Tests\KeyService.
6+
*/
7+
8+
namespace Drupal\encrypt\Tests;
9+
10+
use Drupal\simpletest\WebTestBase;
11+
12+
/**
13+
* Tests the encrypt service.
14+
*
15+
* @group encrypt
16+
*/
17+
class EncryptService extends WebTestBase {
18+
19+
public static $modules = array('key', 'encrypt');
20+
21+
/**
22+
* Test both encrypt and decrypt functions.
23+
*/
24+
function testEncryptAndDecrypt() {
25+
26+
// Create user with permission to create policy.
27+
$user1 = $this->drupalCreateUser(array('administer site configuration', 'administer encrypt'));
28+
$this->drupalLogin($user1);
29+
30+
// Create new simple key.
31+
$edit = [
32+
'label' => 'Testing Key',
33+
'key_type' => 'key_type_simple',
34+
'key_settings[simple_key_value]' => 'test this key out',
35+
];
36+
$this->drupalPostForm('admin/config/system/key/add', $edit, t('Save'));
37+
38+
39+
// Change encrypt settings.
40+
$edit = [
41+
'encryption_key' => 'testing_key',
42+
'encryption_method' => 'mcrypt_aes_256',
43+
];
44+
$this->drupalPostForm('admin/config/security/encryption', $edit, t('Save configuration'));
45+
46+
// Test encryption service.
47+
$enc_string = \Drupal::getContainer()->get('encryption')->encrypt('test');
48+
$this->assertEqual($enc_string, 'encrypted text', 'The encryption service is not properly processing');
49+
50+
// Test decryption service.
51+
$dec_string = \Drupal::getContainer()->get('encryption')->decrypt($enc_string);
52+
$this->assertEqual($dec_string, 'test', 'The decryption service is not properly processing');
53+
54+
}
55+
}

0 commit comments

Comments
 (0)