public void Parse_SafeStaticBindingOnNewMethod_NoProblem() { TypeNode sampleTypeNode = IntrospectionUtility.TypeNodeFactory <InheritanceSampleMethod>(); Microsoft.FxCop.Sdk.Method sample = IntrospectionUtility.MethodFactory(sampleTypeNode, "SafeStaticBindingOnNewMethod"); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False); }
public void Parse_UnsafeCallOnMethodInheritedFromSuperiorClass_ReturnsProblem() { TypeNode sampleTypeNode = IntrospectionUtility.TypeNodeFactory <InheritanceSampleMethod>(); Microsoft.FxCop.Sdk.Method sample = IntrospectionUtility.MethodFactory(sampleTypeNode, "UnsafeCallOnMethodInheritedFromSuperiorClass"); _typeParser.Parse(sample); ProblemCollection result = _typeParser.Problems; Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True); }
public override ProblemCollection Check(Member member) { string str = string.Empty; Resolution resolution = null; int num = 0; string fullName = string.Empty; string str3 = string.Empty; try { if (this.m_listSPDeprecatedAPIStore.Count.Equals(0)) { this.FillSPDeprecatedAPIStore(); } if (member is Microsoft.FxCop.Sdk.Method) { Microsoft.FxCop.Sdk.Method method = member as Microsoft.FxCop.Sdk.Method; MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator(); while (enumerator.MoveNext()) { Instruction current = enumerator.Current; foreach (SPDeprecatedAPIStore store in this.m_listSPDeprecatedAPIStore) { if (current.Value is Local) { fullName = (current.Value as Local).Type.FullName; str3 = store.Namespace + "." + store.APIType; if (fullName.Equals(str3) || fullName.Contains("Microsoft.SharePoint.Portal")) { resolution = base.GetResolution(new string[] { method.ToString(), fullName, store.Message }); base.Problems.Add(new Problem(resolution, Convert.ToString(num))); num++; fullName = string.Empty; str3 = string.Empty; break; } } else if ((current.Value is Microsoft.FxCop.Sdk.Method) && (null != (current.Value as Microsoft.FxCop.Sdk.Method).DeclaringMember)) { str = (current.Value as Microsoft.FxCop.Sdk.Method).DeclaringMember.DeclaringType.FullName; fullName = (current.Value as Microsoft.FxCop.Sdk.Method).DeclaringMember.FullName; if ((str.Equals(store.Namespace) && fullName.Equals(store.APIType)) || fullName.Contains("Microsoft.SharePoint.Portal")) { resolution = base.GetResolution(new string[] { method.ToString(), fullName, store.Message }); base.Problems.Add(new Problem(resolution, Convert.ToString(num))); num++; str = string.Empty; fullName = string.Empty; break; } } } } } } catch (Exception exception) { Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointDeprecatedAPICheck:Check() - " + exception.Message); } return(base.Problems); }
public override ProblemCollection Check(Member member) { string str = string.Empty; Resolution resolution = null; string fullName = string.Empty; string str3 = string.Empty; try { if (this.m_listSPDeprecatedAPIStore.Count.Equals(0)) { this.FillSPDeprecatedAPIStore(); } if (member is Microsoft.FxCop.Sdk.Method) { Microsoft.FxCop.Sdk.Method method = member as Microsoft.FxCop.Sdk.Method; MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator(); while (enumerator.MoveNext()) { Instruction current = enumerator.Current; foreach (SPClaimsTypesToBeChecked checked2 in this.m_listSPDeprecatedAPIStore) { Problem problem; if (current.Value is Local) { Local local = current.Value as Local; fullName = (current.Value as Local).Type.FullName; str3 = checked2.Namespace + "." + checked2.APIType; if (fullName.Equals(str3)) { resolution = new Resolution("This rule is applicable only to SharePoint 2010 customizations. {0}", new string[] { checked2.Message }); problem = new Problem(resolution, current.SourceContext) { Certainty = 90, FixCategory = FixCategories.NonBreaking, Id = this.GetNextId(), MessageLevel = MessageLevel.Warning }; base.Problems.Add(problem); fullName = string.Empty; str3 = string.Empty; break; } } else { if (null == (current.Value as Microsoft.FxCop.Sdk.Method)) { break; } Microsoft.FxCop.Sdk.Method method2 = current.Value as Microsoft.FxCop.Sdk.Method; fullName = this.GetOnlyTheMethodName(method2.FullName); str3 = checked2.Namespace + "." + checked2.APIType; if (fullName.Equals(str3)) { resolution = new Resolution("This rule is applicable only to SharePoint 2010 customizations. {0}", new string[] { checked2.Message }); problem = new Problem(resolution, current.SourceContext) { Certainty = 90, FixCategory = FixCategories.NonBreaking, Id = this.GetNextId(), MessageLevel = MessageLevel.Warning }; base.Problems.Add(problem); str = string.Empty; fullName = string.Empty; break; } MetadataCollection <Parameter> .Enumerator enumerator3 = method2.Parameters.GetEnumerator(); while (enumerator3.MoveNext()) { Parameter parameter = enumerator3.Current; fullName = parameter.Type.FullName; str3 = checked2.Namespace + "." + checked2.APIType; if (fullName.Equals(str3)) { resolution = new Resolution("This rule is applicable only to SharePoint 2010 customizations. {0}", new string[] { checked2.Message }); problem = new Problem(resolution, current.SourceContext) { Certainty = 90, FixCategory = FixCategories.NonBreaking, Id = this.GetNextId(), MessageLevel = MessageLevel.Warning }; base.Problems.Add(problem); str = string.Empty; fullName = string.Empty; } } } } } this.VisitStatements(method.Body.Statements); } } catch (Exception exception) { Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointDeprecatedAPICheck:Check() - " + exception.Message); } return(base.Problems); }