1 | const expect = require( "chai" ).expect;
|
2 | const assert = require( "chai" ).assert;
|
3 | const sinon = require( "sinon" );
|
4 | const AWS = require( "aws-sdk" );
|
5 | const utils = require( "../lib/utils" );
|
6 |
|
7 | const encryptVar = require( "../lib/encrypt-var" );
|
8 |
|
9 | describe( "colly encrypt-var", () => {
|
10 |
|
11 | it( "should encrypt a var passed to it", () => {
|
12 |
|
13 |
|
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 |
|
23 | stubbedEncrypt.callsArgWith( 1, null, { "CiphertextBlob": "encryptedBar" } );
|
24 |
|
25 |
|
26 | process.env.ENV = "live";
|
27 | process.env.COLLY__PROJECT_DIR = "./test/fixtures/encrypt-var";
|
28 |
|
29 |
|
30 | encryptVar.encrypt( "foo", "bar", stubbedEncrypt );
|
31 |
|
32 |
|
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 |
|
38 | stubbedEncrypt.restore();
|
39 | stubbedAddEnvVarToProjectConfig.restore();
|
40 |
|
41 | } );
|
42 |
|
43 | }); |
\ | No newline at end of file |