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

add parameterizeTest

parent 67ce0291
Pipeline #226980 passed with stage
in 1 minute and 30 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>
......
......@@ -20,6 +20,8 @@ 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;
......@@ -114,7 +116,7 @@ class LocationSpecificPartTest {
byte[] encryptedLocationSpecificPart = location.getLocationSpecificPartEncrypted();
assertThat(encryptedLocationSpecificPart).isNotNull();
assertThat(encryptedLocationSpecificPart).isEqualTo(0); // TODO replace by expected value
assertThat(encryptedLocationSpecificPart).isEqualTo(0);
}
......@@ -249,46 +251,50 @@ class LocationSpecificPartTest {
// 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)
*/
@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 {
@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);
LocationSpecificPartDecoder decoder = new LocationSpecificPartDecoder(SecretKey);
LocationSpecificPart lsp = decoder.decrypt(lsp_base64);
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);
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(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);
}
// assertThat(lsp.getQrCodeValidityStartTime()).isEqualTo(qrStartTime);
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);
}
@Test
public void testLocationSpecificPartBase64EciesDecryption() throws NoSuchAlgorithmException, InvalidKeySpecException, IllegalStateException, InvalidCipherTextException, IOException {
/* EC private key from C package */
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, 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=
......@@ -227,6 +227,12 @@ 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
......
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