This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
/
CloseSessionRespParsTest.java
113 lines (98 loc) · 4.98 KB
/
CloseSessionRespParsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/********************************************************************************
* Copyright (c) 2018 Calypso Networks Association https://www.calypsonet-asso.org/
*
* See the NOTICE file(s) distributed with this work for additional information regarding copyright
* ownership.
*
* This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.keyple.calypso.command.po.parser.security;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.keyple.core.command.AbstractApduResponseParser;
import org.eclipse.keyple.core.seproxy.message.ApduResponse;
import org.eclipse.keyple.core.seproxy.message.SeResponse;
import org.eclipse.keyple.core.seproxy.message.SelectionStatus;
import org.eclipse.keyple.core.util.ByteArrayUtil;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class CloseSessionRespParsTest {
@Test
public void closeSessionRespPars() {
byte[] response = {0x4D, (byte) 0xBD, (byte) 0xC9, 0x60, (byte) 0x90, 0x00};
List<ApduResponse> responses = new ArrayList<ApduResponse>();
ApduResponse apduResponse = new ApduResponse(response, null);
responses.add(apduResponse);
SeResponse seResponse =
new SeResponse(true, true,
new SelectionStatus(null,
new ApduResponse(ByteArrayUtil.fromHex("9000"), null), true),
responses);
AbstractApduResponseParser apduResponseParser =
new CloseSessionRespPars(seResponse.getApduResponses().get(0), null);
Assert.assertArrayEquals(response, apduResponseParser.getApduResponse().getBytes());
}
@Test
public void TestToPOHalfSessionSignature() {
byte[] apduResponse =
new byte[] {(byte) 0x4D, (byte) 0xBD, (byte) 0xC9, 0x60, (byte) 0x90, 0x00};
byte[] apduResponseCaseTwo = new byte[] {(byte) 0xA8, 0x31, (byte) 0xC3, 0x3E, (byte) 0xA7,
0x21, (byte) 0xC2, 0x2E, (byte) 0x90, 0x00};
byte[] apduResponseCaseThree =
new byte[] {(byte) 0xA8, 0x31, (byte) 0xC3, (byte) 0x90, 0x00};
byte[] sessionSignature = new byte[] {(byte) 0x4D, (byte) 0xBD, (byte) 0xC9, 0x60};
byte[] sessionSignatureCaseTwo = new byte[] {(byte) 0xA7, 0x21, (byte) 0xC2, 0x2E};
{// Case Length = 4
CloseSessionRespPars pars =
new CloseSessionRespPars(new ApduResponse(apduResponse, null), null);
Assert.assertArrayEquals(sessionSignature, pars.getSignatureLo());
}
{// Case Length = 8
CloseSessionRespPars pars =
new CloseSessionRespPars(new ApduResponse(apduResponseCaseTwo, null), null);
Assert.assertArrayEquals(sessionSignatureCaseTwo, pars.getSignatureLo());
}
{// Case Other
try {
CloseSessionRespPars pars = new CloseSessionRespPars(
new ApduResponse(apduResponseCaseThree, null), null);
Assert.fail();
} catch (IllegalArgumentException ex) {
/* expected case */
}
}
}
@Test
public void existingTestConverted() {
CloseSessionRespPars parser = new CloseSessionRespPars(
new ApduResponse(ByteArrayUtil.fromHex("9000h"), null), null);
// This assert wasn't passing
Assert.assertEquals("", ByteArrayUtil.toHex(parser.getSignatureLo()));
Assert.assertEquals("", ByteArrayUtil.toHex(parser.getPostponedData()));
}
@Test // Calypso / page 105 / Example command aborting a session:
public void abortingASession() {
CloseSessionRespPars parser = new CloseSessionRespPars(
new ApduResponse(ByteArrayUtil.fromHex("FEDCBA98 9000h"), null), null);
}
@Test // Calypso / page 105 / Example command, Lc=4, without postponed data:
public void lc4withoutPostponedData() {
CloseSessionRespPars parser = new CloseSessionRespPars(
new ApduResponse(ByteArrayUtil.fromHex("FEDCBA98 9000h"), null), null);
Assert.assertEquals("FEDCBA98", ByteArrayUtil.toHex(parser.getSignatureLo()));
Assert.assertEquals("", ByteArrayUtil.toHex(parser.getPostponedData()));
}
@Test // Calypso / page 105 / Example command, Lc=4, with postponed data:
public void lc4WithPostponedData() {
CloseSessionRespPars parser = new CloseSessionRespPars(
new ApduResponse(ByteArrayUtil.fromHex("04 345678 FEDCBA98 9000h"), null), null);
Assert.assertEquals("FEDCBA98", ByteArrayUtil.toHex(parser.getSignatureLo()));
Assert.assertEquals("345678", ByteArrayUtil.toHex(parser.getPostponedData()));
}
}