Esempio n. 1
0
 public void PerformSuccessfulPostRequestWithShortPayload()
 {
     var data = "AnyData";
     var payload = new MemoryStream(Encoding.UTF8.GetBytes(data));
     var webClient = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS, payload);
     var dataStream = webClient.UploadString(BASE_ADDRESS.AbsoluteUri, data);
 }
Esempio n. 2
0
 public void SendTimedOutRequestAndRecieveUnauthorizedResponse()
 {
     try
     {
         var webClient = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS);
         var timeToSleep = GetRequestTimeOut();
         Thread.Sleep(timeToSleep);
         var dataStream = webClient.OpenRead(BASE_ADDRESS.AbsoluteUri);
     }
     catch (WebException ex)
     {
         var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
         Assert.IsTrue(HttpStatusCode.Unauthorized.Equals(statusCode));
     }
 }
Esempio n. 3
0
 public void TamperPayloadAndRecieveUnauthorizedResponse()
 {
     var data = "AnyData";
     var tamperedData = String.Format("{0}{1}", data, data);
     var payload = new MemoryStream(Encoding.UTF8.GetBytes(data));
     try
     {
         var webClient = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS, payload);
         var dataStream = webClient.UploadString(BASE_ADDRESS.AbsoluteUri, tamperedData);
     }
     catch (WebException ex)
     {
         var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
         Assert.IsTrue(HttpStatusCode.Unauthorized.Equals(statusCode));
     }
 }
Esempio n. 4
0
        public void SendTamperedTimeStampAndRecieveUnauthorizedResponse()
        {
            var data = "AnyData";
            var payload = new MemoryStream(Encoding.UTF8.GetBytes(data));
            try
            {
                var webClient = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS, payload);
                var headerValue = webClient.Headers.Get(HttpRequestHeader.Authorization.ToString()).Replace("API ", "");
                var decodedHeaderValue = Base64Decode(headerValue);
                var decodedHeaderSplitValues = decodedHeaderValue.Split(':');
                
                var tamperedTimeStamp = DateTime.Now.AddHours(1).ToString("MM/dd/yyyy hh:mm:ss tt");
                var tamperedTimeStampBytes = System.Text.Encoding.UTF8.GetBytes(tamperedTimeStamp);
                var encodedTimeStamp = Convert.ToBase64String(tamperedTimeStampBytes);

                var tamperedHeaderValue = String.Format("{0}:{1}:{2}", decodedHeaderSplitValues[0], encodedTimeStamp, decodedHeaderSplitValues[2]);
                var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(headerValue);
                
                webClient.Headers.Clear();
                webClient.Headers.Add(HttpRequestHeader.Authorization.ToString(), String.Format("{0} {1}", "API ", Convert.ToBase64String(plainTextBytes)));

                var dataStream = webClient.UploadString(BASE_ADDRESS.AbsoluteUri, data);
            }
            catch (WebException ex)
            {
                var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
                Assert.IsTrue(HttpStatusCode.Unauthorized.Equals(statusCode));
            }
        }
Esempio n. 5
0
 public void PerformASuccessfulGetRequest()
 {
     var webClient = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS);
     var dataStream = webClient.OpenRead(BASE_ADDRESS.AbsoluteUri);          
 }