Skip to content

Commit dc7ac8d

Browse files
committed
fix: update test
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
1 parent 75a1d0b commit dc7ac8d

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Notation.Plugin.AzureKeyVault.Tests/Certificate/Pkcs12Tests.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System;
12
using System.IO;
23
using System.Security.Cryptography.Pkcs;
4+
using System.Text;
5+
using Notation.Plugin.Protocol;
36
using Xunit;
47

58
namespace Notation.Plugin.AzureKeyVault.Certificate.Tests
@@ -14,10 +17,36 @@ public void RemoveMac()
1417
Pkcs12Info originPfx = Pkcs12Info.Decode(data, out _);
1518
Assert.True(originPfx.IntegrityMode == Pkcs12IntegrityMode.Password);
1619

20+
// remove MAC for the pfx file
21+
byte[] newData = Pkcs12.RemoveMac(data);
22+
Pkcs12Info pfxWithoutMac = Pkcs12Info.Decode(newData, out _);
23+
Assert.True(pfxWithoutMac.IntegrityMode == Pkcs12IntegrityMode.None);
24+
}
25+
26+
[Fact]
27+
public void RemoveMac_WithInvalidMac()
28+
{
29+
// read the pfx file
30+
byte[] data = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "TestData", "cert_invalid_mac.pfx"));
31+
Pkcs12Info originPfx = Pkcs12Info.Decode(data, out _);
32+
Assert.True(originPfx.IntegrityMode == Pkcs12IntegrityMode.Password);
33+
1734
// decrypt the pfx file
18-
byte[] decryptedData = Pkcs12.RemoveMac(data);
19-
Pkcs12Info decryptedPfx = Pkcs12Info.Decode(decryptedData, out _);
20-
Assert.True(decryptedPfx.IntegrityMode == Pkcs12IntegrityMode.None);
35+
Assert.Throws<ValidationException>(() => Pkcs12.RemoveMac(data));
36+
}
37+
38+
[Fact]
39+
public void RemoveMac_withoutMac(){
40+
// read the pfx file
41+
byte[] data = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "TestData", "cert_without_mac.pfx"));
42+
Pkcs12Info originPfx = Pkcs12Info.Decode(data, out _);
43+
Assert.True(originPfx.IntegrityMode == Pkcs12IntegrityMode.None);
44+
45+
// remove MAC for the pfx file
46+
byte[] newData = Pkcs12.RemoveMac(data);
47+
Pkcs12Info pfxWithoutMac = Pkcs12Info.Decode(newData, out _);
48+
Assert.True(pfxWithoutMac.IntegrityMode == Pkcs12IntegrityMode.None);
49+
2150
}
2251
}
2352
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)