@@ -9,19 +9,26 @@ public class PluginHashCalculatorTests
99{
1010 private string _testDirectory ;
1111 private string _testFilePath ;
12+ private bool _originalBypassSetting ;
1213
1314 [ SetUp ]
1415 public void SetUp ( )
1516 {
1617 _testDirectory = Path . Join ( Path . GetTempPath ( ) , "LogExpertPluginHashTests" ) ;
1718 _ = Directory . CreateDirectory ( _testDirectory ) ;
1819 _testFilePath = Path . Join ( _testDirectory , "test-plugin.dll" ) ;
20+
21+ // Save original bypass setting and disable it for tests that need actual verification
22+ _originalBypassSetting = PluginHashCalculator . BypassHashVerification ;
1923 }
2024
2125 [ TearDown ]
2226 [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Design" , "CA1031:Do not catch general exception types" , Justification = "Unit testcases" ) ]
2327 public void TearDown ( )
2428 {
29+ // Restore original bypass setting
30+ PluginHashCalculator . BypassHashVerification = _originalBypassSetting ;
31+
2532 try
2633 {
2734 if ( Directory . Exists ( _testDirectory ) )
@@ -121,6 +128,7 @@ public void CalculateHash_WhitespacePath_ThrowsArgumentException ()
121128 public void VerifyHash_MatchingHash_ReturnsTrue ( )
122129 {
123130 // Arrange
131+ PluginHashCalculator . BypassHashVerification = false ;
124132 var testContent = "Test content for hash verification" ;
125133 File . WriteAllText ( _testFilePath , testContent ) ;
126134 var expectedHash = PluginHashCalculator . CalculateHash ( _testFilePath ) ;
@@ -136,6 +144,7 @@ public void VerifyHash_MatchingHash_ReturnsTrue ()
136144 public void VerifyHash_MismatchedHash_ReturnsFalse ( )
137145 {
138146 // Arrange
147+ PluginHashCalculator . BypassHashVerification = false ;
139148 var testContent = "Test content" ;
140149 File . WriteAllText ( _testFilePath , testContent ) ;
141150 var wrongHash = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" ;
@@ -151,6 +160,7 @@ public void VerifyHash_MismatchedHash_ReturnsFalse ()
151160 public void VerifyHash_CaseInsensitiveUpperCase_ReturnsTrue ( )
152161 {
153162 // Arrange
163+ PluginHashCalculator . BypassHashVerification = false ;
154164 var testContent = "Test content" ;
155165 File . WriteAllText ( _testFilePath , testContent ) ;
156166 var hash = PluginHashCalculator . CalculateHash ( _testFilePath ) ;
@@ -168,6 +178,7 @@ public void VerifyHash_CaseInsensitiveUpperCase_ReturnsTrue ()
168178 public void VerifyHash_CaseInsensitiveLowerCase_ReturnsTrue ( )
169179 {
170180 // Arrange
181+ PluginHashCalculator . BypassHashVerification = false ;
171182 var testContent = "Test content" ;
172183 File . WriteAllText ( _testFilePath , testContent ) ;
173184 var hash = PluginHashCalculator . CalculateHash ( _testFilePath ) ;
@@ -184,6 +195,7 @@ public void VerifyHash_CaseInsensitiveLowerCase_ReturnsTrue ()
184195 public void VerifyHash_ModifiedFile_ReturnsFalse ( )
185196 {
186197 // Arrange
198+ PluginHashCalculator . BypassHashVerification = false ;
187199 var originalContent = "Original content" ;
188200 File . WriteAllText ( _testFilePath , originalContent ) ;
189201 var originalHash = PluginHashCalculator . CalculateHash ( _testFilePath ) ;
@@ -203,6 +215,7 @@ public void VerifyHash_ModifiedFile_ReturnsFalse ()
203215 public void VerifyHash_NullExpectedHash_ThrowsArgumentNullException ( )
204216 {
205217 // Arrange
218+ PluginHashCalculator . BypassHashVerification = false ;
206219 File . WriteAllText ( _testFilePath , "Test content" ) ;
207220
208221 // Act & Assert
@@ -213,12 +226,29 @@ public void VerifyHash_NullExpectedHash_ThrowsArgumentNullException ()
213226 public void VerifyHash_EmptyExpectedHash_ThrowsArgumentException ( )
214227 {
215228 // Arrange
229+ PluginHashCalculator . BypassHashVerification = false ;
216230 File . WriteAllText ( _testFilePath , "Test content" ) ;
217231
218232 // Act & Assert
219233 _ = Assert . Throws < ArgumentException > ( ( ) => PluginHashCalculator . VerifyHash ( _testFilePath , string . Empty ) ) ;
220234 }
221235
236+ [ Test ]
237+ public void VerifyHash_WithBypassEnabled_AlwaysReturnsTrue ( )
238+ {
239+ // Arrange
240+ PluginHashCalculator . BypassHashVerification = true ;
241+ var testContent = "Test content" ;
242+ File . WriteAllText ( _testFilePath , testContent ) ;
243+ var wrongHash = "WRONGHASH123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456" ;
244+
245+ // Act
246+ var result = PluginHashCalculator . VerifyHash ( _testFilePath , wrongHash ) ;
247+
248+ // Assert
249+ Assert . That ( result , Is . True , "Bypass mode should always return true" ) ;
250+ }
251+
222252 [ Test ]
223253 public void CalculateHashes_MultipleFiles_ReturnsAllHashes ( )
224254 {
0 commit comments