Beispiel #1
0
        public ActionResult RequestSecret()
        {
            for (int i = 0; i < 20; i++)
            {
                string encodedResponse;
                ResponseModel obtainedResponseModel;
                string guid = Guid.NewGuid().ToString();
                using (var client = new WebClient())
                {
                    client.Headers.Add(HttpRequestHeader.Accept, "application/json");
                    var guidConcat = "values/" + guid;
                    var json = client.DownloadString("http://internal-devchallenge-2-dev.apphb.com/" + guidConcat);
                    obtainedResponseModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseModel>(json);
                    AlgorithmsHandler handler = new AlgorithmsHandler();
                    encodedResponse = handler.Encode(obtainedResponseModel);
                }

                var guidConcat2 = "values/" + guid + "/" + obtainedResponseModel.Algorithm.ToString("G");
                var http = (HttpWebRequest) WebRequest.Create(new Uri("http://internal-devchallenge-2-dev.apphb.com/" + guidConcat2));
                http.Accept = "application/json";
                http.ContentType = "application/json";
                http.Method = "POST";
                var postModel = new EncodedStringPostModel(encodedResponse);
                var stringifiedPostModel = Newtonsoft.Json.JsonConvert.SerializeObject(postModel);
                byte[] bytes = Encoding.ASCII.GetBytes(stringifiedPostModel);

                Stream newStream = http.GetRequestStream();
                newStream.Write(bytes, 0, bytes.Length);
                newStream.Close();

                var response = http.GetResponse();
                var stream = response.GetResponseStream();
                var sr = new StreamReader(stream);
                var content = sr.ReadToEnd();
                var postResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<PostResponseModel>(content);
                if (postResponse != null && postResponse.Status.ToLower().Equals("crashandburn"))
                    i--;
            }
            return RedirectToAction("Messages");
        }
Beispiel #2
0
        public ActionResult RequestSecretForDebugging()
        {
            for (int i = 0; i < 1000; i++)
            {
                string encodedResponse;
                ResponseModel obtainedResponseModel;
                string guid = Guid.NewGuid().ToString();
                using (var client = new WebClient())
                {
                    client.Headers.Add(HttpRequestHeader.Accept, "application/json");
                    var guidConcat = "values/" + guid;
                    var json = client.DownloadString("http://internal-devchallenge-2-dev.apphb.com/" + guidConcat);
                    obtainedResponseModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseModel>(json);
                    AlgorithmsHandler handler = new AlgorithmsHandler();
                    encodedResponse = handler.Encode(obtainedResponseModel);
                }

                using (var client = new WebClient())
                {
                    client.Headers.Add(HttpRequestHeader.Accept, "application/json");
                    var guidConcat = "encoded/" + guid + "/" + obtainedResponseModel.Algorithm.ToString("G");
                    var json = client.DownloadString("http://internal-devchallenge-2-dev.apphb.com/" + guidConcat);
                    EncodedResponseModel model = Newtonsoft.Json.JsonConvert.DeserializeObject<EncodedResponseModel>(json);
                    if (model.Encoded != encodedResponse)
                    {
                        throw new Exception();
                    }
                }
            }
            return RedirectToAction("Messages");
        }