Attention une mise à jour du service Gitlab va être effectuée le mardi 14 décembre entre 13h30 et 14h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 1a571e68 authored by Cypres TAC's avatar Cypres TAC
Browse files

Merge branch 'test-enhancements' into 'master'

add parameterizeTest

See merge request !11
parents 468f1889 11a1186b
Pipeline #227591 passed with stages
in 3 minutes and 27 seconds
......@@ -46,6 +46,12 @@
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
......
......@@ -14,12 +14,15 @@ import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.Base64;
import java.util.UUID;
import java.util.Random;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.util.encoders.Hex;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
......@@ -74,7 +77,7 @@ class LocationSpecificPartTest {
@Test
public void testEncodinsAndDecodingOfALocationMessage() throws CleaEncryptionException {
int periodStartTime = TimeUtils.hourRoundedCurrentTimeTimestamp32();
LocationContact locationContact = new LocationContact("0612150292", "01234567", periodStartTime);
LocationContact locationContact = new LocationContact("33800130000", "01234567", periodStartTime);
Location location = Location.builder()
.contact(locationContact)
.manualContactTracingAuthorityPublicKey(manualContactTracingAuthorityKeyPair[1])
......@@ -87,41 +90,11 @@ class LocationSpecificPartTest {
assertThat(decodedLocationContact).isEqualTo(locationContact);
}
@Disabled(value="We should test encodoing / decoding together. 2 encryptions with the same data does not give the same result")
@Test
public void testLocationSpecificPartEncoding() throws CleaEncryptionException {
int periodStartTime = TimeUtils.hourRoundedCurrentTimeTimestamp32();
LocationContact locationContact = new LocationContact("33800130000", "01234567", periodStartTime);
LocationSpecificPart lsp = LocationSpecificPart.builder()
.staff(false)
.countryCode(592)
.qrCodeRenewalIntervalExponentCompact(10)
.venueType(15)
.venueCategory1(0)
.venueCategory2(2)
.periodDuration(3)
.qrCodeValidityStartTime(periodStartTime * 3600)
.build();
Location location = Location.builder()
.contact(locationContact)
.locationSpecificPart(lsp)
.manualContactTracingAuthorityPublicKey(manualContactTracingAuthorityKeyPair[1])
.serverAuthorityPublicKey(serverAuthorityKeyPair[1])
.permanentLocationSecretKey(permanentLocationSecretKey)
.build();
location.setPeriodStartTime(periodStartTime);
byte[] encryptedLocationSpecificPart = location.getLocationSpecificPartEncrypted();
assertThat(encryptedLocationSpecificPart).isNotNull();
assertThat(encryptedLocationSpecificPart).isEqualTo(0); // TODO replace by expected value
}
@Test
public void testEncodingAndDecodingOfALocationSpecificPart() throws CleaEncryptionException {
int periodStartTime = TimeUtils.hourRoundedCurrentTimeTimestamp32();
LocationContact locationContact = new LocationContact("0612150292", "01234567", periodStartTime);
LocationContact locationContact = new LocationContact("33800130000", "01234567", periodStartTime);
/* Encode a LSP with location */
LocationSpecificPart lsp = LocationSpecificPart.builder()
.staff(true)
......@@ -203,7 +176,7 @@ class LocationSpecificPartTest {
assertThat(decryptedMessage).containsExactly(plainTextMessage);
}
@Disabled("Keep this piece of code as example how to generate a Qrcode image")
@Test
public void testQrCodeGeneration() throws Exception {
int periodStartTime = TimeUtils.hourRoundedCurrentTimeTimestamp32();
......@@ -237,44 +210,122 @@ class LocationSpecificPartTest {
MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, fileOutputStream);
fileOutputStream.close();
}
/**
* Testing base64 decoding from C or Java
* Testing the decoding of a LSP in base64 (encoded by C lib)
* testLSPDecoding.csv values are generated by the interoperability test
* launched manually in python (in project/test)
*/
@Test
public void testBase64DecodingFromCToJava() {
@ParameterizedTest
@CsvFileSource(resources = "/testLSPDecoding.csv", numLinesToSkip = 1)
void testDecodingOfLocationSpecificPartInBase64(int staff, int countryCode, String locationTemporaryPublicID, int qrCodeRenewalIntervalExponentCompact,
int venueType, int venueCat1, int venueCat2, int periodDuration, int periodStartTime, long qrStartTime,
String serverAuthoritySecretKey, String serverAuthorityPublicKey, String lspbase64) throws CleaEncryptionException {
LocationSpecificPartDecoder decoder = new LocationSpecificPartDecoder(serverAuthoritySecretKey);
LocationSpecificPart lsp = decoder.decrypt(lspbase64).decodeMessage();
assertThat(lsp.isStaff()).isEqualTo(staff==1);
assertThat(lsp.getCountryCode()).isEqualTo(countryCode);
assertThat(lsp.getQrCodeRenewalIntervalExponentCompact()).isEqualTo(qrCodeRenewalIntervalExponentCompact);
assertThat(lsp.getLocationTemporaryPublicId()).isEqualTo(UUID.fromString(locationTemporaryPublicID));
assertThat(lsp.getPeriodDuration()).isEqualTo(periodDuration);
assertThat(lsp.getVenueType()).isEqualTo(venueType);
assertThat(lsp.getVenueCategory1()).isEqualTo(venueCat1);
assertThat(lsp.getVenueCategory2()).isEqualTo(venueCat2);
assertThat(lsp.getCompressedPeriodStartTime()).isEqualTo(periodStartTime);
// TODO: PROBLEM TO SOLVE: int-> long for qrCodeValidityStartTime
// assertThat(lsp.getQrCodeValidityStartTime()).isEqualTo(qrStartTime);
}
/**
* Generates a random long with n digits
*/
private String generateRandomDigits(int n) {
String lsp64C = "APJexM7Ntkr9l2JO6mpD3HWO9OkU9nDygdP16KhNAiR9JUr05mT9+5kvJbZph/GdRbIqpQCwgFlYkWEr633BiYhJ+x/pc581PYG4aF2ZzjDJfrY5PfZodBKEiWH+Qegtp3x2bw4sfbCM8OPIvPtU7ooyyzj9h7RdKp4GfgeCz9YdikJ8uJYusQaFILrICqswxQzQPhLVHsnkMjAVpayCAxUOVgZbqj5m8lNcMhCxog==";
String lsp64J = "AJMxSV4mHDX9iqjedPJRtpd7XTx53/ZCrZ4l53yFT7CSbiksSWm6vXApD+XeHT5nLEPbVRPXQoY8PJaTakCQNXYa2EUb8UW62n7sMua+UmZwDnf/9OPOVwWyGacP5L94sv0fCk7XnjBbDLhtORCGrdiwkOm3UniGc8gyP41zneHQSmbfzq6kEzFCX2kfKQIXIsFVyCFp7M4KdpVb2oWg2Q/FZr63cBdObwI9mrImCw==";
Base64.getDecoder().decode(lsp64C);
String randomNumString = "";
Random r = new Random();
//Generate the first digit from 0-9
randomNumString += r.nextInt(10);
//Generate the remaining digits between 0-9
for(int x = 1; x < n; x++){
randomNumString += r.nextInt(9);
}
// TODO: I do not understand this test. Result of the decoding is not used
System.out.println("Qrcode size C=" + lsp64C.length() + " Java=" + lsp64J.length());
return randomNumString;
}
@Test
public void testDecodingOfLocationSpecificPartInBase64() throws CleaEncryptionException {
final String lsp_base64 = "APK57CdeWirVk+5bqzle+Fr9ieDlSpYfYkbgTC8zxsGx0bTy9VQq9GzOEqK7YSx5DdZsh5tZ9DT0OLH6MMveQXUky80xLbXkV3glHS+4m1bF2YTnzHNUppxMcb/IpKVoSnxY4pCA5l13gl9Jlkvkl5HIHl5Lv3FmWBZ6ScK4Zuj/VJFSjKp3/+CignJcHwNR6Lz5l+R6EgDugCueAyh9HuiyKrb4ntnGEMeit59btg==";
final String servertAuthoritySecretKey = "34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8";
LocationSpecificPartDecoder decoder = new LocationSpecificPartDecoder(servertAuthoritySecretKey);
/**
* Testing the encoding/decoding of a LSP in base64
* testLSPDecoding.csv values are generated by the interoperability test
* launched manually in python (in project/test)
*/
@ParameterizedTest
@CsvFileSource(resources = "/testLSPDecoding.csv", numLinesToSkip = 1)
void testEncodingDecodingOfLSPSpecificPartInBase64(int staff, int countryCode, String locationTemporaryPublicID, int qrCodeRenewalIntervalExponentCompact,
int venueType, int venueCat1, int venueCat2, int periodDuration, int periodStartTime, long qrStartTime,
String serverAuthoritySecretKey, String serverAuthorityPublicKey, String lspbase64) throws CleaEncryptionException {
/* Use only testLSPDecoding.csv parameters to have a variety of parameters */
/* times parameters and location are generated */
int myPeriodStartTime = TimeUtils.hourRoundedCurrentTimeTimestamp32();
Random rn = new Random();
int nbDigits = rn.nextInt(6) + 10;
String phone = generateRandomDigits(nbDigits);
String pinCode = generateRandomDigits(8);
LocationContact locationContact = new LocationContact(phone, pinCode, myPeriodStartTime);
/* Encode a LSP with location */
LocationSpecificPart lsp = LocationSpecificPart.builder()
.staff(staff==1)
.countryCode(countryCode)
.qrCodeRenewalIntervalExponentCompact(qrCodeRenewalIntervalExponentCompact)
.venueType(venueType)
.venueCategory1(venueCat1)
.venueCategory2(venueCat2)
.periodDuration(periodDuration)
.build();
Location location = Location.builder()
.locationSpecificPart(lsp)
.contact(locationContact)
.manualContactTracingAuthorityPublicKey(manualContactTracingAuthorityKeyPair[1])
.serverAuthorityPublicKey(serverAuthorityPublicKey)
.permanentLocationSecretKey(permanentLocationSecretKey)
.build();
location.setPeriodStartTime(myPeriodStartTime);
/* Encode a LSP with location */
String encryptedLocationSpecificPart = location.getLocationSpecificPartEncryptedBase64();
/* Decode the encoded LSP */
LocationSpecificPart decodedLsp = new LocationSpecificPartDecoder(serverAuthoritySecretKey).decrypt(encryptedLocationSpecificPart).decodeMessage();
assertThat(decodedLsp).isEqualTo(lsp);
}
LocationSpecificPart lsp = decoder.decrypt(lsp_base64).decodeMessage();
/**
* Testing the decoding of a Location inside a LSP in base64 (encoded by C lib)
* testLocationDecoding.csv values are generated by the interoperability test
* launched manually in python (in project/test)
*/
@ParameterizedTest
@CsvFileSource(resources = "/testLocationDecoding.csv", numLinesToSkip = 1)
void testDecodingOfLocationOnlyInBase64(String locationPhone, String locationPin, long t_periodStart,
String serverAuthoritySecretKey, String serverAuthorityPublicKey,
String manualContactTracingAuthoritySecretKey, String manualContactTracingAuthorityPublicKey,
String lspbase64) throws CleaEncryptionException {
/* Decode the encoded LSP */
LocationSpecificPartDecoder decoder = new LocationSpecificPartDecoder(serverAuthoritySecretKey);
LocationSpecificPart lsp = decoder.decrypt(lspbase64).decodeMessage();
;
assertThat(lsp.isStaff()).isEqualTo(false);
assertThat(lsp.getCountryCode()).isEqualTo(492);
assertThat(lsp.getLocationTemporaryPublicId()).isEqualTo(UUID.fromString("f2b9ec27-5e5a-2ad5-93ee-5bab395ef85a"));
assertThat(lsp.getCompressedPeriodStartTime()).isEqualTo(1062479);
// TODO: PROBLEM TO SOLVE
// assertThat(lsp.getQrCodeValidityStartTime()).isEqualTo(3824926044);
assertThat(lsp.getPeriodDuration()).isEqualTo(3);
assertThat(lsp.getQrCodeRenewalIntervalExponentCompact()).isEqualTo(5);
assertThat(lsp.getVenueType()).isEqualTo(12);
assertThat(lsp.getVenueCategory1()).isEqualTo(0);
assertThat(lsp.getVenueCategory2()).isEqualTo(0);
System.out.println(lsp);
}
byte[] encryptedLocationContactMessage = lsp.getEncryptedLocationContactMessage();
LocationContact decodedLocationContact = new LocationContactMessageEncoder(manualContactTracingAuthoritySecretKey).decode(encryptedLocationContactMessage);
assertThat(decodedLocationContact.getLocationPhone()).isEqualTo(locationPhone);
assertThat(decodedLocationContact.getLocationPin()).isEqualTo(locationPin);
// TODO: PROBLEM TO SOLVE: int-> long for PeriodStartTime
// assertThat(decodedLocationContact.getPeriodStartTime()).isEqualTo(t_periodStart);
}
@Test
public void testLocationSpecificPartBase64EciesDecryption() throws NoSuchAlgorithmException, InvalidKeySpecException, IllegalStateException, InvalidCipherTextException, IOException {
......@@ -282,15 +333,16 @@ class LocationSpecificPartTest {
final String privateKey = "3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd";
/* message encrypted, from C package */
final String cipherTextBase64 = "AHHp6U8wrVQuWDomdZfDS0BHC45n72pzlmAhqE7AZp3hTWt2cuUOJ78nNeZSJCrpjpl3glMI49yjLEoIi73wqsSbja1sMH0XzuNoAssCV53wTItE3Nxg+J3FI78/W6uWD8IU+dn0YEroJwH2y1g=";
/* plain text message byte array */
byte[] plainTextBytes = { (byte) 0x00, (byte)0x71, (byte)0xE9, (byte)0xE9, (byte)0x4F, (byte)0x30, (byte)0xAD, (byte)0x54, (byte)0x2E, (byte)0x58, (byte)0x3A, (byte)0x26, (byte)0x75, (byte)0x97, (byte)0xC3, (byte)0x4B, (byte)0x40, (byte)0x89, (byte)0x43, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x10, (byte)0x36, (byte)0x50, (byte)0xE3, (byte)0xFB, (byte)0xC4, (byte)0x2F, (byte)0x13, (byte)0xAD, (byte)0x1A, (byte)0x0B, (byte)0x2C, (byte)0x7B, (byte)0xD2, (byte)0xAD, (byte)0xD1, (byte)0xC6, (byte)0xCB, (byte)0x4E, (byte)0xDF, (byte)0x03, (byte)0x92, (byte)0x76, (byte)0x0A, (byte)0xA7, (byte)0xCB, (byte)0xFE, (byte)0xE8, (byte)0x09, (byte)0x0B, (byte)0x97, (byte)0x08, (byte)0x00, (byte)0x19, (byte)0x96, (byte)0xEA, (byte)0xEB, (byte)0x4B, (byte)0xAF};
/* String -> bytes array */
byte[] cipherText = Base64.getDecoder().decode(cipherTextBase64);
System.out.println("CIFFER LSP " + BytesUtils.bytesToString(cipherText));
/* Java decrypt the message using the EC private key privKey */
byte[] message = new CleaEciesEncoder().decrypt(cipherText, privateKey, true);
System.out.println("PLAIN LSP: " + BytesUtils.bytesToString(message));
// TODO: add assertions
assertThat(message).isEqualTo(plainTextBytes);
}
}
staff, countryCode, LTId, CRIexp, venueType, venueCat1, venueCat2, periodDuration, ct_periodStart, t_qrStart, SK_SA, PK_SA, lsp_base64
0, 492, d5e7c7bb-39c1-5d05-d099-4af94c5e1508, 5, 12, 0, 0, 3, 1062551, 3825183806, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, ANXnx7s5wV0F0JlK+UxeFQhit4IeKD9oDNEJ3ICWC2r+V9+3lmivN0ASWJ2LY4J7JGhBe7no034i84J0sJAxgc7X/k/pRculBiPHXGi30bw2r+iXRZNQXLWsuNdO3Xz/wRbALxE/WEUyjXK1wPpwQK6gIqRN0wCen6UdKqjMm8RT/jPlQ4HC53WmDWtElwKG1cwMV8IvTqlKWHUB4S4JTHMwZuHeLkDq8M8+O2uodA==
1, 4095, d5e7c7bb-39c1-5d05-d099-4af94c5e1508, 31, 31, 15, 15, 255, 1062551, 3825183806, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, ANXnx7s5wV0F0JlK+UxeFQh4pkn9iw5HsbDWFhRGr/AMgxyDtCeFDNdcLDezLMKNXq+xWK6cZuTvsrRLF1t7rFl7kFxXMIJ385crApGR9dcSCudfurY/qyejYYPC8lXL5+RMZwmeJgiIbjditviTn5OJY2NB2Ppy/EMhKUfnyB9Z69Mu1K8zcFQ0upJwZQOqMaRnoi3B7bEy/YB1/a3zTBDfUUx2usoxeddLFxe0yw==
1, 592, d5e7c7bb-39c1-5d05-d099-4af94c5e1508, 31, 31, 15, 15, 255, 1062551, 3825183806, 3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd, 045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4, ANXnx7s5wV0F0JlK+UxeFQgV9xGX/BNF8V7w8HYosVwROBC7hGPHtLsLtgNi8+AoSFlizStzODCWAG1RYxLvzdsqeBg16xuDmJPSuAwC8oLHWqgxzdlvBNCVj2DcZY7QDsutVwJLnR/mZRefSwc=
0, 492, d5e7c7bb-39c1-5d05-d099-4af94c5e1508, 5, 10, 3, 3, 5, 1062551, 3825183806, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, ANXnx7s5wV0F0JlK+UxeFQgVgfG98RQuDK0XKoD66X1m7sPtoqN+quHevsBQQYb0PdoTgJqFhK5d0ffWOVNOntfPHMckUnpoqraUOav4wYCjjhF39ZImldJgT6awp4PLDfglg5JqynANkg+0aFmmow61/NFw4nGlbEnoepMtRkxGmDZ9gxB+fUGZLt1yUgOdKzMy2CHuBwVu6XluiCMfbit+t2EsHUo2cO6o1aiIYg==
1, 202, d5e7c7bb-39c1-5d05-d099-4af94c5e1508, 5, 31, 3, 1, 10, 1062551, 3825183806, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, ANXnx7s5wV0F0JlK+UxeFQgjNbDa0UL0MlRp6PsAMJj/w32hx3y/VuysjaCYlraWJyst+YvqPjvoD2ebZMHdInWhWeQvYLxnqfaIG5Xu+LuXNNoXPxM7MsACQd00UUgrsqGcfRQMhO9+QbK6UJgXTcNtVdNKleqcZsXkDg3nrI/j6OIOrtccYaEhVGZlVwKiassL5jyiOrW8aDbWW1NRI1vAcdLpAR2YpZ548zW2NQ==
locationPhone, locationPin, t_periodStart, SK_SA, PK_SA, SK_MCTA, PK_MCTA, lsp_base64
33800130000, 01234567, 3825183600, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, 3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd, 045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4, ANXnx7s5wV0F0JlK+UxeFQhit4IeKD9oDNEJ3ICWC2r+V9+3lmivN0ASWJ2LY4J7JGhBe7no034i84J0sJAxgc7X/k/pRculBiPHXGi30bw2r+iXRZNQXLWsuNdO3Xz/wRbALxE/WEUyjXK1wPpwQK6gIqRN0wCen6UdKqjMm8RT/jPlQ4HC53WmDWtElwKG1cwMV8IvTqlKWHUB4S4JTHMwZuHeLkDq8M8+O2uodA==
33800130000, 01234567, 3825183600, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, 3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd, 045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4, ANXnx7s5wV0F0JlK+UxeFQh4pkn9iw5HsbDWFhRGr/AMgxyDtCeFDNdcLDezLMKNXq+xWK6cZuTvsrRLF1t7rFl7kFxXMIJ385crApGR9dcSCudfurY/qyejYYPC8lXL5+RMZwmeJgiIbjditviTn5OJY2NB2Ppy/EMhKUfnyB9Z69Mu1K8zcFQ0upJwZQOqMaRnoi3B7bEy/YB1/a3zTBDfUUx2usoxeddLFxe0yw==
33800130000, 01234567, 3825183600, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, 3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd, 045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4, ANXnx7s5wV0F0JlK+UxeFQgVgfG98RQuDK0XKoD66X1m7sPtoqN+quHevsBQQYb0PdoTgJqFhK5d0ffWOVNOntfPHMckUnpoqraUOav4wYCjjhF39ZImldJgT6awp4PLDfglg5JqynANkg+0aFmmow61/NFw4nGlbEnoepMtRkxGmDZ9gxB+fUGZLt1yUgOdKzMy2CHuBwVu6XluiCMfbit+t2EsHUo2cO6o1aiIYg==
33800130000, 76543210, 3825183600, 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8, 04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5, 3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd, 045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4, ANXnx7s5wV0F0JlK+UxeFQgjNbDa0UL0MlRp6PsAMJj/w32hx3y/VuysjaCYlraWJyst+YvqPjvoD2ebZMHdInWhWeQvYLxnqfaIG5Xu+LuXNNoXPxM7MsACQd00UUgrsqGcfRQMhO9+QbK6UJgXTcNtVdNKleqcZsXkDg3nrI/j6OIOrtccYaEhVGZlVwKiassL5jyiOrW8aDbWW1NRI1vAcdLpAR2YpZ548zW2NQ==
......@@ -44,5 +44,37 @@
"SK_MCTA": "34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8",
"PK_MCTA": "04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5",
"SK_L": "23c9b8f36ac1c0cddaf869c3733b771c3dc409416a9695df40397cea53e7f39e21f76925fc0c74ca6ee7c7eafad92473fd85758bab8f45fe01aac504"
},
{
"staff": 0,
"countryCode": 492,
"CRIexp": 5,
"venueType": 10,
"venueCategory1": 3,
"venueCategory2": 3,
"periodDuration": 5,
"locationPhone": "33800130000",
"locationPIN": "01234567",
"SK_SA": "34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8",
"PK_SA": "04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5",
"SK_MCTA": "3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd",
"PK_MCTA": "045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4",
"SK_L": "23c9b8f36ac1c0cddaf869c3733b771c3dc409416a9695df40397cea53e7f39e21f76925fc0c74ca6ee7c7eafad92473fd85758bab8f45fe01aac504"
},
{
"staff": 1,
"countryCode": 202,
"CRIexp": 5,
"venueType": 31,
"venueCategory1": 3,
"venueCategory2": 1,
"periodDuration": 10,
"locationPhone": "33800130000",
"locationPIN": "76543210",
"SK_SA": "34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8",
"PK_SA": "04c14d9db89a3dd8da8a366cf26cd67f1de468fb5dc15f240b0d2b96dbdb5f39af962cb0bdc0bafcc9e523bf5cd4eba420c51758f987457954d32f1003bbaaf1c5",
"SK_MCTA": "3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd",
"PK_MCTA": "045f802c016b2d14ef4d7ef01617c67c7506c0cd08aed3e4bcaf34ef5ffaddebb70a073d82c37bc874ce6705cec8b1c4a03b2ccd8f28b0c5034fb8774f2e97b1a4",
"SK_L": "23c9b8f36ac1c0cddaf869c3733b771c3dc409416a9695df40397cea53e7f39e21f76925fc0c74ca6ee7c7eafad92473fd85758bab8f45fe01aac504"
}
]
\ No newline at end of file
......@@ -227,11 +227,11 @@ def lsp_cmp(enc_in, enc_out, dec_out):
elif nbr != 0:
print('LocationMsg failed')
return False
return testok == nbtests
def lsps_cmp(enc_in_file, enc_out_file, dec_out_file):
def lsps_cmp(enc_in_file, enc_out_file, dec_out_file, csv_lsp_file, csv_loc_file):
"""
Compare a list of LSP parameters
----------
......@@ -239,7 +239,8 @@ def lsps_cmp(enc_in_file, enc_out_file, dec_out_file):
enc_out_file: output file in json of the lsp encoder with generated lsp
parameters (time, TLId)
dec_out_file: output file in json of the lsp decoder
csv_lsp_file: save LSP encoding/decoding results to be updated when necessary for junit5 test in ../java/src/test/resources
csv_loc_file: save location encoding/decoding results to be updated when necessary for junit5 test in ../java/src/test/resources
Return
-------
True / False
......@@ -255,9 +256,23 @@ def lsps_cmp(enc_in_file, enc_out_file, dec_out_file):
return False
iok = 0
for idx, _ in enumerate(enc_in_s):
if lsp_cmp(enc_in_s[idx], enc_out_s[idx], dec_out_s[idx]):
enc_in = enc_in_s[idx]
enc_out = enc_out_s[idx]
dec_out = dec_out_s[idx]
if lsp_cmp(enc_in, enc_out, dec_out):
print('TEST PASS:', idx+1)
iok = iok + 1
SEP = ', '
if csv_lsp_file is not None:
row = str(enc_in['staff']) + SEP + str(enc_in['countryCode']) + SEP + str(enc_out['LTId']) + SEP + str(enc_in['CRIexp']) + SEP
row += str(enc_in['venueType']) + SEP + str(enc_in['venueCategory1']) + SEP + str(enc_in['venueCategory2']) + SEP + str(enc_in['periodDuration']) + SEP
row += str(enc_out['ct_periodStart']) + SEP + str(enc_out['t_qrStart']) + SEP + str(enc_in['SK_SA']) + SEP + str(enc_in['PK_SA']) + SEP + str(enc_out['lsp_base64'])
csv_lsp_file.write(row+ '\n')
if csv_loc_file is not None and enc_in.get('locationPhone') is not None :
row = str(enc_in['locationPhone']) + SEP + str(enc_in['locationPIN']) + SEP + str(enc_out['ct_periodStart']*3600) + SEP
row += str(enc_in['SK_SA']) + SEP + str(enc_in['PK_SA']) + SEP
row += str(enc_in['SK_MCTA']) + SEP + str(enc_in['PK_MCTA']) + SEP + str(enc_out['lsp_base64'])
csv_loc_file.write(row+ '\n')
else:
print('TEST FAILED:', idx+1)
......@@ -272,9 +287,15 @@ parser.add_argument("--noencode",
parser.add_argument("--java",
help="encoding part with Java lib (C lib by default)",
action="store_true")
parser.add_argument("--csvtest",
help="saving file testDecoding.csv",
action="store_true")
args = parser.parse_args()
# clean output files
CSV_LSP_TST = 'testLSPDecoding.csv'
CSV_LOC_TST = 'testLocationDecoding.csv'
ENC_IN = 'encode_in.json'
ENC_OUT = 'encode_out.json'
DEC_OUT = 'decode_out.json'
......@@ -282,13 +303,29 @@ if os.path.exists(ENC_OUT) and not args.noencode:
os.remove(ENC_OUT)
if os.path.exists(DEC_OUT):
os.remove(DEC_OUT)
if os.path.exists(DEC_OUT):
os.remove(DEC_OUT)
# testDecoding.csv, to be updated when necessary for junit5 test in ../java/src/test/resources
if args.csvtest:
csv_lsp_file = open(CSV_LSP_TST,"w")
csv_loc_file = open(CSV_LOC_TST,"w")
header = 'staff, countryCode, LTId, CRIexp, venueType, venueCat1, venueCat2, periodDuration, ct_periodStart, t_qrStart, SK_SA, PK_SA, lsp_base64\n'
csv_lsp_file.write(header)
header = 'locationPhone, locationPin, t_periodStart, SK_SA, PK_SA, SK_MCTA, PK_MCTA, lsp_base64\n'
csv_loc_file.write(header)
else:
csv_lsp_file = None
csv_loc_file = None
# encode_in.json -> [lsps_encode] -> encode_out.json
if not args.noencode:
lsps_encode(ENC_IN, ENC_OUT, java=args.java)
# encode_out.json -> [lsps_decode] -> decode_out.json
lsps_decode(ENC_OUT, DEC_OUT)
# compare parameters input or generated (time, ltid) and output paramaters
if lsps_cmp(ENC_IN, ENC_OUT, DEC_OUT):
if lsps_cmp(ENC_IN, ENC_OUT, DEC_OUT, csv_lsp_file, csv_loc_file):
print('ALL TESTS PASS')
else:
print('TESTS FAILED')
if args.csvtest:
csv_lsp_file.close()
csv_loc_file.close()
\ No newline at end of file
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