Commit 7e32f7cf authored by Cypres TAC's avatar Cypres TAC
Browse files

Merge branch 'feature/completetestjs2' into 'master'

test location message + use clea crypto jar generated in the java folder

See merge request !26
parents dc2ae738 f09bebf8
Pipeline #235558 passed with stages
in 10 minutes and 9 seconds
......@@ -4,6 +4,7 @@ stages:
- build
- test
- deploy
build-java:
stage: build
tags:
......@@ -34,6 +35,17 @@ build-c:
- CLEA-lib/c/build/test_*
- CLEA-lib/c/build/build_clea
build-js:
stage: build
image: node:15.13.0
tags:
- ci
script:
- cd CLEA-lib/js
- npm install
- npm run build
- ls dist
test-java:
stage: test
tags:
......@@ -45,34 +57,11 @@ test-java:
paths:
- CLEA-lib/java/target/*.jar
test-interop:
stage: test
tags:
- ci
image: python:3-buster
before_script:
- apt-get update
- apt-get install -y -qq openjdk-11-jre
script:
- cd CLEA-lib/test
- python test_clea.py
deploy:
stage: deploy
tags:
- ci
script:
- cd CLEA-lib/java
- mvn $MAVEN_CLI_OPTS -DskipTests=true -DnexusReleasesUrl=$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/maven -DnexusSnapshotsUrl=$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/maven -s ../../.gitlab-ci/ci_settings.xml deploy
only:
- master
- tags
test-js:
stage: test
before_script:
#Install node and npm #
- apt-get install -y curl && curl -sL https://deb.nodesource.com/setup_15.x | bash - && apt-get install -y nodejs && curl -L https://www.npmjs.com/install.sh | sh
- apt-get install -y curl && curl -sL https://deb.nodesource.com/setup_15.x | bash - && apt-get install -y nodejs && curl -L https://www.npmjs.com/install.sh | sh
#Install Latest Google chrome package on system for front test#
- apt-get install -y chromium
#Install Latest firefox package on system for front test#
......@@ -82,22 +71,32 @@ test-js:
script:
- cd CLEA-lib/js
- pwd || true
- cp ../java/target/clea-crypto-*-jar-with-dependencies.jar ./clea-crypto.jar
- java -cp ./clea-crypto.jar fr.inria.clea.lsp.LspEncoderDecoder decode || true
- java -cp ../java/target/clea-crypto-*-jar-with-dependencies.jar fr.inria.clea.lsp.LspEncoderDecoder decode || true
- export CHROME_BIN=chromium
- export FIREFOX_BIN=firefox-esr
- npm install
- npm test
- npm run testcrypto
build-js:
stage: build
image: node:15.13.0
test-interop:
stage: test
tags:
- ci
image: python:3-buster
before_script:
- apt-get update
- apt-get install -y -qq openjdk-11-jre
script:
- cd CLEA-lib/js
- npm install
- npm run build
- ls dist
- cd CLEA-lib/test
- python test_clea.py
deploy:
stage: deploy
tags:
- ci
script:
- cd CLEA-lib/java
- mvn $MAVEN_CLI_OPTS -DskipTests=true -DnexusReleasesUrl=$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/maven -DnexusSnapshotsUrl=$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/maven -s ../../.gitlab-ci/ci_settings.xml deploy
only:
- master
- tags
......@@ -39,21 +39,29 @@ validation list in progress:
### installation
* apt-get install -y firefox-esr chromium
* export CHROME_BIN=chromium
* export FIREFOX_BIN=firefox-esr
* cd ../java; mvn install
* cd ../js; cp ../java/target/clea-crypto-*-jar-with-dependencies.jar ./clea-crypto.jar
* npm install
```shell
apt-get install -y firefox-esr chromium
export CHROME_BIN=chromium
export FIREFOX_BIN=firefox-esr
cd ../java; mvn install
cd ../js
npm install
```
### build
* npm run build
```shell
npm run build
```
### development deployment
* npm run dev
To test the example, run a local web server with the following command and browse http://localhost:1234
```shell
npm run dev
```
### Test
* npm test : deploy unit test on clea.js and build a csv file with all produced encrypted results
* npm run testcrypto : final test to check the javascript encryption against the java decryption
* `npm test` : run unit tests on clea.js and build a csv file with all produced encrypted results. Encryption results are produced from data in `CLEA-lib/test/encode_in.json`. The file is copied to js/test/dataset.js and udpated to allow its inclusion as a standard JavaScript file.
* `npm run testcrypto` : interoperabilty tests to check the javascript encryption (crypto.csv file produced by `npm test`) against the java decryption
......@@ -18,6 +18,7 @@
"devDependencies": {
"chai": "^4.3.4",
"csvtojson": "^2.0.10",
"glob": "^7.1.6",
"karma": "^6.3.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
......
......@@ -8,9 +8,7 @@ function hexToBytes(hex) {
return bytes;
}
function logEncodingDataAndResult(conf, result) {
console.log(JSON.stringify({filter_key: 'crypto-filter',
message:
conf.SK_L_HEX+","
let message = conf.SK_L_HEX+","
+conf.SK_MCTA_HEX+","
+conf.SK_SA_HEX+","
+result+","
......@@ -20,19 +18,33 @@ function logEncodingDataAndResult(conf, result) {
+conf.venueCategory1+","
+conf.venueCategory2+","
+conf.countryCode+","
+conf.periodDuration+",\""
+navigator.userAgent+"\""}));
+conf.periodDuration;
message += ",\"" +navigator.userAgent+"\"";
if (typeof conf.locContactMsg !== 'undefined') {
message += ","+conf.locContactMsg.locationPhone+
","+conf.locContactMsg.locationRegion+","+conf.locContactMsg.locationPin;
}
console.log(JSON.stringify({filter_key: 'crypto-filter', message: message}));
}
function configurationFromRun(run) {
let conf = Object.assign({}, runs[0]); // clone runs[0]
let conf = Object.assign({}, run); // clone run
conf.SK_L_HEX = conf.SK_L;
conf.PK_SA_HEX = conf.PK_SA;
conf.SK_SA_HEX = conf.SK_SA;
conf.PK_MCTA_HEX = conf.PK_MCTA;
conf.SK_MCTA_HEX = conf.SK_MCTA;
conf.SK_L = hexToBytes(conf.SK_L_HEX);
conf.SK_L = hexToBytes(conf.SK_L_HEX);
conf.PK_SA = hexToBytes(conf.PK_SA_HEX);
conf.PK_MCTA = hexToBytes(conf.PK_MCTA_HEX);
if ((typeof conf.locationPhone !== 'undefined') && (typeof conf.locationRegion !== 'undefined')
&& (typeof conf.locationPIN !== 'undefined')) {
conf.locContactMsg = {
locationPhone: conf.locationPhone,
locationRegion: conf.locationRegion,
locationPin: conf.locationPIN
}
}
return conf;
}
......@@ -85,12 +97,12 @@ describe('getNtpUtc()', function () {
describe('cleaRenewLSP()', function () {
it('should return something with the right lenght and the right header', async () => {
let conf = configurationFromRun(run);
let conf = configurationFromRun(runs[0]);
let result = await clea.cleaRenewLSP(conf);
logEncodingDataAndResult(conf, result);
expect(result).to.length(148)
expect([148, 236]).to.include(result.length);
expect(result.startsWith('AAAAAAAAAAAAAAAAAAAAAA')).to.be.true;
})
......@@ -105,7 +117,7 @@ describe('cleaStartNewPeriod()', function () {
let result = await clea.cleaStartNewPeriod(conf);
logEncodingDataAndResult(conf, result);
expect(result).to.length(148);
expect([148, 236]).to.include(result.length);
});
});
});
......@@ -124,7 +136,7 @@ describe('getInt64Bytes()', function () {
}
});
it('should return the correct resul for 331', function () {
it('should return the correct result for 331', function () {
let expected = new Uint8Array(8);
expected[6] = 1;
expected[7] = 75;
......@@ -183,7 +195,7 @@ describe('ecdhRawPubKeyCompressed()', function () {
});
describe('encrypt()', function () {
it('should return somethinh with the right length and the right header', async () => {
it('should return something with the right length and the right header', async () => {
let header = new Uint8Array(5);
header[0] = 4;
header[1] = 9;
......
const assert = require('chai').assert;
const csv=require('csvtojson')
const expect = require('chai').expect;
const csv=require('csvtojson');
const { spawn } = require('child_process');
const glob = require("glob");
// setup : load cvs file
let cryptoList;
csv({noheader: true,
headers:['sk_l','sk_mcta','sk_sa','result','staff','CRIexp','venueType','venueCategory1','venueCategory2','countryCode','periodDuration','browser']})
headers:['sk_l','sk_mcta','sk_sa','result','staff','CRIexp','venueType','venueCategory1','venueCategory2','countryCode','periodDuration','browser', 'locationPhone', 'locationRegion', 'locationPIN']})
.fromFile('./crypto.csv')
.then((jsonObj)=> {
cryptoList = jsonObj;
......@@ -14,15 +15,17 @@ csv({noheader: true,
setTimeout(function() {
describe('test suite for crypto', function () {
let cleaCryptoJarPath;
glob("../java/target/clea-crypto-*-jar-with-dependencies.jar", function (error, files) {
cleaCryptoJarPath = files[0];
});
cryptoList.forEach(function (cryptoItem) {
it('test on [' + cryptoItem.browser + '] with ' + cryptoItem.staff + ' ' + cryptoItem.CRIexp + ' ' + cryptoItem.venueType + ' ' + cryptoItem.venueCategory1
+ ' ' + cryptoItem.venueCategory2 + ' ' + cryptoItem.countryCode + ' ' + cryptoItem.periodDuration , async () => {
await new Promise((resolve) => {
let result = '';
let javadir = process.cwd();
const javaproc = spawn('java', ['-cp', javadir+'/clea-crypto.jar',
const javaproc = spawn('java', ['-cp', cleaCryptoJarPath,
'fr.inria.clea.lsp.LspEncoderDecoder', 'decode',
cryptoItem.result,
cryptoItem.sk_sa,
......@@ -43,14 +46,24 @@ setTimeout(function() {
javaproc.on('exit', (code) => {
console.log(`Child exited with code ${code}`);
assert.equal(0, code);
assert.equal(result[0], cryptoItem.staff);
assert.equal(result[1], cryptoItem.countryCode);
assert.equal(result[2], cryptoItem.CRIexp);
assert.equal(result[3], cryptoItem.venueType);
assert.equal(result[4], cryptoItem.venueCategory1);
assert.equal(result[5], cryptoItem.venueCategory2);
assert.equal(result[6], cryptoItem.periodDuration);
expect(code).to.equal(0);
expect([10, 13]).to.include(result.length);
expect(result[0]).to.equal(cryptoItem.staff);
expect(result[1]).to.equal(cryptoItem.countryCode);
expect(result[2]).to.equal(cryptoItem.CRIexp);
expect(result[3]).to.equal(cryptoItem.venueType);
expect(result[4]).to.equal(cryptoItem.venueCategory1);
expect(result[5]).to.equal(cryptoItem.venueCategory2);
expect(result[6]).to.equal(cryptoItem.periodDuration);
// result[7] LTId
// result[8] ct_periodStart
// result[9] t_qrStart
if (result.length == 13) {
console.log('checking location');
expect(result[10]).to.equal(cryptoItem.locationPhone);
expect(result[11]).to.equal(cryptoItem.locationRegion);
expect(result[12]).to.equal(cryptoItem.locationPIN);
}
resolve();
});
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment