unit tests are working
MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
@@ -179,11 +179,7 @@ export default class MongoDBStorage {
type: CryptoSettingsType.CRYPTO,
crypto: {
key: Utils.generateKey(),
- keyProperties: {
- blockCypher: 'AES',
- keySize: 256,
- operationMode: 'GCM'
- }
+ keyProperties: Utils.getKeyProperties()
}
} as KeySetting;
// Save Crypto Key Settings

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1360,6 +1360,16 @@ export default class Utils {
}
public static generateKey(): string {
- return crypto.randomBytes(32).toString('hex');
+ // TODO change 16 to 32 and test on Mac
+ return crypto.randomBytes(16).toString('hex');
+ }
+
+ public static getKeyProperties(): CryptoKeyProperties {
+ // TODO change CTR to GCM and test on Mac
+ return {
+ blockCypher: 'AES',
+ keySize: 256,
+ operationMode: 'CTR'
+ };
}
}

MODIFY
test/api/ComponentActivationTenantTest.ts
test/api/ComponentActivationTenantTest.ts
@@ -103,8 +103,8 @@ describe('Tenant Settings test', function() {
expect(res.status).to.equal(200);
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
- expect(settings.data.count).to.equal(1);
- expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.OCPI, RoamingSettingsType.GIREVE);
+ expect(settings.data.count).to.equal(2);
+ expect(settings.data.result[1]).to.be.validatedSetting(TenantComponents.OCPI, RoamingSettingsType.GIREVE);
});
it('Pricing/Simple : Check that the setting has been created in the tenant after activation', async function() {
@@ -132,8 +132,8 @@ describe('Tenant Settings test', function() {
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
expect(settings.status).to.equal(200);
- expect(settings.data.count).to.equal(1);
- expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.SIMPLE);
+ expect(settings.data.count).to.equal(2);
+ expect(settings.data.result[1]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.SIMPLE);
});
it('Billing : Check that the setting has been created in the tenant after activation', async function() {
@@ -183,9 +183,9 @@ describe('Tenant Settings test', function() {
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
expect(settings.status).to.equal(200);
- expect(settings.data.count).to.equal(2);
+ expect(settings.data.count).to.equal(3);
expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.BILLING, BillingSettingsType.STRIPE);
- expect(settings.data.result[1]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.SIMPLE);
+ expect(settings.data.result[2]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.SIMPLE);
});
it('Refund : Check that the setting has been created in the tenant after activation', async function() {
@@ -234,9 +234,9 @@ describe('Tenant Settings test', function() {
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
expect(settings.status).to.equal(200);
- expect(settings.data.count).to.equal(2);
- expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.SIMPLE);
- expect(settings.data.result[1]).to.be.validatedSetting(TenantComponents.REFUND, RefundSettingsType.CONCUR);
+ expect(settings.data.count).to.equal(3);
+ expect(settings.data.result[1]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.SIMPLE);
+ expect(settings.data.result[2]).to.be.validatedSetting(TenantComponents.REFUND, RefundSettingsType.CONCUR);
});
it('SmartCharging : Check that the setting has been created in the tenant after activation', async function() {
@@ -284,8 +284,8 @@ describe('Tenant Settings test', function() {
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
expect(settings.status).to.equal(200);
- expect(settings.data.count).to.equal(1);
- expect(settings.data.result[0]).to.be.validatedSetting('smartCharging', 'sapSmartCharging');
+ expect(settings.data.count).to.equal(2);
+ expect(settings.data.result[1]).to.be.validatedSetting('smartCharging', 'sapSmartCharging');
});
it('Pricing/Convergent : Check that the setting has been created in the tenant after activation', async function() {
@@ -312,8 +312,8 @@ describe('Tenant Settings test', function() {
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
expect(settings.status).to.equal(200);
- expect(settings.data.count).to.equal(1);
- expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.CONVERGENT_CHARGING);
+ expect(settings.data.count).to.equal(2);
+ expect(settings.data.result[1]).to.be.validatedSetting(TenantComponents.PRICING, PricingSettingsType.CONVERGENT_CHARGING);
});
it('Analytics : Check that the setting has been created in the tenant after activation', async function() {
@@ -341,7 +341,7 @@ describe('Tenant Settings test', function() {
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
expect(settings.status).to.equal(200);
- expect(settings.data.count).to.equal(1);
+ expect(settings.data.count).to.equal(2);
expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.ANALYTICS, AnalyticsSettingsType.SAC);
});
@@ -390,7 +390,7 @@ describe('Tenant Settings test', function() {
expect(res.status).to.equal(200);
testData.connectUser();
const settings = await testData.centralService.settingApi.readAll({});
- expect(settings.data.count).to.equal(1);
+ expect(settings.data.count).to.equal(2);
expect(settings.data.result[0]).to.be.validatedSetting(TenantComponents.ASSET, null);
});
});

MODIFY
test/api/CypherTest.ts
test/api/CypherTest.ts
import chai, { expect } from 'chai';
+import { CryptoSetting } from '../types/Setting';
import CypherJSON from './client/utils/CypherJSON';
import chaiDatetime from 'chai-datetime';
import chaiSubset from 'chai-subset';
@@ -16,17 +17,24 @@ chai.use(responseHelper);
const FAKE_JSON: CypherJSON = { 'sensitiveData': ['content.secret1', 'content.secret2'], 'content': { 'secret1': 'Harry', 'secret2': 'Potter' } };
const FAKE_WORD = 'Wingardium Leviosa';
-const FAKE_WORD_ENCRYPTED = '73d49673e8f70de6e16ba99bc0c273da:8b9cb41f960d2b50604921a68d7d0382472d';
+const FAKE_WORD_ENCRYPTED = '04480e7ab47eb5729faea20f0844dffa:81927d0bc660c4548b27cc0e3427d6874ea3';
+const CRYPTO_KEY: CryptoSetting = {
+ 'key': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
+ 'keyProperties': {
+ 'blockCypher': 'AES',
+ 'keySize': 256,
+ 'operationMode': 'CTR'
+ }
+};
-// TODO No point of testing this without tenant? How to change here?
describe('Cypher Tests', function() {
this.timeout(30000);
describe('Success cases', () => {
it('Check that encryption and decryption work', () => {
- const encrypted = cypher.encrypt(FAKE_WORD);
- expect(FAKE_WORD).to.equal(cypher.decrypt(encrypted));
+ const encrypted = cypher.encrypt(FAKE_WORD, CRYPTO_KEY);
+ expect(FAKE_WORD).to.equal(cypher.decrypt(encrypted, CRYPTO_KEY));
});
it('Check that hashing works', () => {
@@ -36,18 +44,18 @@ describe('Cypher Tests', function() {
it('Check that the sensitive data present in JSONs are encrypted', () => {
const testJSON: CypherJSON = { 'sensitiveData': ['content.secret1', 'content.secret2'], 'content': { 'secret1': 'Harry', 'secret2': 'Potter' } };
- cypher.encryptSensitiveDataInJSON(testJSON);
+ cypher.encryptSensitiveDataInJSON(testJSON, CRYPTO_KEY);
// Check encryption
expect(FAKE_JSON.content.secret1).to.not.equal(testJSON.content.secret1);
expect(FAKE_JSON.content.secret2).to.not.equal(testJSON.content.secret2);
// Check decryption
- cypher.decryptSensitiveDataInJSON(testJSON);
+ cypher.decryptSensitiveDataInJSON(testJSON, CRYPTO_KEY);
expect(FAKE_JSON.content.secret1).to.equal(testJSON.content.secret1);
expect(FAKE_JSON.content.secret2).to.equal(testJSON.content.secret2);
});
it('Check that the global encryption key is unchanged', () => {
- const decrypted = cypher.decrypt(FAKE_WORD_ENCRYPTED);
+ const decrypted = cypher.decrypt(FAKE_WORD_ENCRYPTED, CRYPTO_KEY);
expect(FAKE_WORD).to.equal(decrypted);
});
});

unit tests are working