public void GetRequiredMethodPermissionsCacheForMethodWithoutAttributes() { IMethodInformation methodInformation = MethodInfoAdapter.Create(typeof(SecurableObject).GetMethod("Save")); var requiredAccessTypes = _permissionReflector.GetRequiredMethodPermissions(typeof(SecurableObject), methodInformation); Assert.That(_permissionReflector.GetRequiredMethodPermissions(typeof(SecurableObject), methodInformation), Is.SameAs(requiredAccessTypes)); }
public void SetUp() { _testHelper = new SecurityClientTestHelper(); _securityClient = _testHelper.CreateSecurityClient(); _methodInformation = MockRepository.GenerateMock <IMethodInformation>(); _methodInformation.Expect(n => n.Name).Return("StaticMethod"); }
private static void InternalConvertFromPInvokeFunction( CodeTextWriter tw, IMethodInformation method, PInvokeInfo pinvokeInfo) { tw.WriteLine("///////////////////////////////////////"); tw.WriteLine("// [6] P/Invoke: {0}", method.FriendlyName); tw.SplitLine(); tw.WriteLine(method.CLanguageFunctionPrototype); tw.WriteLine("{"); using (var _ = tw.Shift()) { var arguments = string.Join( ", ", method.Parameters. Select(parameter => parameter.GetMarshaledInExpression())); if (method.ReturnType.IsVoidType) { tw.WriteLine("{0}({1});", pinvokeInfo.EntryPoint, arguments); } else { tw.WriteLine("return {0}({1});", pinvokeInfo.EntryPoint, arguments); } } tw.WriteLine("}"); tw.SplitLine(); }
public ILocalVariableInformation GetOrAdd(ITypeInformation targetType, IMethodInformation method, object hintInformation) { var index = typedStackInformation. FindIndex(si => si.TargetType == targetType); if (index >= 0) { selectedStackInformation = index; return(typedStackInformation[index]); } var symbolName = string.Format( "stack{0}_{1}__", stackPointer, typedStackInformation.Count); selectedStackInformation = typedStackInformation.Count; var stackInformation = new LocalVariableInformation( method, stackPointer, symbolName, targetType, hintInformation); typedStackInformation.Add(stackInformation); return(stackInformation); }
private static void InternalConvertFromAbstractFunction( CodeTextWriter tw, IMethodInformation method) { tw.WriteLine("///////////////////////////////////////"); tw.WriteLine("// [5] Abstract: {0}", method.FriendlyName); tw.SplitLine(); tw.WriteLine(method.CLanguageFunctionPrototype); tw.WriteLine("{"); using (var _ = tw.Shift()) { tw.WriteLine( "// WARNING: Pure virtual function called."); tw.WriteLine( "// TODO: throw : assert(0);"); if (method.ReturnType.IsVoidType == false) { tw.WriteLine( "return ({0}){1};", method.ReturnType.CLanguageTypeName, method.ReturnType.IsNumericPrimitive ? "0" : "NULL"); } } tw.WriteLine("}"); tw.SplitLine(); }
public void SetUp() { _testHelper = NullSecurityClientTestHelper.CreateForStatefulSecurity(); _securityClient = _testHelper.CreateSecurityClient(); _methodInfo = typeof(SecurableObject).GetMethod("Show"); _methodInformation = MockRepository.GenerateStub <IMethodInformation>(); }
private static void InternalConvertFromInternalCallFunction( CodeTextWriter tw, IMethodInformation method) { Debug.Assert(method.IsExtern); tw.WriteLine("///////////////////////////////////////"); tw.WriteLine( "// [6] {0}: {1}", (method.PInvokeInformation != null) ? "P/Invoke" : "IL2C/Invoke", method.FriendlyName); tw.SplitLine(); // P/Invoke linkage doesn't verify the C header declarations. // It will lookp up by the library symbol name. if (method.PInvokeInformation != null) { tw.WriteLine( "extern {0};", method.CLanguagePInvokePrototype); tw.SplitLine(); } if (method.IsPrivate) { tw.WriteLine("static inline {0}", method.CLanguageFunctionPrototype); } else { tw.WriteLine(method.CLanguageFunctionPrototype); } tw.WriteLine("{"); using (var _ = tw.Shift()) { var arguments = string.Join( ", ", method.Parameters.Select(GetMarshaledInExpression)); if (method.ReturnType.IsVoidType) { tw.WriteLine( "{0}({1});", method.CLanguageInteropName, arguments); } else { tw.WriteLine( "return {0}({1});", method.CLanguageInteropName, arguments); } } tw.WriteLine("}"); tw.SplitLine(); }
public void SetUp() { _implementationMethodInformationStub = MockRepository.GenerateStub <IMethodInformation>(); _declarationMethodInformationStub = MockRepository.GenerateStub <IMethodInformation>(); _interfaceImplementationMethodInformation = new InterfaceImplementationMethodInformation( _implementationMethodInformationStub, _declarationMethodInformationStub); _mixinIntroducedMethodInformation = new MixinIntroducedMethodInformation(_interfaceImplementationMethodInformation); }
public void SetUp() { _testHelper = new SecurityClientTestHelper(); _securityClient = _testHelper.CreateSecurityClient(); _methodInformation = MockRepository.GenerateMock <IMethodInformation> (); _methodInformation.Expect(n => n.Name).Return("InstanceMethod"); _methodInfo = typeof(SecurableObject).GetMethod("IsValid", new[] { typeof(SecurableObject) }); }
public void GetRequiredMethodPermissionsOverriddenMethodWithPermissionFromBaseMethod() { IMethodInformation methodInformation = MethodInfoAdapter.Create(typeof(DerivedSecurableObject).GetMethod("Record")); var requiredAccessTypes = _permissionReflector.GetRequiredMethodPermissions(typeof(DerivedSecurableObject), methodInformation); Assert.That(requiredAccessTypes.Count, Is.EqualTo(1)); Assert.That(requiredAccessTypes, Has.Member(GeneralAccessTypes.Edit)); }
public CacheKey(Type type, IMethodInformation methodInformation) { ArgumentUtility.DebugCheckNotNull("type", type); ArgumentUtility.DebugCheckNotNull("methodInformation", methodInformation); Type = type; MethodInformation = methodInformation; }
public void GetRequiredMethodPermissionsMethodWithoutAttributes() { IMethodInformation methodInformation = MethodInfoAdapter.Create(typeof(SecurableObject).GetMethod("Save")); var requiredAccessTypes = _permissionReflector.GetRequiredMethodPermissions(typeof(SecurableObject), methodInformation); Assert.That(requiredAccessTypes, Is.Not.Null); Assert.That(requiredAccessTypes, Is.Empty); }
public void ExpectPermissionReflectorGetRequiredMethodPermissions(IMethodInformation methodInformation, params Enum[] returnedAccessTypes) { Expect.Call( _mockPermissionReflector.GetRequiredMethodPermissions( Arg.Is(typeof(SecurableObject)), Arg <IMethodInformation> .Matches(mi => mi.Equals(methodInformation)))) .Return(returnedAccessTypes); }
public override bool HasStaticMethodAccess(Type securableClass, IMethodInformation methodInformation, ISecurityPrincipal principal) { ArgumentUtility.DebugCheckNotNull("securableClass", securableClass); ArgumentUtility.DebugCheckNotNull("methodInformation", methodInformation); ArgumentUtility.DebugCheckNotNull("principal", principal); return(true); }
public InterfaceImplementationMethodInformation(IMethodInformation implementationMethodInfo, IMethodInformation declarationMethodInfo) { ArgumentUtility.CheckNotNull("implementationMethodInfo", implementationMethodInfo); ArgumentUtility.CheckNotNull("declarationMethodInfo", declarationMethodInfo); _implementationMethodInfo = implementationMethodInfo; _declarationMethodInfo = declarationMethodInfo; }
public void SetUp() { _testHelper = new SecurityClientTestHelper(); _securityClient = _testHelper.CreateSecurityClient(); _methodInformation = MockRepository.GenerateMock <IMethodInformation>(); _propertyInfo = typeof(SecurableObject).GetProperty("IsVisible"); _methodInfo = _propertyInfo.GetGetMethod(); }
public void GetAccessors() { var objToReturn = new IMethodInformation[0]; _implementationPropertyInformationStub.Stub(stub => stub.GetAccessors(false)).Return(objToReturn); Assert.That(_interfaceImplementationPropertyInformation.GetAccessors(false), Is.SameAs(objToReturn)); }
public void SetUp() { _testHelper = new SecurityClientTestHelper(); _securityClient = _testHelper.CreateSecurityClient(); _propertyInformation = MockRepository.GenerateMock <IPropertyInformation>(); _methodInformation = MockRepository.GenerateMock <IMethodInformation> (); _propertyInformation.Expect(mock => mock.GetSetMethod(true)).Return(_methodInformation); }
public override bool HasPropertyReadAccess(ISecurableObject securableObject, IMethodInformation methodInformation, ISecurityPrincipal principal) { ArgumentUtility.DebugCheckNotNull("securableObject", securableObject); ArgumentUtility.DebugCheckNotNull("methodInformation", methodInformation); ArgumentUtility.DebugCheckNotNull("principal", principal); return(true); }
public void GetRequiredMethodPermissionsStaticMethod() { IMethodInformation methodInformation = MethodInfoAdapter.Create(typeof(SecurableObject).GetMethod("CreateForSpecialCase")); var requiredAccessTypes = _permissionReflector.GetRequiredMethodPermissions(typeof(SecurableObject), methodInformation); Assert.That(requiredAccessTypes.Count, Is.EqualTo(1)); Assert.That(requiredAccessTypes[0], Is.EqualTo(GeneralAccessTypes.Create)); }
public void SetUp() { _testHelper = NullSecurityClientTestHelper.CreateForStatefulSecurity(); _securityClient = _testHelper.CreateSecurityClient(); _propertyInfo = typeof(SecurableObject).GetProperty("IsVisible"); _propertyInformation = MockRepository.GenerateStub <IPropertyInformation>(); _methodInformation = MockRepository.GenerateMock <IMethodInformation> (); _propertyInformation.Expect(mock => mock.GetSetMethod(true)).Return(_methodInformation); }
public override ExpressionEmitter Prepare( IMethodInformation method, DecodeContext decodeContext) { // ECMA-335 III.4.18: ldvirtfn - load a virtual method pointer if (method.IsStatic) { throw new InvalidProgramSequenceException( "Invalid method token (static): Location={0}, Method={1}", decodeContext.CurrentCode.RawLocation, method.FriendlyName); } var si = decodeContext.PopStack(); if (!method.DeclaringType.IsAssignableFrom(si.TargetType)) { throw new InvalidProgramSequenceException( "Invalid method token (not a member): Location={0}, Method={1}", decodeContext.CurrentCode.RawLocation, method.FriendlyName); } var symbol = decodeContext.PushStack( decodeContext.PrepareContext.MetadataContext.IntPtrType); // Register callee method declaring type (at the file scope). decodeContext.PrepareContext.RegisterType(method.DeclaringType, decodeContext.Method); if (method.IsVirtual && !method.IsSealed) { // Last newslot method is short named function: "ToString", // But have to apply full named function when NOT equals last newslot method: "System_Object_ToString" var methodsBySlots = method.DeclaringType.AllCombinedMethods. Where(entry => entry.Item1.CLanguageFunctionName == method.CLanguageFunctionName). ToArray(); var slotIndex = methodsBySlots. Select((entry, index) => entry.Item2.Any(m => m.Equals(method)) ? index : -1). First(index => index >= 0); var newslotMethod = methodsBySlots[slotIndex].Item1; return((extractContext, _) => new[] { string.Format( "{0} = (intptr_t){1}->vptr0__->{2}", extractContext.GetSymbolName(symbol), extractContext.GetSymbolName(si), (slotIndex == (methodsBySlots.Length - 1)) ? newslotMethod.CLanguageFunctionName : newslotMethod.CLanguageFunctionFullName) }); } else { return((extractContext, _) => new[] { string.Format( "{0} = (intptr_t){1}", extractContext.GetSymbolName(symbol), method.CLanguageFunctionFullName) }); } }
public LocalVariableInformation( IMethodInformation declaredMethod, int index, string symbolName, ITypeInformation targetType, object hintInformation = null) : base(declaredMethod, index, symbolName, targetType, hintInformation) { }
public void FilterMultipleAccessTypes() { IMethodInformation methodInformation = MethodInfoAdapter.Create(typeof(SecurableObject).GetMethod("Close")); var requiredAccessTypes = _permissionReflector.GetRequiredMethodPermissions(typeof(SecurableObject), methodInformation); Assert.That(requiredAccessTypes.Count, Is.EqualTo(2)); Assert.That(requiredAccessTypes, Has.Member(GeneralAccessTypes.Edit)); Assert.That(requiredAccessTypes, Has.Member(GeneralAccessTypes.Find)); }
public override Func <IExtractContext, string[]> Apply( IMethodInformation operand, DecodeContext decodeContext) { var symbol = decodeContext.PushStack(decodeContext.PrepareContext.MetadataContext.IntPtrType); return(extractContext => new[] { string.Format( "{0} = (intptr_t){1}", extractContext.GetSymbolName(symbol), operand.CLanguageFunctionName) }); }
public ParameterInformation( IMethodInformation declaredMethod, int index, string symbolName, ITypeInformation targetType, CustomAttribute[] customAttributes, object hintInformation = null) : base(declaredMethod, index, symbolName, targetType, hintInformation) { this.customAttributes = customAttributes; }
public void FindInterfaceDeclaration() { IMethodInformation methodInformation = MethodInfoAdapter.Create(typeof(object).GetMethod("ToString")); _declarationMethodInformationStub .Stub(stub => stub.FindInterfaceDeclarations()) .Return(EnumerableUtility.Singleton(methodInformation).AsOneTime()); Assert.That(_mixinIntroducedMethodInformation.FindInterfaceDeclarations(), Is.EqualTo(new[] { _declarationMethodInformationStub })); Assert.That(_mixinIntroducedMethodInformation.FindInterfaceDeclarations(), Is.EqualTo(new[] { _declarationMethodInformationStub })); }
public override void SetUp() { base.SetUp(); _testHelper = new TestHelper(); _extension = new SecurityClientTransactionExtension(); _propertyInfo = typeof(SecurableObject).GetProperty("Parent"); _getMethodInformation = MethodInfoAdapter.Create(_propertyInfo.GetGetMethod()); _testHelper.SetupSecurityIoCConfiguration(); }
public virtual bool HasStatelessMethodAccess(Type securableClass, IMethodInformation methodInformation, ISecurityPrincipal principal) { ArgumentUtility.CheckNotNull("securableClass", securableClass); ArgumentUtility.CheckNotNull("methodInformation", methodInformation); ArgumentUtility.DebugCheckNotNull("principal", principal); var requiredAccessTypeEnums = _permissionProvider.GetRequiredMethodPermissions(securableClass, methodInformation); Assertion.DebugIsNotNull(requiredAccessTypeEnums, "IPermissionProvider.GetRequiredMethodPermissions evaluated and returned null."); return(HasStatelessAccess(securableClass, methodInformation, requiredAccessTypeEnums, principal)); }
public override Func <IExtractContext, string[]> Apply( IMethodInformation method, DecodeContext decodeContext) { // ECMA-335 III.4.18: ldvirtfn - load a virtual method pointer if (method.IsStatic) { throw new InvalidProgramSequenceException( "Invalid method token (static): Location={0}, Method={1}", decodeContext.CurrentCode.RawLocation, method.FriendlyName); } var si = decodeContext.PopStack(); if (!method.DeclaringType.IsAssignableFrom(si.TargetType)) { throw new InvalidProgramSequenceException( "Invalid method token (not a member): Location={0}, Method={1}", decodeContext.CurrentCode.RawLocation, method.FriendlyName); } var symbol = decodeContext.PushStack( decodeContext.PrepareContext.MetadataContext.IntPtrType); // Register callee method declaring type (at the file scope). decodeContext.PrepareContext.RegisterType(method.DeclaringType, decodeContext.Method); if (method.IsVirtual && !method.IsSealed) { // TODO: interface member vptr var virtualMethods = method.DeclaringType.CalculatedVirtualMethods; var(m, overloadIndex) = virtualMethods.First(entry => entry.method.Equals(method)); var vptrName = m.GetCLanguageDeclarationName(overloadIndex); return(extractContext => new[] { string.Format( "{0} = (intptr_t){1}->vptr0__->{2}", extractContext.GetSymbolName(symbol), extractContext.GetSymbolName(si), vptrName) }); } else { return(extractContext => new[] { string.Format( "{0} = (intptr_t){1}", extractContext.GetSymbolName(symbol), method.CLanguageFunctionName) }); } }