UNPKG

1.34 kBJavaScriptView Raw
1const expect = require( "chai" ).expect;
2const assert = require( "chai" ).assert;
3const sinon = require( "sinon" );
4const AWS = require( "aws-sdk" );
5const utils = require( "../lib/utils" );
6
7const encryptVar = require( "../lib/encrypt-var" );
8
9describe( "colly encrypt-var", () => {
10
11 it( "should encrypt a var passed to it", () => {
12
13 // Create players
14 const kms = new AWS.KMS();
15 const stubbedEncrypt = sinon.stub( kms, "encrypt" );
16 const stubbedAddEnvVarToProjectConfig = sinon.stub( utils, "addEnvVarToProjectConfig" );
17 const expectedKmsArg = {
18 "KeyId": "arn:aws:kms:eu-west-1:550213415212:key/55e324f3-218f-46e2-a177-a1b04c3f6cbc",
19 "Plaintext": "bar"
20 };
21
22 // Mock returns
23 stubbedEncrypt.callsArgWith( 1, null, { "CiphertextBlob": "encryptedBar" } );
24
25 // Setup inputs
26 process.env.ENV = "live";
27 process.env.COLLY__PROJECT_DIR = "./test/fixtures/encrypt-var";
28
29 // Run method
30 encryptVar.encrypt( "foo", "bar", stubbedEncrypt );
31
32 // Assert
33 expect( stubbedEncrypt.getCall( 0 ).args[ 0 ] ).to.deep.equal( expectedKmsArg );
34 expect( stubbedAddEnvVarToProjectConfig.getCall( 0 ).args[ 0 ] ).to.equal( "foo" );
35 expect( stubbedAddEnvVarToProjectConfig.getCall( 0 ).args[ 1 ] ).to.equal( "encryptedBar" );
36
37 // Clean up
38 stubbedEncrypt.restore();
39 stubbedAddEnvVarToProjectConfig.restore();
40
41 } );
42
43});
\No newline at end of file