Esempio n. 1
0
        /// <summary>
        /// Runs FUN test cases for Partner Notification service
        /// </summary>
        /// <param name="testcasename">test case name</param>
        /// <param name="updateurl">autoupdate url</param>
        /// <param name="testNode">node representing the test data for a perticular test</param>
        internal void TestRunnerPN(string testcasename, string updateurl, XmlNode testNode)
        {
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;

            try
            {
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                updateurl += "?";

                for (int i = 3; i < testNode.Attributes.Count; i++)
                {
                    if (!testNode.Attributes[i].Name.Equals("NA", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("PuidBasedAuth", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("UserName", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("Password", StringComparison.InvariantCultureIgnoreCase))
                    {
                        updateurl += testNode.Attributes[i].Name + "=" + testNode.Attributes[i].Value + "&";
                    }
                    else if (testNode.Attributes[i].Name.Equals("PuidBasedAuth", StringComparison.InvariantCultureIgnoreCase))
                    {
                        try
                        {
                            Helper.PuidBasedAuth = Boolean.Parse(testNode.Attributes[i].Value.Trim());
                        }
                        catch
                        {
                            Helper.PuidBasedAuth = true;
                        }

                        Helper.Email    = testNode.Attributes["UserName"].Value;
                        Helper.Password = testNode.Attributes["Password"].Value;
                    }
                }

                this.responseFromServer = string.Empty;

                Logger.AddComment("Notification url: " + updateurl, Logger.CommentType.Message);
                request  = MyWeb.CreateGetRequest(new Uri(updateurl).AbsoluteUri, true);
                response = (HttpWebResponse)request.GetResponse();

                if (response == null)
                {
                    Logger.AddComment(Test.FUN_RESPONSE_NULL, Logger.CommentType.Error);
                    throw new FUNException();
                }

                ////take out the stream from response.
                this.datastream = response.GetResponseStream();

                this.reader = new StreamReader(this.datastream);

                this.responseFromServer = this.reader.ReadToEnd();

                if (!(response.StatusCode == HttpStatusCode.OK))
                {
                    Logger.AddComment("Notification url returned errror", Logger.CommentType.Error);
                    throw new FUNException();
                }
                else
                {
                    // Throws exception in case of failure; does nothing otherwise
                    this.ValidateNotificationXml();

                    Logger.AddComment(Test.NOTIFICATION_XML + this.responseFromServer, Logger.CommentType.Message);
                    //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                    Logger.AddComment("Notification xml download: " + updateurl, Logger.CommentType.Pass);
                    //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                }
            }
            catch (XmlException ex)
            {
                Logger.AddComment("Notification XML is incorrect: " + ex.Message + ex.StackTrace, Logger.CommentType.Error);
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                Logger.AddComment("Notification xml download failed", Logger.CommentType.Fail);
            }
            catch (FUNException)
            {
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                Logger.AddComment(Test.NOTIFICATION_XML + this.responseFromServer, Logger.CommentType.Error);
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                Logger.AddComment(testcasename, Logger.CommentType.Fail);
            }
            catch (WebException ex)
            {
                string actualresponsestatusmsg    = ex.Message;
                string expectedresponsestatuscode = testNode.Attributes["ExpectedResult"].Value;

                if (actualresponsestatusmsg.Contains(expectedresponsestatuscode))
                {
                    //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                    Logger.AddComment("Expected response: " + expectedresponsestatuscode + ", actual response: " + actualresponsestatusmsg,
                                      Logger.CommentType.Pass);
                }
                else if (actualresponsestatusmsg.Contains("502"))
                {
                    //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                    this.LogServerResponse(ex.Response);
                    Logger.AddComment("Expected response: " + expectedresponsestatuscode + ", actual response: " + actualresponsestatusmsg,
                                      Logger.CommentType.Fail);
                }
                else
                {
                    //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                    Logger.AddComment("Expected response: " + expectedresponsestatuscode + ", actual response: " + actualresponsestatusmsg,
                                      Logger.CommentType.Fail);
                }
            }
            catch (Exception ex)
            {
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                Logger.AddComment(Messages.SmokeToolException + ex.Message + ex.StackTrace, Logger.CommentType.Error);
                Logger.AddComment("Notification xml downlaod failed", Logger.CommentType.Fail);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }

                if (this.reader != null)
                {
                    this.reader.Close();
                }

                if (this.datastream != null)
                {
                    this.datastream.Close();
                }

                Helper.PuidBasedAuth = false;
                Helper.Email         = string.Empty;
                Helper.Password      = string.Empty;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a generalised Web request.
        /// </summary>
        /// <param name="path">Url for which the response has to be created</param>
        /// <param name="forPuid">true if uses puid-based-auth</param>
        /// <returns>Web request for given Url</returns>
        public static HttpWebRequest CreateGetRequest(string path, bool forPuid)
        {
            HttpWebRequest request = null;

            try
            {
                request = (HttpWebRequest)WebRequest.Create(new Uri(path));

                if (!string.IsNullOrEmpty(Helper.ProxyAddress))
                {
                    request.Proxy = new WebProxy(Helper.ProxyAddress, Helper.Port);
                }

                request.AllowAutoRedirect = false;
                request.Method            = "GET";

                if (forPuid)
                {
                    if (Helper.PuidBasedAuth)
                    {
                        string email    = Helper.Email;
                        string password = Helper.Password;

                        //Logger.AddComment(string.Empty, Logger.CommentType.Break);

                        if (email != MyWeb._priorEmail || password != MyWeb._priorPassowrd || MyWeb._cookieJar == null)
                        {
                            MyWeb._priorEmail    = email;
                            MyWeb._priorPassowrd = password;

                            MyWeb._cookieJar = MyWeb.LoginAccount(email, password);
                            //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                        }

                        if (MyWeb._cookieJar != null)
                        {
                            request.CookieContainer = new CookieContainer();
                            request.CookieContainer = MyWeb._cookieJar;
                        }
                    }
                }

                request.ProtocolVersion = HttpVersion.Version10;
                request.Accept          = "*/*";
                request.Headers.Add("Accept-Language", "en-us");
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; Trident/4.0; .NET CLR 2.0.50727; " +
                                    ".NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
                request.Headers.Add("Accept-Encoding", "gzip, deflate");
            }
            catch (FUNException)
            {
                throw;
            }
            catch (WebException e)
            {
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                Logger.AddComment("Error occured while creating http request: ", Logger.CommentType.Error);
                throw new FUNException(Messages.SmokeToolException, e);
            }

            return(request);
        }
Esempio n. 3
0
        /// <summary>
        /// Runs FUN test case for checking AutoUpdate and Feature Update services
        /// </summary>
        /// <param name="testcasename">test case name</param>
        /// <param name="updateurl">auto update url</param>
        /// <param name="testNode">node representing the test data for a particular test</param>
        internal void TestRunner(string testcasename, string updateurl, XmlNode testNode)
        {
            HttpWebRequest  request  = null;
            HttpWebResponse response = null;

            Stream resStream = null;
            Stream cabFile   = null;

            string cabManifest   = null;
            bool   sha1Confirmed = false;

            try
            {
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);

                ////make complete FUN Url added with query string for a specific language, company and location.
                int j = testNode.Attributes.Count;

                updateurl += "?";

                for (int i = 3; i < j; i++)
                {
                    if (!testNode.Attributes[i].Name.Equals("NA", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("PuidBasedAuth", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("UserName", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("Password", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("ManifestUrl", StringComparison.InvariantCultureIgnoreCase) &&
                        !testNode.Attributes[i].Name.Equals("ManifestSha1", StringComparison.InvariantCultureIgnoreCase))
                    {
                        updateurl += testNode.Attributes[i].Name + "=" + testNode.Attributes[i].Value.Trim() + "&";
                    }
                    else if (testNode.Attributes[i].Name.Equals("PuidBasedAuth", StringComparison.InvariantCultureIgnoreCase))
                    {
                        try
                        {
                            Helper.PuidBasedAuth = Boolean.Parse(testNode.Attributes[i].Value.Trim());
                        }
                        catch
                        {
                            Helper.PuidBasedAuth = true;
                        }

                        Helper.Email    = testNode.Attributes["UserName"].Value.Trim();
                        Helper.Password = testNode.Attributes["Password"].Value.Trim();
                    }
                    else if (testNode.Attributes[i].Name.Equals("ManifestUrl", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Helper.ManifestUrl = testNode.Attributes["ManifestUrl"].Value.Trim();
                    }
                }

                Logger.AddComment("FUN Url: " + updateurl, Logger.CommentType.Message);

                this.responseFromServer = string.Empty;
                request  = MyWeb.CreateGetRequest(new Uri(updateurl).AbsoluteUri, true);
                response = (HttpWebResponse)request.GetResponse();
                string redirecturl = String.Empty;

                while (Test.IsGlink(response, out redirecturl))
                {
                    request = MyWeb.CreateGetRequest(redirecturl, false);
                    response.Close();

                    response = (HttpWebResponse)request.GetResponse();
                }

                if (!(response.StatusCode == HttpStatusCode.OK))
                {
                    Logger.AddComment(testcasename + ": incorrect response retreived from manifest url",
                                      Logger.CommentType.Error);
                    this.LogServerResponse(response);
                    throw new FUNException();
                }

                // Remove the stream from the response
                resStream = response.GetResponseStream();

                // Remove the file download url from the response
                audownloadUrl = response.ResponseUri.AbsoluteUri;

                // Check if URL in response matches the expected based on request
                if (audownloadUrl.ToLower() == Helper.ManifestUrl.ToLower())
                {
                    Logger.AddComment("Returned manifest URL matches expected", Logger.CommentType.Message);
                }
                else
                {
                    Logger.AddComment("Expected manifest url: " + Helper.ManifestUrl, Logger.CommentType.Message);
                    Logger.AddComment("Returned manifest URL does not match expected", Logger.CommentType.Error);
                }

                if (audownloadUrl.Contains("?"))
                {
                    int querystringstartindex = audownloadUrl.IndexOf("?");
                    audownloadUrl = audownloadUrl.Substring(0, querystringstartindex);
                }

                string manifestcabname = audownloadUrl.Substring(audownloadUrl.LastIndexOf("/") + 1);

                cabManifest = this.objHelper.DownloadFolder + @"\" + manifestcabname;
                Logger.AddComment("Downloading file: " + manifestcabname, Logger.CommentType.Message);

                // Create cab file based on the response
                cabFile = File.Create(cabManifest);
                byte[] buffer = new byte[1024];
                int    bytesRead;

                do
                {
                    // Read data (up to 1k) from the stream
                    bytesRead = resStream.Read(buffer, 0, buffer.Length);

                    // Write data to the local file
                    cabFile.Write(buffer, 0, bytesRead);
                }while (bytesRead > 0);

                if (cabFile == null)
                {
                    // Cab file not created
                    Logger.AddComment(testcasename + ": Manifest downloaded from URL is blank: " + updateurl,
                                      Logger.CommentType.Error);
                    throw new FUNException();
                }

                /* Comment By:v-aroy,Since binaries gets updated and based on the updated binaries we need to modify the
                 * hash value of the file.If there are mismatch then test cases would fail.At this point of time we are
                 * validating the file download only.
                 * string hashvalue = String.Empty;
                 * hashvalue = this.GetStoredHashfromTextFile(manifestcabname);
                 * if (hashvalue == null)
                 * {
                 *  Logger.AddComment(testcasename.PadRight(20) + Test.HASH_VALUES_FILENAME + Messages.FileMissing, Logger.CommentType.Error);
                 *  throw new FUNException();
                 * }
                 *
                 * // compute hash value from the Smoke tool
                 * string hash = this.GetHashByFile(cabManifest);
                 *
                 * if (hashvalue == String.Empty)
                 * {
                 *  Logger.AddComment(testcasename.PadRight(20) + Messages.HashNotFound + Test.HASH_VALUES_FILENAME + " for file : " + manifestcabname, Logger.CommentType.Error);
                 * throw new FUNException();
                 * }
                 *
                 * ////comapare the hash value of file downloaded with the hash value for that file in HashValues.txt file for that cab file
                 * if (hash != hashvalue)
                 * {
                 *  Logger.AddComment(testcasename.PadRight(20) + Messages.HashUnmatched.PadRight(20) + manifestcabname, Logger.CommentType.Error);
                 *  throw new FUNException();
                 * }
                 *
                 * Logger.AddComment(Messages.HashMatched.PadRight(20) + manifestcabname, Logger.CommentType.Message);
                 */

                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                cabFile.Close(); // Will fail on file access if not

                // Validate expected SHA1 value for manifest.cab using the downloaded file
                sha1Confirmed = Test.SHA1ValuesMatch(cabManifest, testNode.Attributes["ManifestSha1"].Value.Trim());

                if (sha1Confirmed)
                {
                    Logger.AddComment(testcasename + " cab file downloaded successfully and matches expected SHA1 value: "
                                      + updateurl, Logger.CommentType.Pass);
                }
            }
            catch (FUNException)
            {
                Logger.AddComment(testcasename, Logger.CommentType.Fail);
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
            }
            catch (WebException ex)
            {
                string actualresponsestatusmsg    = ex.Message.ToString();
                string expectedresponsestatuscode = testNode.Attributes["ExpectedResult"].Value;

                if (actualresponsestatusmsg.Contains(expectedresponsestatuscode))
                {
                    Logger.AddComment(testcasename + " expected response: " + expectedresponsestatuscode +
                                      ", actual response: " + actualresponsestatusmsg, Logger.CommentType.Pass);
                }
                else if (actualresponsestatusmsg.Contains("502"))
                {
                    this.LogServerResponse(ex.Response);
                    Logger.AddComment(testcasename + " expected response: " + expectedresponsestatuscode, Logger.CommentType.Fail);
                }
                else
                {
                    Logger.AddComment(testcasename + " expected response: " + expectedresponsestatuscode +
                                      ", actual response: " + actualresponsestatusmsg, Logger.CommentType.Fail);
                }
            }
            catch (Exception ex)
            {
                //Logger.AddComment(string.Empty, Logger.CommentType.Break);
                Logger.AddComment(testcasename, Logger.CommentType.Fail);
                Logger.AddComment(Messages.SmokeToolException + ex.Message + ex.StackTrace, Logger.CommentType.Error);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }

                if (cabFile != null)
                {
                    cabFile.Close();
                }

                if (this.reader != null)
                {
                    this.reader.Close();
                }

                if (this.datastream != null)
                {
                    this.datastream.Close();
                }

                Helper.Password      = string.Empty;
                Helper.Email         = string.Empty;
                Helper.PuidBasedAuth = false;
            }
        }