private void Insert(int index, string key, UnitTestItem value) { if (count == keys.Length) EnsureCapacity(count + 1); if (index < count) { Array.Copy(keys, index, keys, index + 1, count - index); Array.Copy(values, index, values, index + 1, count - index); } keys[index] = key; values[index] = value; count++; version++; }
/// <summary> /// Adds a HtmlFormTag to a HtmlUnitTestReport. /// </summary> /// <param name="parentRow"> The TestItemRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="unitTestItem"> The UnitTestItem type.</param> private void AddFormTag(HtmlUnitTestReport.TestItemRow parentRow,HtmlUnitTestReport report,UnitTestItem unitTestItem) { HtmlUnitTestReport.FormRow row = report.Form.NewFormRow(); if ( unitTestItem.Form != null ) { row.Action = unitTestItem.Form.Action; row.Enctype = unitTestItem.Form.Enctype; row.Method = unitTestItem.Form.Method; row.Name = unitTestItem.Form.Name; row.SetParentRow(parentRow); report.Form.AddFormRow(row); } }
/// <summary> /// Removes the element at the specified index of the <b>UnitTestFormCollection</b>. /// </summary> /// <param name="index">The zero-based index of the element to remove.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="index"/> is outside the range of valid indices for the <see cref="UnitTestFormCollection"/>. /// </exception> /// <exception cref="NotSupportedException"> /// <para>The <see cref="UnitTestFormCollection"/> is read-only.</para> /// <para>-or-</para> /// <para>The <b>UnitTestFormCollection</b> has a fixed size.</para> /// </exception> /// <remarks> /// <para>The index sequence is based on the sort sequence. When an element is added, /// it is inserted into <see cref="UnitTestFormCollection"/> in the correct sort order, and /// the indexing adjusts accordingly. When an element removed, the indexing also adjusts /// accordingly. Therefore, the index of a specific key-and-value pair might change as /// elements are added or removed from the <see cref="UnitTestFormCollection"/>.</para> /// <para>In collections of contiguous elements, such as lists, the elements that /// follow the removed element move up to occupy the vacated spot. If the collection is /// indexed, the indices of the elements that are moved are also updated.</para> /// </remarks> public virtual void RemoveAt(int index) { if (index < 0 || index >= count) throw new ArgumentOutOfRangeException("index", index, "The index is outside the range of valid indices."); count--; if (index < count) { Array.Copy(keys, index + 1, keys, index, count - index); Array.Copy(values, index + 1, values, index, count - index); } // We can't set the deleted entries equal to null, because they might be value types. // Instead, we'll create empty single-element arrays of the right type and copy them // over the entries we want to erase. string[] tempKey = new string[1]; UnitTestItem[] tempVal = new UnitTestItem[1]; Array.Copy(tempKey, 0, keys, count, 1); Array.Copy(tempVal, 0, values, count, 1); version++; }
/// <summary> /// Replaces the value at a specific index in the <b>UnitTestFormCollection</b>. /// </summary> /// <param name="index">The zero-based index at which to save <paramref name="value"/>.</param> /// <param name="value">The <see cref="UnitTestItem"/> to save into the <see cref="UnitTestFormCollection"/>.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="index"/> is outside the range of valid indices for the <see cref="UnitTestFormCollection"/>. /// </exception> /// <remarks> /// <para>The index sequence is based on the sort sequence. When an element is added, /// it is inserted into <see cref="UnitTestFormCollection"/> in the correct sort order, and /// the indexing adjusts accordingly. When an element removed, the indexing also adjusts /// accordingly. Therefore, the index of a specific key-and-value pair might change as /// elements are added or removed from the <see cref="UnitTestFormCollection"/>.</para> /// </remarks> public virtual void SetByIndex(int index, UnitTestItem value) { if (index < 0 || index >= count) throw new ArgumentOutOfRangeException("index", index, "The index is outside the range of valid indices."); values[index] = value; version++; }
/// <summary> /// Determines whether the <b>UnitTestFormCollection</b> contains a specific value. /// </summary> /// <param name="value">The value to locate in the <see cref="UnitTestFormCollection"/>.</param> /// <returns> /// <b>true</b> if the <see cref="UnitTestFormCollection"/> contains an element with the specified /// <paramref name="value"/>; otherwise, <b>false</b>. /// </returns> public virtual bool ContainsValue(UnitTestItem value) { return (IndexOfValue(value) >= 0); }
/// <summary> /// Returns the zero-based index of the first occurrence of the specified value in /// the <b>UnitTestFormCollection</b>. /// </summary> /// <param name="value">The value to locate in the <see cref="UnitTestFormCollection"/>.</param> /// <returns> /// The zero-based index of <paramref name="value"/>, if <paramref name="value"/> is found in /// the <see cref="UnitTestFormCollection"/>; otherwise, -1. /// </returns> /// <remarks> /// <para>The index sequence is based on the sort sequence. When an element is added, /// it is inserted into <see cref="UnitTestFormCollection"/> in the correct sort order, and /// the indexing adjusts accordingly. When an element removed, the indexing also adjusts /// accordingly. Therefore, the index of a specific key-and-value pair might change as /// elements are added or removed from the <see cref="UnitTestFormCollection"/>.</para> /// <para>The values of the elements of the <see cref="UnitTestFormCollection"/> are compared to the /// specified value using the Equals method.</para> /// <para>This method uses a linear search; therefore, the average execution time is /// proportional to <see cref="UnitTestFormCollection.Count"/>.</para> /// </remarks> public virtual int IndexOfValue(UnitTestItem value) { return Array.IndexOf(values, value, 0, count); }
public virtual int IndexOf(UnitTestItem value) { return list.IndexOfValue(value); }
public virtual void Reset() { if (version != list.version) throw new InvalidOperationException("The collection was modified - enumeration cannot continue."); // We can't set the entries equal to null, because they might be value types. // Instead, we'll create empty single-element arrays of the right type and copy them // over the entries we want to erase. string[] tempKey = new string[1]; UnitTestItem[] tempVal = new UnitTestItem[1]; key = tempKey[0]; value = tempVal[0]; currentValid = false; index = startIndex; }
public override void SetByIndex(int index, UnitTestItem value) { lock (root) list.SetByIndex(index, value); }
public virtual bool Contains(UnitTestItem value) { return list.ContainsValue(value); }
public override int IndexOfValue(UnitTestItem value) { lock (root) return list.IndexOfValue(value); }
public override bool ContainsValue(UnitTestItem value) { lock (root) return list.ContainsValue(value); }
public override void Add(string key, UnitTestItem value) { lock (root) list.Add(key, value); }
/// <summary> /// Adds the tests to the report. /// </summary> /// <param name="parentRow"> The TestItemRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="unitTestItem"> The UnitTestItem type.</param> private void AddTest(HtmlUnitTestReport.TestItemRow parentRow, HtmlUnitTestReport report, UnitTestItem unitTestItem) { HtmlUnitTestReport.TestsRow row = report.Tests.NewTestsRow(); Test t = unitTestItem.Tests.GetByIndex(unitTestItem.SelectedTestIndex); if ( t.Arguments is BufferOverflowTesterArgs ) { row.BufferLength = ((BufferOverflowTesterArgs)t.Arguments).BufferLength; } if ( t.Arguments is DataTypesTesterArgs ) { Ecyware.GreenBlue.Engine.DataType dt = ((DataTypesTesterArgs)t.Arguments).SelectedDataType; switch ( dt ) { case Ecyware.GreenBlue.Engine.DataType.Character: row.DataTypeTest = "Character"; break; case Ecyware.GreenBlue.Engine.DataType.Null: row.DataTypeTest = "Null String"; break; case Ecyware.GreenBlue.Engine.DataType.Numeric: row.DataTypeTest = "Numeric"; break; } } if ( t.Arguments is SqlInjectionTesterArgs ) { string testValue = ((SqlInjectionTesterArgs)t.Arguments).SqlValue; row.TestValue = testValue; } if ( t.Arguments is XssInjectionTesterArgs ) { string testValue = ((XssInjectionTesterArgs)t.Arguments).XssValue; row.TestValue = testValue; } row.PostData = t.Arguments.PostData; row.Name = t.Name; switch ( t.UnitTestDataType ) { case UnitTestDataContainer.Cookies: row.PostDataContainer = "Cookies"; break; case UnitTestDataContainer.HtmlFormTag: row.PostDataContainer = "Form"; break; case UnitTestDataContainer.NoPostData: row.PostDataContainer = "Url"; break; case UnitTestDataContainer.PostDataHashtable: row.PostDataContainer = "Post Data"; break; } switch ( t.TestType ) { case UnitTestType.BufferOverflow: row.TestType = "Buffer overflow"; break; case UnitTestType.DataTypes: row.TestType = "Data type"; break; case UnitTestType.Predefined: row.TestType = "Predefined"; break; case UnitTestType.SafeTest: row.TestType = "Safe Test"; break; case UnitTestType.SqlInjection: row.TestType = "SQL Injection"; break; case UnitTestType.XSS: row.TestType = "XSS"; break; } row.SetParentRow(parentRow); report.Tests.AddTestsRow(row); }
/// <summary> /// Adds an element with the specified key and value to the <b>UnitTestFormCollection</b>. /// </summary> /// <param name="key">The key of the element to add.</param> /// <param name="value">The value of the element to add.</param> /// <exception cref="ArgumentNullException">The <paramref name="key"/> is a null reference.</exception> /// <exception cref="ArgumentException"> /// <para>An element with the specified <paramref name="key"/> already exists in the <see cref="UnitTestFormCollection"/>.</para> /// <para>-or-</para> /// <para>The <b>UnitTestFormCollection</b> is set to use the <see cref="IComparable"/> interface, /// and <paramref name="key"/> does not implement the <b>IComparable</b> interface.</para> /// </exception> /// <exception cref="InvalidOperationException">The comparer throws an exception.</exception> /// <exception cref="NotSupportedException"> /// <para>The <see cref="UnitTestFormCollection"/> is read-only.</para> /// <para>-or-</para> /// <para>The <b>UnitTestFormCollection</b> has a fixed size.</para> /// </exception> public virtual void Add(string key, UnitTestItem value) { if (Object.ReferenceEquals(key, null)) // avoids compiler error for null check on value type throw new ArgumentNullException("key", "The key cannot be null."); int index = Array.BinarySearch(keys, 0, count, key, comparer); if (index >= 0) throw new ArgumentException(String.Format("Item has already been added. Key being added: \"{0}\".", key)); Insert(~index, key, value); }
/// <summary> /// Adds a UnitTestItem to a HtmlUnitTestReport. /// </summary> /// <param name="parentRow"> The TestItemRow.</param> /// <param name="report"> The HtmlUnitTestReport type.</param> /// <param name="unitTestItem"> The UnitTestItem type.</param> /// <returns> A TestItemRow type.</returns> private HtmlUnitTestReport.TestItemRow AddTestItemRow(HtmlUnitTestReport.ResponseDocumentRow parentRow,HtmlUnitTestReport report, UnitTestItem unitTestItem) { HtmlUnitTestReport.TestItemRow row = report.TestItem.NewTestItemRow(); row.SetParentRow(parentRow); report.TestItem.AddTestItemRow(row); return row; }
/// <summary> /// Runs the command. /// </summary> public void Run() { this._isRunning = true; postRequest = new PostForm(); getRequest = new GetForm(); postRequest.EndHttp += new ResponseCallbackDelegate(httpResponse_EndHttp); getRequest.EndHttp += new ResponseCallbackDelegate(httpResponse_EndHttp); reports = new ArrayList(); TestCollection tests = GetTests(); UnitTestItem testItem = new UnitTestItem(FormTag, tests); int availableTests = tests.Count; bool lastItem = false; #region Run each test in UnitTestItem // run each test in Form foreach (DictionaryEntry de in tests) { Test test = (Test)de.Value; // apply test to form HtmlFormTag filledForm = ApplyTestToForm(test, FormTag.CloneTag()); // set current test index testItem.SelectedTestIndex = testItem.Tests.IndexOfValue(test); // resolve uri string url = UriResolver.ResolveUrl(this.Url,filledForm.Action); // convert to array list // TODO: Send HTML Source for bypassing fields. Will be needed for ASP.NET testing. ArrayList al = parser.GetArrayList(filledForm); // set posted data StringBuilder postDataBuffer = new StringBuilder(); postDataBuffer.Append("?"); for (int k=0;k<al.Count;k++) { postDataBuffer.Append(al[k]); postDataBuffer.Append("&"); } test.Arguments.PostData = postDataBuffer.ToString(); // set last item flag if ( availableTests == 1) { lastItem = true; } CookieManager cookieManager = new CookieManager(); CookieCollection cookies = cookieManager.GetCookies(new Uri(url)); HttpState httpRequestState = new HttpState(); httpRequestState.TestItem = testItem.Clone(); httpRequestState.IsLastItem = lastItem; if ( filledForm.Method.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "get" ) { getRequest.StartAsyncHttpGet( url, this.ProtocolProperties, al, cookies, httpRequestState, false); } else { postRequest.StartAsyncHttpPost( url, this.ProtocolProperties, al, cookies, httpRequestState); } availableTests--; } #endregion }