@@ -35,8 +35,12 @@ private static Config Config
35
35
}
36
36
" ) ;
37
37
38
+ private readonly ITestOutputHelper _output ;
39
+
38
40
public HyperionSerializerSetupSpec ( ITestOutputHelper output ) : base ( Config , output )
39
- { }
41
+ {
42
+ _output = output ;
43
+ }
40
44
41
45
[ Fact ]
42
46
public void Setup_should_be_converted_to_settings_correctly ( )
@@ -128,14 +132,22 @@ public void Setup_surrogate_should_work()
128
132
129
133
[ Theory ]
130
134
[ MemberData ( nameof ( DangerousObjectFactory ) ) ]
131
- public void Setup_disallow_unsafe_type_should_work ( object dangerousObject , Type type )
135
+ public void Setup_disallow_unsafe_type_should_work_by_default ( byte [ ] dangerousObject , Type type )
132
136
{
137
+ _output . WriteLine ( $ "Dangerous type: [{ type } ]") ;
133
138
var deserializer = new HyperionSerializer ( ( ExtendedActorSystem ) Sys , HyperionSerializerSettings . Default ) ;
134
- var serializer = new HyperionSerializer ( ( ExtendedActorSystem ) Sys , deserializer . Settings . WithDisallowUnsafeType ( false ) ) ;
135
- var serialized = serializer . ToBinary ( dangerousObject ) ;
136
- deserializer . Invoking ( s => s . FromBinary ( serialized , type ) ) . Should ( ) . Throw < SerializationException > ( ) ;
139
+ deserializer . Invoking ( s => s . FromBinary ( dangerousObject , type ) ) . Should ( ) . Throw < SerializationException > ( ) ;
137
140
}
138
141
142
+ [ Theory ]
143
+ [ MemberData ( nameof ( DangerousObjectFactory ) ) ]
144
+ public void Setup_should_deserialize_unsafe_type_if_allowed ( byte [ ] dangerousObject , Type type )
145
+ {
146
+ _output . WriteLine ( $ "Dangerous type: [{ type } ]") ;
147
+ var deserializer = new HyperionSerializer ( ( ExtendedActorSystem ) Sys , HyperionSerializerSettings . Default . WithDisallowUnsafeType ( false ) ) ;
148
+ deserializer . FromBinary ( dangerousObject , type ) ; // should not throw
149
+ }
150
+
139
151
[ Theory ]
140
152
[ MemberData ( nameof ( TypeFilterObjectFactory ) ) ]
141
153
public void Setup_TypeFilter_should_filter_types_properly ( object sampleObject , bool shouldSucceed )
@@ -170,17 +182,23 @@ public static IEnumerable<object[]> DangerousObjectFactory()
170
182
{
171
183
var isWindow = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
172
184
173
- yield return new object [ ] { new FileInfo ( "C:\\ Windows\\ System32" ) , typeof ( FileInfo ) } ;
174
- yield return new object [ ] { new ClaimsIdentity ( ) , typeof ( ClaimsIdentity ) } ;
185
+ yield return new object [ ] { Serialize ( new FileInfo ( "C:\\ Windows\\ System32" ) ) , typeof ( FileInfo ) } ;
186
+ yield return new object [ ] { Serialize ( new ClaimsIdentity ( ) ) , typeof ( ClaimsIdentity ) } ;
175
187
if ( isWindow )
176
188
{
177
- yield return new object [ ] { WindowsIdentity . GetAnonymous ( ) , typeof ( WindowsIdentity ) } ;
178
- yield return new object [ ] { new WindowsPrincipal ( WindowsIdentity . GetAnonymous ( ) ) , typeof ( WindowsPrincipal ) } ;
189
+ yield return new object [ ] { Serialize ( WindowsIdentity . GetAnonymous ( ) ) , typeof ( WindowsIdentity ) } ;
190
+ yield return new object [ ] { Serialize ( new WindowsPrincipal ( WindowsIdentity . GetAnonymous ( ) ) ) , typeof ( WindowsPrincipal ) } ;
179
191
}
180
192
#if NET471
181
- yield return new object [ ] { new Process ( ) , typeof ( Process ) } ;
193
+ yield return new object [ ] { Serialize ( new Process ( ) ) , typeof ( Process ) } ;
182
194
#endif
183
- yield return new object [ ] { new ClaimsIdentity ( ) , typeof ( ClaimsIdentity ) } ;
195
+ yield return new object [ ] { Serialize ( new ClaimsIdentity ( ) ) , typeof ( ClaimsIdentity ) } ;
196
+ }
197
+
198
+ private static byte [ ] Serialize ( object obj )
199
+ {
200
+ var serializer = new HyperionSerializer ( null , HyperionSerializerSettings . Default . WithDisallowUnsafeType ( false ) ) ;
201
+ return serializer . ToBinary ( obj ) ;
184
202
}
185
203
186
204
public static IEnumerable < object [ ] > TypeFilterObjectFactory ( )
0 commit comments