Skip to content

Commit 32256bf

Browse files
committed
tests: PivSession
fix tests with auth add complex pin and puk
1 parent c268c1d commit 32256bf

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Piv/PinNoCollectorTests.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace Yubico.YubiKey.Piv
2323
[Trait(TraitTypes.Category, TestCategories.Simple)]
2424
public class PinNoCollectorTests : PivSessionIntegrationTestBase
2525
{
26-
2726
[Theory]
2827
[InlineData(StandardTestDevice.Fw5)]
2928
public void VerifyPin_Sign_Succeeds(
@@ -54,7 +53,7 @@ public void VerifyPin_WrongPin_ReturnsFalse(
5453

5554
// Act
5655
var isValid = Session.TryVerifyPin(pin, out var retriesRemaining);
57-
56+
5857
// Assert
5958
Assert.False(isValid);
6059
_ = Assert.NotNull(retriesRemaining);
@@ -94,24 +93,22 @@ public void ChangePuk_Succeeds(
9493
{
9594
// Arrange
9695
TestDeviceType = testDeviceType;
97-
var newPuk = "gjH@5K!8"u8.ToArray();
98-
var newPin = "1@$#5s!8"u8.ToArray();
9996

10097
using (var pivSession = GetSession(authenticate: false))
10198
{
10299
pivSession.ResetApplication();
103-
var isValid = pivSession.TryChangePuk(DefaultPuk, newPuk, out var retriesRemaining);
100+
var isValid = pivSession.TryChangePuk(DefaultPuk, ComplexPuk, out var retriesRemaining);
104101
Assert.True(isValid);
105102
Assert.Null(retriesRemaining);
106103
}
107104

108105
using (var pivSession = GetSession(authenticate: false))
109106
{
110-
var isValid = pivSession.TryResetPin(newPuk, newPin, out var retriesRemaining);
107+
var isValid = pivSession.TryResetPin(ComplexPuk, ComplexPin, out var retriesRemaining);
111108
Assert.True(isValid);
112109
Assert.Null(retriesRemaining);
113110

114-
isValid = pivSession.TryVerifyPin(newPin, out retriesRemaining);
111+
isValid = pivSession.TryVerifyPin(ComplexPin, out retriesRemaining);
115112
Assert.True(isValid);
116113
Assert.Null(retriesRemaining);
117114

@@ -135,27 +132,25 @@ public void ChangeRetryCounts_Succeeds(
135132
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
136133
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
137134
};
138-
var newPuk = "gjH@5K!8"u8.ToArray();
139-
var newPin = "1@$#5s!8"u8.ToArray();
140-
135+
141136
using (var pivSession = GetSession(authenticate: false))
142137
{
143-
var isValid = pivSession.TryChangePin(DefaultPin, newPin, out var retriesRemaining);
138+
var isValid = pivSession.TryChangePin(DefaultPin, ComplexPin, out var retriesRemaining);
144139
Assert.True(isValid);
145140
Assert.Null(retriesRemaining);
146141

147-
isValid = pivSession.TryChangePuk(DefaultPuk, newPuk, out retriesRemaining);
142+
isValid = pivSession.TryChangePuk(DefaultPuk, ComplexPuk, out retriesRemaining);
148143
Assert.Null(retriesRemaining);
149144
Assert.True(isValid);
150145
}
151146

152147
using (var pivSession = GetSession(authenticate: false))
153148
{
154-
var isValid = pivSession.TryVerifyPin(newPin, out var retriesRemaining);
149+
var isValid = pivSession.TryVerifyPin(ComplexPin, out var retriesRemaining);
155150
Assert.True(isValid);
156151
Assert.Null(retriesRemaining);
157152

158-
isValid = pivSession.TryResetPin(newPuk, DefaultPin, out retriesRemaining);
153+
isValid = pivSession.TryResetPin(ComplexPuk, DefaultPin, out retriesRemaining);
159154
Assert.True(isValid);
160155
Assert.Null(retriesRemaining);
161156
}
@@ -166,30 +161,31 @@ public void ChangeRetryCounts_Succeeds(
166161
Assert.True(isValid);
167162
Assert.Null(retriesRemaining);
168163

169-
isValid = pivSession.TryChangePin(DefaultPin, newPin, out retriesRemaining);
164+
isValid = pivSession.TryChangePin(DefaultPin, ComplexPin, out retriesRemaining);
170165
Assert.True(isValid);
171166
Assert.Null(retriesRemaining);
172167

173-
isValid = pivSession.TryVerifyPin(newPin, out retriesRemaining);
168+
isValid = pivSession.TryVerifyPin(ComplexPin, out retriesRemaining);
174169
Assert.Null(retriesRemaining);
175170
Assert.True(isValid);
176171
}
177172

178173
using (var pivSession = GetSession(authenticate: false))
179174
{
180-
var isValid = pivSession.TryChangePinAndPukRetryCounts(mgmtKey, newPin, 7, 8, out var retriesRemaining);
175+
var isValid =
176+
pivSession.TryChangePinAndPukRetryCounts(mgmtKey, ComplexPin, 7, 8, out var retriesRemaining);
181177
Assert.True(isValid);
182178
Assert.Null(retriesRemaining);
183179

184180
isValid = pivSession.TryVerifyPin(DefaultPin, out retriesRemaining);
185181
Assert.True(isValid);
186182
Assert.Null(retriesRemaining);
187183

188-
isValid = pivSession.TryResetPin(DefaultPuk, newPin, out retriesRemaining);
184+
isValid = pivSession.TryResetPin(DefaultPuk, ComplexPin, out retriesRemaining);
189185
Assert.True(isValid);
190186
Assert.Null(retriesRemaining);
191187

192-
isValid = pivSession.TryChangePin(newPin, DefaultPin, out retriesRemaining);
188+
isValid = pivSession.TryChangePin(ComplexPin, DefaultPin, out retriesRemaining);
193189
Assert.True(isValid);
194190
Assert.Null(retriesRemaining);
195191
}

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Piv/PivSessionIntegrationTestBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class PivSessionIntegrationTestBase : IDisposable
2424
{
2525
public static readonly ReadOnlyMemory<byte> DefaultPin = "123456"u8.ToArray();
2626
public static readonly ReadOnlyMemory<byte> DefaultPuk = "12345678"u8.ToArray();
27+
public static readonly ReadOnlyMemory<byte> ComplexPuk = "gjH@5K!8"u8.ToArray();
28+
public static readonly ReadOnlyMemory<byte> ComplexPin = "1@$#5s!8"u8.ToArray();
2729

2830
public static readonly ReadOnlyMemory<byte> DefaultManagementKey = new byte[] // Both Aes and TDes
2931
{

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Piv/PivSessionTests.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void Auth_ThenWrongKey()
101101
Assert.Equal(ResponseStatus.Success, genPairResponse.Status);
102102

103103
SetKeyFlag(1);
104-
TryAuthenticate(true, false);
104+
TryAuthenticate(false, false);
105105
Assert.Equal(AuthenticateManagementKeyResult.SingleAuthenticationFailed,
106106
Session.ManagementKeyAuthenticationResult);
107107

@@ -139,19 +139,8 @@ public void ChangePuk()
139139
[Fact]
140140
public void ResetPin()
141141
{
142-
SetKeyFlag(0);
143142
var isChanged = Session.TryResetPin();
144143
Assert.True(isChanged);
145-
146-
isChanged = Session.TryChangePuk();
147-
Assert.True(isChanged);
148-
149-
SetKeyFlag(1);
150-
isChanged = Session.TryResetPin();
151-
Assert.True(isChanged);
152-
153-
isChanged = Session.TryChangePuk();
154-
Assert.True(isChanged);
155144
}
156145

157146
[Fact]

0 commit comments

Comments
 (0)