Skip to content

Commit eaa9c58

Browse files
committed
Add check if target interface is public
1 parent 46bd543 commit eaa9c58

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

LegacyWrapperClient/Client/WrapperProxyFactory.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Linq.Expressions;
6-
using System.Reflection;
72
using System.Runtime.Serialization;
83
using System.Runtime.Serialization.Formatters.Binary;
9-
using System.Text;
10-
using System.Threading.Tasks;
114
using Castle.DynamicProxy;
125
using LegacyWrapper.Common.Token;
13-
using LegacyWrapperClient.Architecture;
146
using LegacyWrapperClient.Configuration;
157
using LegacyWrapperClient.DynamicProxy;
168
using LegacyWrapperClient.ProcessHandling;
179
using LegacyWrapperClient.Token;
1810
using LegacyWrapperClient.Transport;
1911
using Ninject;
20-
using Ninject.Modules;
2112
using PommaLabs.Thrower;
2213

2314
namespace LegacyWrapperClient.Client
@@ -64,7 +55,8 @@ private static TFunctions CreateProxy()
6455
/// <returns>Returns a new instance of TFunctions.</returns>
6556
public static TFunctions GetInstance(IWrapperConfig configuration)
6657
{
67-
Raise.ArgumentException.If(!typeof(TFunctions).IsInterface, nameof(TFunctions), "Generic parameter type <TFunctions> must be an interface.");
58+
Raise.ArgumentException.IfNot(typeof(TFunctions).IsInterface, nameof(TFunctions), "Generic parameter type <TFunctions> must be an interface.");
59+
Raise.ArgumentException.IfNot(typeof(TFunctions).IsPublic, nameof(TFunctions), "The provided interface type <TFunctions> must be public.");
6860

6961
CreateToken();
7062

LegacyWrapperTest.Integration/Client/EdgeCaseTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ public void TestTypeIsNotAnInterface()
2626
}
2727
}
2828

29+
[TestMethod, ExpectedException(typeof(ArgumentException))]
30+
public void TestNonPublicInterface()
31+
{
32+
IWrapperConfig configuration = WrapperConfigBuilder.Create()
33+
.TargetArchitecture(ArchitectureToLoad)
34+
.Build();
35+
36+
using (var client = WrapperProxyFactory<ITestDllWithProtectedInterface>.GetInstance(configuration))
37+
{
38+
client.MethodWithoutAttribute();
39+
}
40+
}
41+
2942
[TestMethod, ExpectedException(typeof(LegacyWrapperException))]
3043
public void TestLoadNonExistingLibrary()
3144
{

LegacyWrapperTest.Integration/Interface/ITestDll.cs

+6
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ public interface ITestDllWithAttribute : IDisposable
6868
{
6969
void MethodWithoutAttribute();
7070
}
71+
72+
[LegacyDllImport("User32.dll")]
73+
interface ITestDllWithProtectedInterface : IDisposable
74+
{
75+
void MethodWithoutAttribute();
76+
}
7177
}

0 commit comments

Comments
 (0)