public void Parse_CallWithUnsafeProperty_ReturnsProblem()
        {
            Method sample = TestHelper.GetSample <PropertySample> ("CallWithUnsafeProperty");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
        public void Parse_CallWithSafePropertyVerboseAnnotation_NoProblem()
        {
            Method sample = TestHelper.GetSample <PropertySample> ("CallWithSafePropertyVerboseAnnotation");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #3
0
        public void Parse_BinaryConcatDifferentFragmentVariables_ReturnsProblem()
        {
            Method sample = TestHelper.GetSample <FragmentParameterInferenceSample> ("BinaryConcatDifferentFragmentVariables");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
        public void ShouldReturnNoProblemsWithNonWcfConfigurationFile()
        {
            MockServiceModelConfigurationRule rule = new MockServiceModelConfigurationRule();
            Configuration     configuration        = ConfigurationLoader.LoadConfiguration("EmptyConfigFile.config");
            ProblemCollection problems             = rule.Check(configuration);

            Assert.IsNotNull(problems);
            Assert.AreEqual(0, problems.Count);
        }
Пример #5
0
        public void Parse_UnsafeStringFormatPattern_ReturnsProblem()
        {
            Method sample = TestHelper.GetSample <FragmentParameterInferenceSample>("UnsafeStringFormatPattern");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
Пример #6
0
        public void Parse_BinaryConcatFragmentAndLiteral_NoProblem()
        {
            Method sample = TestHelper.GetSample <FragmentParameterInferenceSample> ("BinaryConcatFragmentAndLiteral");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #7
0
        public void Parse_QuarternaryStringFormatSafeCall_NoProblem()
        {
            Method sample = TestHelper.GetSample <FragmentParameterInferenceSample> ("QuarternaryStringFormatSafeCall");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #8
0
        public void Parse_SafeFormatCallWithArray_NoProblem()
        {
            Method sample = TestHelper.GetSample <FragmentParameterInferenceSample>("SafeFormatCallWithArray");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #9
0
        public void Parse_ValidSafenessPropagationVariable_NoProblem()
        {
            Method sample = TestHelper.GetSample <AssignmentPropagationSample>("ValidSafenessPropagationVariable");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #10
0
        public void Parse_UnsafeCallNestedTry_ReturnsProblem()
        {
            Method sample = TestHelper.GetSample <TryCatchFinallySample> ("UnsafeCallNestedTry");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
Пример #11
0
        public void Parse_SafeCallInsideFinally_NoProblem()
        {
            Method sample = TestHelper.GetSample <TryCatchFinallySample> ("SafeCallInsideFinally");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
        public void Parse_SetSafePropertyVerboseAnnotationWithUnsafeValue_ReturnsProblem()
        {
            Method sample = TestHelper.GetSample <PropertySample> ("SetSafePropertyVerboseAnnotationWithUnsafeValue");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
        public void Parse_SetSafePropertyWithSafeValue_NoProblem()
        {
            Method sample = TestHelper.GetSample <PropertySample> ("SetSafePropertyWithSafeValue");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #14
0
        public void Parse_SafeMethodCallInsideAnonymousMethod_NoProblem()
        {
            Method sample = TestHelper.GetSample <AnonymousMethodSample> ("SafeMethodCallInsideAnonymousMethod");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #15
0
        public void Parse_UnsafeReturnInsideAnonymousMethod_ReturnsProblem()
        {
            Method sample = TestHelper.GetSample <AnonymousMethodSample>("UnsafeReturnInsideAnonymousMethod");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
Пример #16
0
        /// <summary>
        /// Read the data files and set up the MATLAB component.
        /// Would like to do this in a static constructor, but we don't have access to a
        /// HttpRequest object at that time, so it's not clear how to map the paths.
        /// </summary>
        private void init()
        {
            HttpRequest request   = this.Context.Request;
            string      dataDir   = request.MapPath("Data");
            string      schemaDir = request.MapPath("Schema");

            _logger.Debug("Loading SpecificPower.xml");
            string specificPowerDataFile   = Path.Combine(dataDir, "SpecificPower.xml");
            string specificPowerSchemaFile = Path.Combine(schemaDir, "SpecificPower.xsd");

            specificPowerData = new SpecificPowerDataManager(specificPowerDataFile, specificPowerSchemaFile);

            inputPowerCalc = new InputPowerCalculator(specificPowerData.Data);

            _logger.Debug("Loading Coolers.xml");
            string coolerDataFile   = Path.Combine(dataDir, "Coolers.xml");
            string coolerSchemaFile = Path.Combine(schemaDir, "Coolers.xsd");

            coolers = new CoolerCollection(coolerDataFile, coolerSchemaFile);
            foreach (Cooler c in coolers)
            {
                c.InputPowerCalculator = inputPowerCalc;
            }
            _logger.DebugFormat("{0} coolers loaded", coolers.Count);

            _logger.Debug("Loading Materials.xml");
            string materialsDataFile   = Path.Combine(dataDir, "Materials.xml");
            string materialsSchemaFile = Path.Combine(schemaDir, "Materials.xsd");

            materials = new MaterialsCollection(materialsDataFile, materialsSchemaFile);
            _logger.DebugFormat("{0} materials loaded", materials.Count);

            _logger.Debug("Loading Problems.xml");
            string problemsDataFile   = Path.Combine(dataDir, "Problems.xml");
            string problemsSchemaFile = Path.Combine(schemaDir, "Problems.xsd");

            problems = new ProblemCollection(problemsDataFile, problemsSchemaFile);
            _logger.DebugFormat("{0} problems loaded", problems.Count);

            _logger.Debug("Loading MathGates.xml");
            string mathGateDataFile   = Path.Combine(dataDir, "MathGates.xml");
            string mathGateSchemaFile = Path.Combine(schemaDir, "MathGates.xsd");

            mathGates = new MathGateCollection(mathGateDataFile, mathGateSchemaFile);
            _logger.DebugFormat("{0} math gates loaded", mathGates.Count);

            _logger.Debug("Initializing Optimizer");
            optimizer = new Optimizer(coolers, materials);
            _logger.Debug("Initializaing SolutionChecker");
            solutionChecker = new SolutionChecker(problems);

            _logger.Debug("Initializaing SteadyStateSimulator");
            sim = new SteadyStateSimulator();
            _logger.Debug("Initializing API");
            api = new API();
        }
        public void Parse_UnsafeCallWithSingleVariableSetSafeByIndexer_ReturnsProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <IndexerSample>("UnsafeCallWithSingleVariableSetSafeByIndexer", stringTypeNode.GetArrayType(1));

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
        public void Parse_SafeCallUsingIndexer_NoProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <IndexerSample>("SafeCallUsingIndexer", stringTypeNode.GetArrayType(1));

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #19
0
        public void AddProblem_TwoViolations_ReturnsInjectionCopProblems()
        {
            Method sample = TestHelper.GetSample <AddProblemSample>("TwoViolations");

            _typeParser.Parse(sample);
            ProblemCollection result         = _typeParser.Problems;
            bool returnsInjectionCopProblems = result.All(problem => problem.Id == c_InjectionCopRuleId);

            Assert.That(returnsInjectionCopProblems, Is.True);
        }
Пример #20
0
        public void ShouldGetOneProblemWithRuleViolation()
        {
            UnTrustedClientCertificateRevocation rule = new UnTrustedClientCertificateRevocation();
            Configuration     configuration           = ConfigurationLoader.LoadConfiguration("UnTrustedClientCertificateR.config");
            ProblemCollection problems = rule.Check(configuration);

            Assert.IsNotNull(problems);
            Assert.AreEqual(1, problems.Count);
            Assert.AreEqual(configuration.FilePath, problems[0].SourceFile);
        }
        public void Parse_FragmentRefParameterUnsafeReturn_ReturnsProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <CallByReferenceSample> ("FragmentRefParameterUnsafeReturn", stringTypeNode.GetReferenceType());

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
Пример #22
0
        public void Parse_SafeFragmentOutParameterInsideWhile_NoProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <OutSample> ("SafeFragmentOutParameterInsideWhile", stringTypeNode.GetReferenceType());

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
        public void Parse_ConstructorChainingWithBaseClassCorrectFragment_NoProblem()
        {
            TypeNode sampleTypeNode = IntrospectionUtility.TypeNodeFactory <InheritanceSampleConstructor>();
            Method   sample         = IntrospectionUtility.MethodFactory(sampleTypeNode, ".ctor");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
        public void Parse_GetValidIdentifier_NoProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <LostAndFoundSample> ("GetValidIdentifier", stringTypeNode);

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #25
0
        public void ShouldGetOneProblemWithRuleViolation()
        {
            ExceptionDetailInFaults rule          = new ExceptionDetailInFaults();
            Configuration           configuration = ConfigurationLoader.LoadConfiguration("ExceptionDetailInFaults.config");
            ProblemCollection       problems      = rule.Check(configuration);

            Assert.IsNotNull(problems);
            Assert.AreEqual(2, problems.Count);
            Assert.AreEqual(configuration.FilePath, problems[0].SourceFile);
        }
        public void Parse_UnsafeMethodParameter_ReturnsProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <CallByShareSample> ("UnsafeMethodParameter", stringTypeNode);

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
Пример #27
0
        public void Parse_UnsafeCallWithInheritedField_ReturnsProblem()
        {
            TypeNode sampleTypeNode = IntrospectionUtility.TypeNodeFactory <InheritanceSampleField>();
            Method   sample         = IntrospectionUtility.MethodFactory(sampleTypeNode, "UnsafeCallWithInheritedField");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
Пример #28
0
        public void Parse_UnsafeAssignmentOnFieldResetByHidingParent_ReturnsProblem()
        {
            TypeNode sampleTypeNode = IntrospectionUtility.TypeNodeFactory <InheritanceSampleField>();
            Method   sample         = IntrospectionUtility.MethodFactory(sampleTypeNode, "UnsafeAssignmentOnFieldResetByHidingParent");

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #29
0
        public void Parse_ConstructorWithFragmentParameterOnlyValidCalls_NoProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <ConstructorSample> (".ctor", stringTypeNode, stringTypeNode);

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.False);
        }
Пример #30
0
        public void Parse_ConstructorChainingViolation_ReturnsProblem()
        {
            TypeNode stringTypeNode = IntrospectionUtility.TypeNodeFactory <string>();
            Method   sample         = TestHelper.GetSample <ConstructorSample> (".ctor", stringTypeNode, stringTypeNode, stringTypeNode, stringTypeNode, stringTypeNode);

            _typeParser.Parse(sample);
            ProblemCollection result = _typeParser.Problems;

            Assert.That(TestHelper.ContainsProblemID(c_InjectionCopRuleId, result), Is.True);
        }
 private ProblemCollection ParseGraph()
 {
     _methodGraphAnalyzer.Parse (_methodGraphBuilder, _parameterSymbolTableBuilder);
       ProblemCollection problemCollection = new ProblemCollection();
       _problemPipeStub.Problems.ForEach (problem => problemCollection.Add (new Problem (new Resolution("resolution"), c_InjectionCopRuleId)));
       return problemCollection;
 }