예제 #1
0
        protected string GetUpdatedParameterValue(HttpRequestInfo curWorkingReqInfo, TestJob testJob)
        {
            string        val       = null;
            HttpVariables variables = null;
            HTTPHeaders   headers   = null;

            switch (testJob.RequestLocation)
            {
            case RequestLocation.Body: variables = curWorkingReqInfo.BodyVariables; break;

            case RequestLocation.Path: variables = curWorkingReqInfo.PathVariables; break;

            case RequestLocation.Query: variables = curWorkingReqInfo.QueryVariables; break;

            case RequestLocation.Cookies: variables = curWorkingReqInfo.Cookies; break;

            case RequestLocation.Headers: headers = curWorkingReqInfo.Headers; break;
            }

            if (variables != null && variables.ContainsKey(testJob.ParameterName))
            {
                val = variables[testJob.ParameterName];
            }
            else if (headers != null)
            {
                val = headers[testJob.ParameterName];
            }

            return(val);
        }
예제 #2
0
		private void WriteParameters(XmlWriter writer, HttpVariables variables)
		{
			if (variables.Count > 0)
			{
				string linkParamType;
				string tvCustomParamName = String.Empty;
				string parameterType = Enum.GetName(typeof(RequestLocation), variables.MatchingDefinition.Location).ToUpper();
				bool isRegular;
				//hack for the unusual handling of custom parameters in AppScan
				if (String.Compare(variables.MatchingDefinition.Name, HttpVariableDefinition.REGULAR_TYPE, true) != 0)
				{
					isRegular = false;
					linkParamType = "invalid";
					parameterType = "QUERY";

				}
				else
				{
					isRegular = true;
					linkParamType = "simplelink";
				}

				int count = 0;

				foreach (KeyValuePair<string, string> pair in variables)
				{
					string name = isRegular ? pair.Key : String.Format("__patternParameter__{0}__{1}__{2}", variables.MatchingDefinition.Name, pair.Key, count);
					if (String.IsNullOrEmpty(ParameterExclusion) || !Utils.IsMatch(name, ParameterExclusion))
					{
						writer.WriteStartElement("parameter");
						writer.WriteAttributeString("name", name);
						writer.WriteAttributeString("value", pair.Value);
						writer.WriteAttributeString("type", parameterType);
						writer.WriteAttributeString("linkParamType", linkParamType);
						writer.WriteAttributeString("separator", "&");
						writer.WriteAttributeString("operator", "=");
						writer.WriteEndElement();
					}
					count++;
				}
			}
		}
예제 #3
0
        private void UpdateParams(HttpVariables variables, string responseText)
        {
            List <string> paramNames = new List <string>(variables.Keys);

            foreach (string name in paramNames)
            {
                if (Utils.IsMatchInList(name, _sessionIdNames))
                {
                    //update value from previous requests
                    if (_sessionIds.ContainsKey(name))
                    {
                        lock (_lock)
                        {
                            variables[name] = _sessionIds[name];
                        }
                    }

                    foreach (string responsePattern in _responsePatterns)
                    {
                        //match known response patterns
                        string regex = String.Format(responsePattern, name);
                        string value = Utils.RegexFirstGroupValue(responseText, regex);

                        if (!String.IsNullOrEmpty(value))
                        {
                            //update the parameter with the new value
                            variables[name] = value;
                            lock (_lock)
                            {
                                _sessionIds[name] = value;
                            }
                            break;                            //pattern was found break the loop
                        }
                    }
                }
            }
        }
예제 #4
0
        public void TestLink()
        {
            const string issueKey = "TIL-001";
            const string linkDescription = "Tested With";
            const int issueId = 42;

            var loginHttpClient = new Mock<IHttpClient>();
            var linkHttpClient = new Mock<IHttpClient>();
            var clientFactory = new Mock<IHttpClientFactory>();

            clientFactory.Setup(factory => factory.Connect(LoginPage)).Returns(loginHttpClient.Object);

            var config = new Mock<IHttpInterfaceConfiguration>();
            config.Setup(cfg => cfg.LoginUrl).Returns(LoginPage);
            config.Setup(cfg => cfg.LinkUrl).Returns(LinkPage);

            HttpVariables loginVariables = new HttpVariables();
            loginHttpClient.Setup(client => client.Variables).Returns(loginVariables);
            loginHttpClient.Setup(client => client.Post()).Callback(delegate
            {
                Assert.AreEqual("john", loginVariables["os_username"]);
                Assert.AreEqual("doe", loginVariables["os_password"]);
            });

            loginHttpClient.Setup(client => client.ResponseStream).Returns(new MemoryStream());
            var jiraProxy = new JiraHttpProxy(clientFactory.Object, config.Object);
            jiraProxy.Login(UserName, Password);

            clientFactory.Setup(factory => factory.Connect(LinkPage)).Returns(linkHttpClient.Object);
            HttpVariables linkVariables = new HttpVariables();
            linkHttpClient.Setup(client => client.Variables).Returns(linkVariables);
            linkHttpClient.Setup(client => client.ResponseStream).Returns(new MemoryStream());

            linkHttpClient.Setup(client => client.Post()).Callback(delegate
            {
                Assert.AreEqual(linkDescription, linkVariables["linkDesc"]);
                Assert.AreEqual(issueKey, linkVariables["linkKey"]);
                Assert.AreEqual("", linkVariables["comment"]);
                Assert.AreEqual("", linkVariables["commentLevel"]);
                Assert.AreEqual(issueId.ToString(), linkVariables["id"]);
                Assert.AreEqual("", linkVariables[""]);
                Assert.AreEqual("Link", linkVariables["Link"]);
            });

            jiraProxy.CreateLink(issueId, linkDescription, issueKey, true);

            loginHttpClient.VerifyAll();
            linkHttpClient.VerifyAll();
        }