GSoC17 : Client Side File Crypto : Week 9

Tameesh Biswas
tameeshb
Published in
3 min readFeb 22, 2018

Note: This is a repost of the original Blog post during GSoC ’17. As my AWS instance went down, I’ve been migrating my old blog posts here.
Originally posted in August 2017

This blog post summarises the ninth week of writing open-source code for Drupal with Google Summer of Code.

Attaching JS to all nodes

One thing that i was wondering and trying to figure out how to do was to attach a JS script to all the nodes on the site for the decryption of the files on the article node.

How I went around doing that was by using the node preprocessing hook.

function client_side_file_crypto_preprocess_node(&$variables) {

$node = $variables[‘node’];

$variables[‘#attached’][‘library’][] = ‘client_side_file_crypto/csfcDecrypt’;

}

Adding this code to the .module file of the module attaches this “client_side_file_crypto/csfcDecrypt” JS library defined in the .libraries.yml file to all the nodes on the Drupal site:

Attempting to programmatically attaching files to nodes

I tried to list the encrypted files on a specific node by attaching that file to that node programmatically and later override the onclick action on it to first decrypt those files and then download it. I tried to implement this using the file field on the node but it didn’t quite work out for anything other than images so I decided to take a different approach to it, as described below:

File metadata storage

The way I’m handling file fetching on the backend is by registering in a database the metadata of the uploaded encrypted files with their paths and nodeIDs and later fetching the file metadata using a new REST resource and from the metadata, fetching the actual files via GET and then decrypting it before downloading the files.

Writing functional tests

I also started writing functional tests/Browser tests for my module towards the end of the week.

This link on drupal.org API documentation briefs on all types of testing that can be done in drupal modules. The parts that aided me were the “Write functional PHP tests (phpunit)” and the “Write functional JavaScript tests (phpunit)” sections. It was discussed in the last meeting that we would be emphasising on writing functional tests more than unit tests.

This is a great tutorial on writing browser tests in Drupal.

This week I will be continuing my work on the functional tests and focus on completing the small components left on the feature branches ( js_encrypt and js_decrypt ) on my module and remove the WIP tag from the merge requests to merge the features into 8.x-1.x for moving to the alpha version of the module being left with a few modifications, adding more tests and documentation.

--

--