来自nunit测试的C#远程处理(遗留)导致安全异常
本文关键字:遗留 nunit 异常 安全 处理 程处理 来自 测试 | 更新日期: 2024-09-22 08:54:22
我正在为使用远程处理的遗留api编写系统范围的测试。如果我从示例中调用远程处理:控制台应用程序,则远程处理是有效的。
然而,以下代码来自NUnit项目:
((FooBar)System.Activator.GetObject(typeof (FooBar), "http://localhost/FooBar.rem")).SomeMethod("abc");
失败,异常:
System.Security.SecurityException : Type System.Runtime.Remoting.ObjRef and the types derived from it (such as System.Runtime.Remoting.ObjRef) are not permitted to be deserialized at this security level.
此异常的许多指针显示服务器端安全设置的更改,但由于服务器与其他使用者一起工作,所以安全问题似乎在客户端。
我已经尝试添加:
var clientProvider = new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
const int httpConnectionLimit = 100;
const int httpTimeout = 30*1000;
props["clientConnectionLimit"] = httpConnectionLimit;
props["timeout"] = httpTimeout;
var channel = new HttpChannel(props, clientProvider, null);
ChannelServices.RegisterChannel(channel, false);
没有效果。
Runner是Resharper 9。也尝试了MS runner,但似乎失败了,出现了同样的错误。
遗憾的是,在这一点上,重构旧系统以使用像休息到通信这样的现代技术并不是一种选择。
使用Nunit 2.6.3和2.6.4进行测试。2.6.2有一个问题看起来像这样,但看起来不一样。
https://github.com/nunit/nunit/issues/522