Commit cec026fe authored by Cypres TAC's avatar Cypres TAC
Browse files

clean and add tests

parent b9549eb6
Pipeline #227478 passed with stage
in 1 minute and 32 seconds
......@@ -14,6 +14,7 @@ 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;
......@@ -76,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])
......@@ -89,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);
}
@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 +174,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,48 +208,122 @@ class LocationSpecificPartTest {
MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, fileOutputStream);
fileOutputStream.close();
}
/**
* Testing base64 decoding from C or Java
*/
@Test
public void testBase64DecodingFromCToJava() {
String lsp64C = "APJexM7Ntkr9l2JO6mpD3HWO9OkU9nDygdP16KhNAiR9JUr05mT9+5kvJbZph/GdRbIqpQCwgFlYkWEr633BiYhJ+x/pc581PYG4aF2ZzjDJfrY5PfZodBKEiWH+Qegtp3x2bw4sfbCM8OPIvPtU7ooyyzj9h7RdKp4GfgeCz9YdikJ8uJYusQaFILrICqswxQzQPhLVHsnkMjAVpayCAxUOVgZbqj5m8lNcMhCxog==";
String lsp64J = "AJMxSV4mHDX9iqjedPJRtpd7XTx53/ZCrZ4l53yFT7CSbiksSWm6vXApD+XeHT5nLEPbVRPXQoY8PJaTakCQNXYa2EUb8UW62n7sMua+UmZwDnf/9OPOVwWyGacP5L94sv0fCk7XnjBbDLhtORCGrdiwkOm3UniGc8gyP41zneHQSmbfzq6kEzFCX2kfKQIXIsFVyCFp7M4KdpVb2oWg2Q/FZr63cBdObwI9mrImCw==";
Base64.getDecoder().decode(lsp64C);
// 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());
}
/**
* Testing the decoding of a LSP in base64 (encoded by C lib)
* testDecoding.csv values are generated by the interoperability test
* launched in python (in project/test)
* testLSPDecoding.csv values are generated by the interoperability test
* launched manually in python (in project/test)
*/
@ParameterizedTest
@CsvFileSource(resources = "/testDecoding.csv", numLinesToSkip = 1)
void testDecodingOfLocationSpecificPartInBase64(int staff, int countryCode, String LTId, int periodDuration, int CRI,
int venueType, int venueCat1, int venueCat2, int periodStartTime, long qrStartTime,
String SecretKey, String lsp_base64) throws CleaEncryptionException {
LocationSpecificPartDecoder decoder = new LocationSpecificPartDecoder(SecretKey);
LocationSpecificPart lsp = decoder.decrypt(lsp_base64);
@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);
assertThat(lsp.isStaff()).isEqualTo(staff==1);
assertThat(lsp.getCountryCode()).isEqualTo(countryCode);
assertThat(lsp.getLocationTemporaryPublicId()).isEqualTo(UUID.fromString(LTId));
assertThat(lsp.getCompressedPeriodStartTime()).isEqualTo(periodStartTime);
// TODO: PROBLEM TO SOLVE
// assertThat(lsp.getQrCodeValidityStartTime()).isEqualTo(qrStartTime);
assertThat(lsp.getQrCodeRenewalIntervalExponentCompact()).isEqualTo(qrCodeRenewalIntervalExponentCompact);
assertThat(lsp.getLocationTemporaryPublicId()).isEqualTo(UUID.fromString(locationTemporaryPublicID));
assertThat(lsp.getPeriodDuration()).isEqualTo(periodDuration);
assertThat(lsp.getQrCodeRenewalIntervalExponentCompact()).isEqualTo(CRI);
assertThat(lsp.getVenueType()).isEqualTo(venueType);
assertThat(lsp.getVenueCategory1()).isEqualTo(venueCat1);
assertThat(lsp.getVenueCategory2()).isEqualTo(venueCat2);
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 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);
}
return randomNumString;
}
/**
* 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);
assertThat(decodedLsp).isEqualTo(lsp);
}
/**
* 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);
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 {
/* EC private key from C package */
......
staff, countryCode, LTId, periodDuration, CRIexp, venueType, venueCat1, venueCat2, periodStartTime, qrStartTime, lsp_base64, SecretKey
0 , 492 , 572d64df-ff59-fa25-bb6b-4887612856e1 , 3, 5 , 12 , 0 , 0 , 1062527 , 3825096280 , 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8 , AFctZN//Wfolu2tIh2EoVuHHo1UwTLwTwlGUxeQEk/zl6Li+LavL4VOytwTrLQb0unX85O4zgvhUb8vTtNhWnCSGgtfE0d5sbwN85aZRLrTkemk+7yQmWlbqsICc9MiMv3ognC2D5DlRF3HEFWoozFOTE0yFKuMM5WuI70pNlbZBM8ApYCBBwwZIk6qJIgOcd++Zy9Tveqsnwo/YSccrVpyUEyKs/zYRg/wWW/6ICA==
1 , 4095 , 572d64df-ff59-fa25-bb6b-4887612856e1 , 255 , 31 , 31 , 15 , 15 , 1062527 , 3825097324 , 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8 , AFctZN//Wfolu2tIh2EoVuFWz+bpCByCd3BakNqmPtsiw6dD96TJOdj915izmOd3eDxHmH9unfS35sbg42sxZbOb6lLue/bQsP5GKGL/bcLIDtenrvI8jrY3I7zUa469OifGWfRlCPEfRl+WxpYaG9O4Y0P+23JL7QBwHJXSdl0uNK+4mSLzP9FJmK7KFQN3qL/P16Xyfc048scGqFQO+AZ3IRNxRnarU6NGpvX2SQ==
1 , 592 , 572d64df-ff59-fa25-bb6b-4887612856e1 , 255 , 31 , 31 , 15 , 15 , 1062527 , 3825097324 , 3108f08b1485adb6f72cfba1b55c7484c906a2a3a0a027c78dcd991ca64c97bd , AFctZN//Wfolu2tIh2EoVuEGkpeCMOXPVvdhrT6S2lztCTXlL+cS9bzKc7l6e+Tfdcp1az4JGiM1At4yW7NxhVP6PLEwJ0DFaqJ0XoIDRQXkqjF9HhdRYR5SL0z4G9Of0b2cmRVd9EhhLY3Fu5Y=
0 , 492 , 572d64df-ff59-fa25-bb6b-4887612856e1 , 10 , 3 , 3 , 1 , 4 , 1062527 , 3825097324 , 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8 , AFctZN//Wfolu2tIh2EoVuEdyvfL2ga8sYbphwFR09/I+8bzpq+CEC0evhV0yXIN79Zf8xtziEVYTw54fex0wpIM+65Ba2mBS/DLo+oyxqLHJdzQOedTAGi0YGvtYLOKJSAJ0opWe/N6qBaWcuxVlhbESdTB3fgX+Eiwba2Q3Gmpf9m72BYiPCY1lk3K5gO7ksEGmL/+P1L8yuPF0Azw73iEUvUwdJPklpyXsNW4/g==
1 , 492 , 572d64df-ff59-fa25-bb6b-4887612856e1 , 10 , 31 , 3 , 1 , 4 , 1062527 , 3825097324 , 34af7f978c5a17772867d929e0b800dd2db74608322d73f2f0cfd19cdcaeccc8 , AFctZN//Wfolu2tIh2EoVuHInA6/gXQDz0rmI3GFnFFmAB5twBtBVeyQxWvg7xHMOdnTuAqeuuHwmPiJdIpBCQRnvunC55Dfof/DTlYDEQugdIg39YZdLQ+KO8PZ66sioc34/RIp28YGErkuKys=
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,17 +227,11 @@ def lsp_cmp(enc_in, enc_out, dec_out):
elif nbr != 0:
print('LocationMsg failed')
return False
if testok == nbtests :
# staff, countryCode, LTId, periodDuration, CRIexp, venueType, venueCat1, venueCat2, periodStartTime, qrStartTime, lsp_base64, SecretKey
print(enc_in['staff'], ',', enc_in['countryCode'], ',', enc_out['LTId'], ',', enc_in['periodDuration'],
',', enc_in['CRIexp'], ',', enc_in['venueType'], ',', enc_in['venueCategory1'], ',', enc_in['venueCategory2'],
',', enc_out['ct_periodStart'], ',', enc_out['t_qrStart'], ',', enc_in['SK_SA'], ',', enc_out['lsp_base64'])
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
----------
......@@ -245,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
......@@ -261,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)
......@@ -278,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'
......@@ -288,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