@@ -6,67 +6,78 @@ namespace Yubico.YubiKey.Pipelines;
6
6
public class OtpErrorTransformTests
7
7
{
8
8
[ Theory ]
9
- [ InlineData ( 0 , 1 ) ] // First increment
10
- [ InlineData ( 5 , 6 ) ] // Normal increment
11
- [ InlineData ( 254 , 255 ) ] // Near byte boundary
12
- [ InlineData ( 257 , 258 ) ] // Near byte boundary
13
-
14
- public void IsValidSequenceProgression_NormalIncrement_ReturnsTrue ( int before , int after )
9
+ [ InlineData ( 0 , 1 ) ] // First increment
10
+ [ InlineData ( 5 , 6 ) ] // Normal increment
11
+ [ InlineData ( 254 , 255 ) ] // Near byte boundary
12
+ public void IsValidSequenceProgression_NormalIncrement_ReturnsTrue (
13
+ byte before ,
14
+ byte after )
15
15
{
16
- var status = CreateOtpStatus ( touchLevel : 0xFF ) ; // TouchLevel irrelevant
17
-
18
- bool isValid = OtpErrorTransform . IsValidSequenceProgression ( before , after , status ) ;
19
-
16
+ var beforeStatus = CreateOtpStatus ( before , hasConfigs : true ) ;
17
+ var afterStatus = CreateOtpStatus ( after , hasConfigs : true ) ;
18
+
19
+ var isValid = OtpErrorTransform . IsValidSequenceProgression ( beforeStatus , afterStatus ) ;
20
+
20
21
Assert . True ( isValid ) ;
21
22
}
22
23
23
24
[ Theory ]
24
- [ InlineData ( 0 , 2 ) ] // Skip increment
25
- [ InlineData ( 5 , 7 ) ] // Jump by 2
26
- [ InlineData ( 10 , 8 ) ] // Backwards
27
- public void IsValidSequenceProgression_InvalidIncrement_ReturnsFalse ( int before , int after )
25
+ [ InlineData ( 0 , 2 ) ] // Skip increment
26
+ [ InlineData ( 5 , 7 ) ] // Jump by 2
27
+ [ InlineData ( 10 , 8 ) ] // Backwards
28
+ [ InlineData ( 255 , 0 ) ] // Byte overflow (should be rejected as normal increment)
29
+ public void IsValidSequenceProgression_InvalidIncrement_ReturnsFalse (
30
+ byte before ,
31
+ byte after )
28
32
{
29
- var status = CreateOtpStatus ( touchLevel : 0x00 ) ; // TouchLevel irrelevant
30
-
31
- bool isValid = OtpErrorTransform . IsValidSequenceProgression ( before , after , status ) ;
32
-
33
+ var beforeStatus = CreateOtpStatus ( before , hasConfigs : true ) ;
34
+ var afterStatus = CreateOtpStatus ( after , hasConfigs : true ) ; // Still has configs
35
+
36
+ var isValid = OtpErrorTransform . IsValidSequenceProgression ( beforeStatus , afterStatus ) ;
37
+
33
38
Assert . False ( isValid ) ;
34
39
}
35
40
36
41
[ Theory ]
37
- [ InlineData ( 1 , 0x00 ) ] // Config bits clear
38
- [ InlineData ( 5 , 0x20 ) ] // Upper bits set, config clear
39
- [ InlineData ( 255 , 0xE0 ) ] // Multiple upper bits, config clear
40
- public void IsValidSequenceProgression_ValidReset_ReturnsTrue ( int before , byte touchLevel )
42
+ [ InlineData ( 1 ) ] // Delete from sequence 1
43
+ [ InlineData ( 5 ) ] // Delete from sequence 5
44
+ [ InlineData ( 255 ) ] // Delete from sequence 255
45
+ public void IsValidSequenceProgression_ValidReset_ReturnsTrue (
46
+ byte before )
41
47
{
42
- var status = CreateOtpStatus ( touchLevel ) ;
43
-
44
- bool isValid = OtpErrorTransform . IsValidSequenceProgression ( before , 0 , status ) ;
45
-
48
+ var beforeStatus = CreateOtpStatus ( before , hasConfigs : true ) ;
49
+ var afterStatus = CreateOtpStatus ( 0 , hasConfigs : false ) ; // No configs remain
50
+
51
+ var isValid = OtpErrorTransform . IsValidSequenceProgression ( beforeStatus , afterStatus ) ;
52
+
46
53
Assert . True ( isValid ) ;
47
54
}
48
55
49
56
[ Theory ]
50
- [ InlineData ( 0 , 0x00 ) ] // Already zero (invalid before state)
51
- [ InlineData ( 1 , 0x01 ) ] // Config bit set
52
- [ InlineData ( 5 , 0x1F ) ] // All config bits set
53
- [ InlineData ( 5 , 0x21 ) ] // Config + upper bits set
54
- public void IsValidSequenceProgression_InvalidReset_ReturnsFalse ( int before , byte touchLevel )
57
+ [ InlineData ( 0 , false ) ] // Already zero
58
+ [ InlineData ( 1 , true ) ] // Reset but configs still exist
59
+ [ InlineData ( 5 , true ) ] // Reset but configs still exist
60
+ public void IsValidSequenceProgression_InvalidReset_ReturnsFalse (
61
+ byte before ,
62
+ bool afterHasConfigs )
55
63
{
56
- var status = CreateOtpStatus ( touchLevel ) ;
57
-
58
- bool isValid = OtpErrorTransform . IsValidSequenceProgression ( before , 0 , status ) ;
59
-
64
+ var beforeStatus = CreateOtpStatus ( before , hasConfigs : true ) ;
65
+ var afterStatus = CreateOtpStatus ( 0 , hasConfigs : afterHasConfigs ) ;
66
+
67
+ var isValid = OtpErrorTransform . IsValidSequenceProgression ( beforeStatus , afterStatus ) ;
68
+
60
69
Assert . False ( isValid ) ;
61
70
}
62
71
63
- private static OtpStatus CreateOtpStatus ( byte touchLevel ) => new ( )
72
+ private static OtpStatus CreateOtpStatus (
73
+ byte sequenceNumber ,
74
+ bool hasConfigs ) => new ( )
64
75
{
65
76
FirmwareVersion = new FirmwareVersion ( ) ,
66
- SequenceNumber = 0 ,
67
- TouchLevel = touchLevel ,
68
- ShortPressConfigured = false ,
69
- LongPressConfigured = false ,
77
+ SequenceNumber = sequenceNumber ,
78
+ TouchLevel = 0x00 ,
79
+ ShortPressConfigured = hasConfigs ,
80
+ LongPressConfigured = false , // Only test one slot for simplicity
70
81
ShortPressRequiresTouch = false ,
71
82
LongPressRequiresTouch = false ,
72
83
LedBehaviorInverted = false
0 commit comments