16
16
using Xunit ;
17
17
using Xunit . Abstractions ;
18
18
using Microsoft . DotNet . Build . Tasks . Installers ;
19
+ using Microsoft . DotNet . StrongName ;
19
20
20
21
namespace Microsoft . DotNet . SignTool . Tests
21
22
{
@@ -3028,11 +3029,11 @@ public void RunWixToolThrowsErrorIfWixToolsProvidedButDirDoesNotExist()
3028
3029
[ Fact ]
3029
3030
public void MissingStrongNameSignaturesDoNotValidate ( )
3030
3031
{
3031
- StrongName . IsSigned ( GetResourcePath ( "AspNetCoreCrossLib.dll" ) ) . Should ( ) . BeFalse ( ) ;
3032
- StrongName . IsSigned ( GetResourcePath ( "CoreLibCrossARM.dll" ) ) . Should ( ) . BeFalse ( ) ;
3033
- StrongName . IsSigned ( GetResourcePath ( "EmptyPKT.dll" ) ) . Should ( ) . BeFalse ( ) ;
3034
- StrongName . IsSigned ( GetResourcePath ( "DelaySigned.dll" ) ) . Should ( ) . BeFalse ( ) ;
3035
- StrongName . IsSigned ( GetResourcePath ( "ProjectOne.dll" ) ) . Should ( ) . BeFalse ( ) ;
3032
+ StrongNameHelper . IsSigned ( GetResourcePath ( "AspNetCoreCrossLib.dll" ) ) . Should ( ) . BeFalse ( ) ;
3033
+ StrongNameHelper . IsSigned ( GetResourcePath ( "CoreLibCrossARM.dll" ) ) . Should ( ) . BeFalse ( ) ;
3034
+ StrongNameHelper . IsSigned ( GetResourcePath ( "EmptyPKT.dll" ) ) . Should ( ) . BeFalse ( ) ;
3035
+ StrongNameHelper . IsSigned ( GetResourcePath ( "DelaySigned.dll" ) ) . Should ( ) . BeFalse ( ) ;
3036
+ StrongNameHelper . IsSigned ( GetResourcePath ( "ProjectOne.dll" ) ) . Should ( ) . BeFalse ( ) ;
3036
3037
}
3037
3038
3038
3039
/// <summary>
@@ -3099,9 +3100,9 @@ public void NoFlipButWriteShouldVerify()
3099
3100
3100
3101
PEHeaders peHeaders = new PEHeaders ( inputStream ) ;
3101
3102
inputStream . Position = 0 ;
3102
- int checksumStart = peHeaders . PEHeaderStartOffset + StrongName . ChecksumOffsetInPEHeader ;
3103
+ int checksumStart = peHeaders . PEHeaderStartOffset + Microsoft . DotNet . StrongName . Constants . ChecksumOffsetInPEHeader ;
3103
3104
WriteBytesToLocation ( inputStream , outputStream , checksumStart , peHeaders . PEHeader . CheckSum ) ;
3104
- StrongName . IsSigned ( outputStream ) . Should ( ) . BeTrue ( ) ;
3105
+ StrongNameHelper . IsSigned ( outputStream ) . Should ( ) . BeTrue ( ) ;
3105
3106
}
3106
3107
3107
3108
[ Fact ]
@@ -3113,9 +3114,9 @@ public void IncorrectChecksumsDoNotValidate()
3113
3114
3114
3115
PEHeaders peHeaders = new PEHeaders ( inputStream ) ;
3115
3116
inputStream . Position = 0 ;
3116
- int checksumStart = peHeaders . PEHeaderStartOffset + StrongName . ChecksumOffsetInPEHeader ;
3117
+ int checksumStart = peHeaders . PEHeaderStartOffset + Microsoft . DotNet . StrongName . Constants . ChecksumOffsetInPEHeader ;
3117
3118
WriteBytesToLocation ( inputStream , outputStream , checksumStart , peHeaders . PEHeader . CheckSum ^ 0x1 ) ;
3118
- StrongName . IsSigned ( outputStream ) . Should ( ) . BeFalse ( ) ;
3119
+ StrongNameHelper . IsSigned ( outputStream ) . Should ( ) . BeFalse ( ) ;
3119
3120
}
3120
3121
3121
3122
// This binary has had a resource added after it was strong name. This invalidated the checksum too,
@@ -3129,25 +3130,25 @@ public void InvalidatedSNSignatureDoesNotValidate()
3129
3130
PEHeaders peHeaders = new PEHeaders ( inputStream ) ;
3130
3131
inputStream . Position = 0 ;
3131
3132
3132
- int checksumStart = peHeaders . PEHeaderStartOffset + StrongName . ChecksumOffsetInPEHeader ;
3133
+ int checksumStart = peHeaders . PEHeaderStartOffset + Microsoft . DotNet . StrongName . Constants . ChecksumOffsetInPEHeader ;
3133
3134
// Write the checksum that would be expected after editing the binary.
3134
3135
WriteBytesToLocation ( inputStream , outputStream , checksumStart , 110286 ) ;
3135
3136
3136
- StrongName . IsSigned ( outputStream ) . Should ( ) . BeFalse ( ) ;
3137
+ StrongNameHelper . IsSigned ( outputStream ) . Should ( ) . BeFalse ( ) ;
3137
3138
}
3138
3139
3139
3140
[ Fact ]
3140
3141
public void ValidStrongNameSignaturesValidate ( )
3141
3142
{
3142
- StrongName . IsSigned ( GetResourcePath ( "SignedLibrary.dll" ) ) . Should ( ) . BeTrue ( ) ;
3143
- StrongName . IsSigned ( GetResourcePath ( "StrongNamedWithEcmaKey.dll" ) ) . Should ( ) . BeTrue ( ) ;
3143
+ StrongNameHelper . IsSigned ( GetResourcePath ( "SignedLibrary.dll" ) ) . Should ( ) . BeTrue ( ) ;
3144
+ StrongNameHelper . IsSigned ( GetResourcePath ( "StrongNamedWithEcmaKey.dll" ) ) . Should ( ) . BeTrue ( ) ;
3144
3145
}
3145
3146
3146
3147
[ WindowsOnlyFact ]
3147
3148
public void ValidStrongNameSignaturesValidateWithFallback ( )
3148
3149
{
3149
- StrongName . IsSigned_Legacy ( GetResourcePath ( "SignedLibrary.dll" ) , s_snPath ) . Should ( ) . BeTrue ( ) ;
3150
- StrongName . IsSigned_Legacy ( GetResourcePath ( "StrongNamedWithEcmaKey.dll" ) , s_snPath ) . Should ( ) . BeTrue ( ) ;
3150
+ StrongNameHelper . IsSigned_Legacy ( GetResourcePath ( "SignedLibrary.dll" ) , s_snPath ) . Should ( ) . BeTrue ( ) ;
3151
+ StrongNameHelper . IsSigned_Legacy ( GetResourcePath ( "StrongNamedWithEcmaKey.dll" ) , s_snPath ) . Should ( ) . BeTrue ( ) ;
3151
3152
}
3152
3153
3153
3154
[ Theory ]
@@ -3157,12 +3158,12 @@ public void SigningSignsAsExpected(string file, string key, bool initiallySigned
3157
3158
{
3158
3159
// Make sure this is unique
3159
3160
string resourcePath = GetResourcePath ( file , Guid . NewGuid ( ) . ToString ( ) ) ;
3160
- StrongName . IsSigned ( resourcePath ) . Should ( ) . Be ( initiallySigned ) ;
3161
- StrongName . Sign ( resourcePath , GetResourcePath ( key ) ) ;
3162
- StrongName . IsSigned ( resourcePath ) . Should ( ) . BeTrue ( ) ;
3161
+ StrongNameHelper . IsSigned ( resourcePath ) . Should ( ) . Be ( initiallySigned ) ;
3162
+ StrongNameHelper . Sign ( resourcePath , GetResourcePath ( key ) ) ;
3163
+ StrongNameHelper . IsSigned ( resourcePath ) . Should ( ) . BeTrue ( ) ;
3163
3164
3164
3165
// Legacy sn verification works on on Windows only
3165
- StrongName . IsSigned_Legacy ( resourcePath , s_snPath ) . Should ( ) . Be (
3166
+ StrongNameHelper . IsSigned_Legacy ( resourcePath , s_snPath ) . Should ( ) . Be (
3166
3167
RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) ;
3167
3168
}
3168
3169
@@ -3174,11 +3175,11 @@ public void SigningSignsAsExpectedWithLegacyAndVerifiesWithNonLegacy(string file
3174
3175
{
3175
3176
// Make sure this is unique
3176
3177
string resourcePath = GetResourcePath ( file , Guid . NewGuid ( ) . ToString ( ) ) ;
3177
- StrongName . IsSigned_Legacy ( resourcePath , s_snPath ) . Should ( ) . Be ( initiallySigned ) ;
3178
+ StrongNameHelper . IsSigned_Legacy ( resourcePath , s_snPath ) . Should ( ) . Be ( initiallySigned ) ;
3178
3179
// Unset the strong name bit first
3179
- StrongName . ClearStrongNameSignedBit ( resourcePath ) ;
3180
- StrongName . Sign_Legacy ( resourcePath , GetResourcePath ( key ) , s_snPath ) . Should ( ) . BeTrue ( ) ;
3181
- StrongName . IsSigned ( resourcePath ) . Should ( ) . BeTrue ( ) ;
3180
+ StrongNameHelper . ClearStrongNameSignedBit ( resourcePath ) ;
3181
+ StrongNameHelper . Sign_Legacy ( resourcePath , GetResourcePath ( key ) , s_snPath ) . Should ( ) . BeTrue ( ) ;
3182
+ StrongNameHelper . IsSigned ( resourcePath ) . Should ( ) . BeTrue ( ) ;
3182
3183
}
3183
3184
3184
3185
[ Fact ]
@@ -3187,7 +3188,7 @@ public void CannotSignWithTheEcmaKey()
3187
3188
// Using stream variant so that legacy fallback doesn't swallow the exception.
3188
3189
using ( var inputStream = File . OpenRead ( GetResourcePath ( "StrongNamedWithEcmaKey.dll" ) ) )
3189
3190
{
3190
- Action shouldFail = ( ) => StrongName . Sign ( inputStream , GetResourcePath ( "OpenSignedCorrespondingKey.snk" ) ) ;
3191
+ Action shouldFail = ( ) => StrongNameHelper . Sign ( inputStream , GetResourcePath ( "OpenSignedCorrespondingKey.snk" ) ) ;
3191
3192
shouldFail . Should ( ) . Throw < NotImplementedException > ( ) ;
3192
3193
}
3193
3194
}
@@ -3198,7 +3199,7 @@ public void DelaySignedBinaryFailsToSignWithDifferentKey()
3198
3199
// Using stream variant so that legacy fallback doesn't swallow the exception.
3199
3200
using ( var inputStream = File . OpenRead ( GetResourcePath ( "DelaySigned.dll" ) ) )
3200
3201
{
3201
- Action shouldFail = ( ) => StrongName . Sign ( inputStream , GetResourcePath ( "OpenSignedCorrespondingKey.snk" ) ) ;
3202
+ Action shouldFail = ( ) => StrongNameHelper . Sign ( inputStream , GetResourcePath ( "OpenSignedCorrespondingKey.snk" ) ) ;
3202
3203
shouldFail . Should ( ) . Throw < InvalidOperationException > ( ) ;
3203
3204
}
3204
3205
}
0 commit comments