Skip to content

Commit cae12af

Browse files
committed
tests: added test that verifies that CommandChainingTransformTests stops sending data
1 parent 487494f commit cae12af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Yubico.YubiKey/tests/unit/Yubico/YubiKey/Pipelines/CommandChainingTransformTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public void Invoke_CommandApduWithLargeDataBuffer_OrsHex10ToClaOnAllExceptLast()
153153

154154
_ = mockTransform
155155
.Setup(x => x.Invoke(It.IsAny<CommandApdu>(), It.IsAny<Type>(), It.IsAny<Type>()))
156+
.Returns(new ResponseApdu([], 0x90))
156157
.Callback<CommandApdu, Type, Type>((a, b, c) => observedCla.Add(a.Cla));
157158

158159
// Act
@@ -180,6 +181,7 @@ public void Invoke_CommandApduWithLargeDataBuffer_AllOtherApduPropertiesRemainUn
180181

181182
_ = mockTransform
182183
.Setup(x => x.Invoke(It.IsAny<CommandApdu>(), It.IsAny<Type>(), It.IsAny<Type>()))
184+
.Returns(new ResponseApdu([], 0x90))
183185
.Callback<CommandApdu, Type, Type>((a, b, c) => observedApdus.Add(a));
184186

185187
// Act
@@ -209,6 +211,7 @@ public void Invoke_CommandApduWithLargeDataBuffer_SplitsDataAcrossInvokeCalls()
209211

210212
_ = mockTransform
211213
.Setup(x => x.Invoke(It.IsAny<CommandApdu>(), It.IsAny<Type>(), It.IsAny<Type>()))
214+
.Returns(new ResponseApdu([], 0x90))
212215
.Callback<CommandApdu, Type, Type>((a, b, c) => observedApdus.Add(a.Data.ToArray()));
213216

214217
// Act
@@ -219,5 +222,34 @@ public void Invoke_CommandApduWithLargeDataBuffer_SplitsDataAcrossInvokeCalls()
219222
Assert.Equal(new byte[] { 5, 6, 7, 8 }, observedApdus[1]);
220223
Assert.Equal(new byte[] { 9, 10 }, observedApdus[2]);
221224
}
225+
226+
[Fact]
227+
public void Invoke_CommandApduWithLargeDataBuffer_DoesntProcessAllBytes()
228+
{
229+
var observedApdus = new List<byte[]>();
230+
231+
// Arrange
232+
var mockTransform = new Mock<IApduTransform>();
233+
var transform = new CommandChainingTransform(mockTransform.Object) { MaxChunkSize = 4 };
234+
var commandApdu = new CommandApdu
235+
{
236+
Data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
237+
};
238+
239+
_ = mockTransform
240+
.Setup(x => x.Invoke(It.IsAny<CommandApdu>(), It.IsAny<Type>(), It.IsAny<Type>()))
241+
.Returns(new ResponseApdu([], 0x6700))
242+
.Callback<CommandApdu, Type, Type>((a, b, c) =>
243+
{
244+
observedApdus.Add(a.Data.ToArray());
245+
});
246+
247+
// Act
248+
_ = transform.Invoke(commandApdu, typeof(object), typeof(object));
249+
250+
// Assert
251+
// Should only make one pass with 4 bytes, before exiting
252+
Assert.Equal(4, observedApdus[0].Length);
253+
}
222254
}
223255
}

0 commit comments

Comments
 (0)