@@ -12,6 +12,25 @@ public class PackTest
1212 private Mock < IBuildEngine > buildEngine ;
1313 private List < BuildErrorEventArgs > errors ;
1414
15+ private const string PrivateKey = """
16+ -----BEGIN PRIVATE KEY-----
17+ MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAMU/F0sTHCUeJL3U
18+ /rnmcTGQpSdGQrfaAEOTdVZlaNskLL1QyQUi+ejbiFhisDDr2w6yFJCtQ8f717cn
19+ mHLzf3tOZtnLCz5cRcABkNu+9XOPBUpHt+VV445NlpbraWZKEmsXZgJ0yv/jBv8i
20+ HoGIPyvODmn19kbVH0ODOvcVTLmTAgMBAAECgYALC6tsQteypGt+Te0tz9/K3MTC
21+ 3EZkMUsOfbV2bxteGjp/J4T6SqkgBxsth+lB9BNCUWqhZ3KCQnIkCY2Z8lTTI7My
22+ dVgFhO2ch8mEsNlcCH3ZY1HmOzdmO8scExlSE9X4ZgThpCrvE6FRpaIbHnRVko2S
23+ +AJJsuznlpHcjuE7gQJBAOl+oWLCdCcJFMUS1ruSyTtU7HO/Vwu/gqumrpxBtIDX
24+ CSJHq71+PL3yfSZ/SXxRSC0X+HI3CcK8DrG4joOOUrMCQQDYQg2uAXC3Ug02xNtp
25+ 6+GVREFJWSCyYVQYJcRw0ayu3H/z6cRv1LKA/UKUQzrMNic6n0iHJaiwRS0K4t7S
26+ We2hAkAK8PshBJmqxpspjPNxALTbSeR2nA25KDU4U+w0uEN8EheEerVKgOLZx8Yj
27+ iq1n3Osz6b6jo36amHNb0pkjAwVPAkASBf9J30jbnnUHeYSn4Ubdv+CJEmqNM1tk
28+ 39DtbiwsLqhjVbpPb7So13KzFJ9T4beHRTswOE1E058bZykW8vPBAkB8OQ4TbQRs
29+ oTBYOAc/F4JVGrqma04CjEPUn4J/5qzSScI8hkImfJvtZk8Dd8lQ/wpb94KTfWwR
30+ 4IiXOmwPm/Zt
31+ -----END PRIVATE KEY-----
32+ """ ;
33+
1534 [ TestInitialize ( ) ]
1635 public void Startup ( )
1736 {
@@ -30,10 +49,11 @@ public void Pack_Success()
3049 PluginAssembly = "MySamplePluginTemplate" ,
3150 PluginAuthors = "ObsidianTeam" ,
3251 PluginVersion = "1.0.0" ,
33- PluginPublishDir = ".\\ Resources\\ " ,
3452 PluginDependencies = [ ] ,
3553 BuildEngine = this . buildEngine . Object ,
36- PluginName = "My Sample Plugin"
54+ PluginName = "My Sample Plugin" ,
55+ PluginSigningKey = PrivateKey ,
56+ PluginPublishDir = "."
3757 } ;
3858
3959 var success = packTask . Execute ( ) ;
@@ -54,27 +74,49 @@ public void Pack_Read_Success()
5474 PluginAssembly = "MySamplePluginTemplate" ,
5575 PluginAuthors = "ObsidianTeam" ,
5676 PluginVersion = "1.0.0" ,
57- PluginPublishDir = ".\\ Resources \\ " ,
77+ PluginPublishDir = "." ,
5878 PluginDependencies = [ ] ,
5979 BuildEngine = this . buildEngine . Object ,
6080 PluginName = "My Sample Plugin" ,
61- ProjectUrl = "https://obsidianmc.net"
81+ ProjectUrl = "https://obsidianmc.net" ,
82+ PluginSigningKey = PrivateKey ,
6283 } ;
6384
6485 var success = packTask . Execute ( ) ;
6586
6687 Assert . IsTrue ( success ) ;
6788 Assert . IsTrue ( File . Exists ( packTask . PackedFile ) ) ;
68-
6989 using ( var file = File . OpenRead ( packTask . PackedFile ) )
7090 {
7191 using var reader = new BinaryReader ( file ) ;
7292
7393 var headerId = Encoding . ASCII . GetString ( reader . ReadBytes ( 4 ) ) ;
7494 var apiVersion = reader . ReadString ( ) ;
7595
96+ var hash = reader . ReadBytes ( SHA384 . HashSizeInBytes ) ;
97+ var signed = reader . ReadBoolean ( ) ;
98+ if ( signed )
99+ {
100+ var length = reader . ReadInt32 ( ) ;
101+ reader . ReadBytes ( length ) ;
102+ }
103+
104+ var dataLength = reader . ReadInt32 ( ) ;
105+ var dataPos = file . Position ;
106+
107+ using ( var sha384 = SHA384 . Create ( ) )
108+ {
109+ var verifyHash = sha384 . ComputeHash ( file ) ;
110+ var hashString = Convert . ToHexString ( verifyHash ) ;
111+
112+ Assert . IsTrue ( verifyHash . SequenceEqual ( hash ) , $ "Expected { Convert . ToHexString ( hash ) } got { hashString } ") ;
113+ }
114+
115+ file . Position = dataPos ;
116+
76117 var assemblyName = reader . ReadString ( ) ;
77118 var version = reader . ReadString ( ) ;
119+
78120 var name = reader . ReadString ( ) ;
79121 var id = reader . ReadString ( ) ;
80122 var authors = reader . ReadString ( ) ;
@@ -83,18 +125,11 @@ public void Pack_Read_Success()
83125
84126 var dependencies = new List < PluginDependency > ( ) ;
85127 var dependsLength = reader . ReadInt32 ( ) ;
86-
87- if ( dependsLength > 0 )
128+ for ( int i = 0 ; i < dependsLength ; i ++ )
88129 {
89- for ( int i = 0 ; i < dependsLength ; i ++ )
90- {
91- dependencies . Add ( new ( reader . ReadString ( ) , reader . ReadString ( ) , reader . ReadBoolean ( ) ) ) ;
92- }
130+ dependencies . Add ( new ( reader . ReadString ( ) , reader . ReadString ( ) , reader . ReadBoolean ( ) ) ) ;
93131 }
94132
95- var hash = reader . ReadBytes ( SHA384 . HashSizeInBytes ) ;
96- var signed = reader . ReadBoolean ( ) ;
97- var dataLength = reader . ReadInt32 ( ) ;
98133 var entryCount = reader . ReadInt32 ( ) ;
99134
100135 Assert . AreEqual ( "OBBY" , headerId ) ;
@@ -113,8 +148,8 @@ public void Pack_Read_Success()
113148 Console . WriteLine ( $ "Hash: { Convert . ToHexString ( hash ) } ") ;
114149 Console . WriteLine ( $ "Data Length: { dataLength } ") ;
115150
116- Assert . IsFalse ( signed ) ;
117- Assert . AreEqual ( 9 , entryCount ) ;
151+ Assert . IsTrue ( signed ) ;
152+ Assert . AreEqual ( 37 , entryCount ) ;
118153 }
119154
120155 File . Delete ( packTask . PackedFile ) ;
0 commit comments