{"action":"opened","issue":{"url":"https://api.github.com/repos/ravitejaseetha/Coded_UI/issues/5","repository_url":"https://api.github.com/repos/ravitejaseetha/Coded_UI","labels_url":"https://api.github.com/repos/ravitejaseetha/Coded_UI/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/ravitejaseetha/Coded_UI/issues/5/comments","events_url":"https://api.github.com/repos/ravitejaseetha/Coded_UI/issues/5/events","html_url":"https://github.com/ravitejaseetha/Coded_UI/issues/5","id":223609006,"number":5,"title":"issue5","user":{"login":"ravitejaseetha","id":7837013,"avatar_url":"https://avatars2.githubusercontent.com/u/7837013?v=3","gravatar_id":"","url":"https://api.github.com/users/ravitejaseetha","html_url":"https://github.com/ravitejaseetha","followers_url":"https://api.github.com/users/ravitejaseetha/followers","following_url":"https://api.github.com/users/ravitejaseetha/following{/other_user}","gists_url":"https://api.github.com/users/ravitejaseetha/gists{/gist_id}","starred_url":"https://api.github.com/users/ravitejaseetha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ravitejaseetha/subscriptions","organizations_url":"https://api.github.com/users/ravitejaseetha/orgs","repos_url":"https://api.github.com/users/ravitejaseetha/repos","events_url":"https://api.github.com/users/ravitejaseetha/events{/privacy}","received_events_url":"https://api.github.com/users/ravitejaseetha/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-23T03:14:04Z","updated_at":"2017-04-23T03:14:04Z","closed_at":null,"body":"\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Security.Cryptography;\r\nusing System.Text.RegularExpressions;\r\nusing System.Net;\r\nusing System.IO;\r\nusing NUnit.Framework;\r\nusing Newtonsoft.Json;\r\n\r\npublic class DigestAuthRequest\r\n{\r\n    private static string _host = \"http://172.25.177.146\";\r\n    private static string _user = \"DC_API_HEALTH\";\r\n    private static string _password = \"DC_API_HEALTH\";\r\n    private static string _realm;\r\n    private static string _nonce;\r\n    private static string _qop;\r\n    private static string _cnonce;\r\n    private static DateTime _cnonceDate;\r\n    private static int _nc;\r\n\r\n    public DigestAuthRequest(string host, string user, string password)\r\n    {\r\n        // TODO: Complete member initialization\r\n        _host = host;\r\n        _user = user;\r\n        _password = password;\r\n    }\r\n\r\n    public DigestAuthRequest()\r\n    {\r\n\r\n    }\r\n    [Test]\r\n    public void CheckStatus()\r\n    {\r\n\r\n       var response =  GrabResponse(\"/di/services/admin/serverConfiguration\");\r\n        var statusObj = JsonConvert.DeserializeObject<ValidateResponse>(response);\r\n        Assert.AreEqual(\"ONLINE\", statusObj.status);\r\n\r\n    }\r\n    private string CalculateMd5Hash(string input)\r\n    {\r\n\r\n        var inputBytes = Encoding.ASCII.GetBytes(input);\r\n        var hash = MD5.Create().ComputeHash(inputBytes);\r\n        var sb = new StringBuilder();\r\n        foreach (var b in hash)\r\n            sb.Append(b.ToString(\"x2\"));\r\n        return sb.ToString();\r\n    }\r\n\r\n    private string GrabHeaderVar(string varName, string header)\r\n    {\r\n\r\n        var regHeader = new Regex(string.Format(@\"{0}=\"\"([^\"\"]*)\"\"\", varName));\r\n        var matchHeader = regHeader.Match(header);\r\n        if (matchHeader.Success)\r\n            return matchHeader.Groups[1].Value;\r\n        throw new ApplicationException(string.Format(\"Header {0} not found\", varName));\r\n    }\r\n\r\n    private string GetDigestHeader(string dir)\r\n    {\r\n\r\n        _nc = _nc + 1;\r\n\r\n        var ha1 = CalculateMd5Hash(string.Format(\"{0}:{1}:{2}\", _user, _realm, _password));\r\n        var ha2 = CalculateMd5Hash(string.Format(\"{0}:{1}\", \"GET\", dir));\r\n        var digestResponse =\r\n            CalculateMd5Hash(string.Format(\"{0}:{1}:{2:00000000}:{3}:{4}:{5}\", ha1, _nonce, _nc, _cnonce, _qop, ha2));\r\n\r\n        return string.Format(\"Digest username=\\\"{0}\\\", realm=\\\"{1}\\\", nonce=\\\"{2}\\\", uri=\\\"{3}\\\", \" +\r\n                             \"algorithm=MD5, response=\\\"{4}\\\", qop={5}, nc={6:00000000}, cnonce=\\\"{7}\\\"\",\r\n            _user, _realm, _nonce, dir, digestResponse, _qop, _nc, _cnonce);\r\n    }\r\n\r\n    public string GrabResponse(string dir)\r\n    {\r\n\r\n        var url = _host + dir;\r\n        var uri = new Uri(url);\r\n\r\n        var request = (HttpWebRequest)WebRequest.Create(uri);\r\n\r\n        // If we've got a recent Auth header, re-use it!\r\n        if (!string.IsNullOrEmpty(_cnonce) &&\r\n            DateTime.Now.Subtract(_cnonceDate).TotalHours < 1.0)\r\n        {\r\n            request.Headers.Add(\"Authorization\", GetDigestHeader(dir));\r\n        }\r\n\r\n        HttpWebResponse response;\r\n        try\r\n        {\r\n            response = (HttpWebResponse)request.GetResponse();\r\n        }\r\n        catch (WebException ex)\r\n        {\r\n            // Try to fix a 401 exception by adding a Authorization header\r\n            if (ex.Response == null || ((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.Unauthorized)\r\n                throw;\r\n\r\n            var wwwAuthenticateHeader = ex.Response.Headers[\"WWW-Authenticate\"];\r\n            _realm = GrabHeaderVar(\"realm\", wwwAuthenticateHeader);\r\n            _nonce = GrabHeaderVar(\"nonce\", wwwAuthenticateHeader);\r\n            _qop = GrabHeaderVar(\"qop\", wwwAuthenticateHeader);\r\n\r\n            _nc = 0;\r\n            _cnonce = new Random().Next(123400, 9999999).ToString();\r\n            _cnonceDate = DateTime.Now;\r\n\r\n            var request2 = (HttpWebRequest)WebRequest.Create(uri);\r\n            request2.Headers.Add(\"Authorization\", GetDigestHeader(dir));\r\n            request2.ContentType = \"application/json\";\r\n            request2.Accept = \"application/json\";\r\n            response = (HttpWebResponse)request2.GetResponse();\r\n        }\r\n        var reader = new StreamReader(response.GetResponseStream());\r\n        return reader.ReadToEnd();\r\n    }\r\n\r\n    public class ValidateResponse\r\n    {\r\n        public string status { get; set; }\r\n    }\r\n}"}}
{"actor":{"display_login":"ravitejaseetha"}}