public static HttpRequestWrapperException DeserializeException(string str)
        {
            using (Stream stream = new MemoryStream())
            {
                StringToStream(EncodingHelper.Base64Decode(str), stream);
                stream.Seek(0, SeekOrigin.Begin);
                Dictionary <string, string> dictionary = DeserializeDictionary(stream);
                Stream bodyStream = new MemoryStream();

                var headers = new Dictionary <string, string>();
                foreach (var key in dictionary.Keys)
                {
                    if (key.StartsWith("Header-", StringComparison.OrdinalIgnoreCase))
                    {
                        headers.Add(key.Substring(7), dictionary[key]);
                    }
                }

                StringToStream(dictionary["Body"], bodyStream);
                bodyStream.Position = 0;
                return(new HttpRequestWrapperException(
                           new HttpWebResponseWrapper(bodyStream, headers, (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), dictionary["StatusCode"])),
                           new HttpRequestException()));
            }
        }
Exemplo n.º 2
0
        private PasswordModel GetPasswordModelFromEncodedPassword(string password)
        {
            var decodedPassword   = EncodingHelper.Base64Decode(password);
            var decryptedPassword = EncryptionHelper.Decrypt(decodedPassword);

            return(JsonConvert.DeserializeObject <PasswordModel>(decryptedPassword));
        }
Exemplo n.º 3
0
 public static WebException DeserializeWebException(string str)
 {
     using (Stream stream = new MemoryStream())
     {
         StringToStream(EncodingHelper.Base64Decode(str), stream);
         stream.Seek(0, SeekOrigin.Begin);
         Dictionary <string, string> dictionary = DeserializeDictionary(stream);
         WebResponse replayerWebResponse        = new ReplayerWebResponse(dictionary);
         return(new WebException("", null, WebExceptionStatus.UnknownError, replayerWebResponse));
     }
 }
        public void PasswordGeneration_CheckGeneration_DecodedPasswordShouldKeepTheValues(int userId, DateTime generationDate)
        {
            //Arrange

            _passwordGuidRepositoryMock.Setup(x => x.StoreGuid(It.IsAny <string>())).Returns(true);
            var passwordGenerator = new PasswordGeneratorService(_passwordGuidRepositoryMock.Object);

            //Act
            var password        = passwordGenerator.GenerateOneTimePassword(userId, generationDate);
            var decodedPassword = EncodingHelper.Base64Decode(password);
            var passwordModel   = JsonConvert.DeserializeObject <PasswordModel>(EncryptionHelper.Decrypt(decodedPassword));


            //Assert
            Assert.AreEqual(userId, passwordModel.UserId);
            Assert.AreEqual(generationDate, new DateTime(passwordModel.CreationDateTicks));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string key     = Request.QueryString["code"];
            string game    = Request.QueryString["game"];
            string balance = Request.QueryString["balance"];

            if (key != null)
            {
                CodePanel.Visible = true;
                Code.Text         = EncodingHelper.Base64Decode(HttpUtility.UrlDecode(key));
            }

            if (game != null && int.TryParse(game, out int gameId))
            {
                GamePanel.Visible    = true;
                PlayHere.NavigateUrl = "./GamePage.aspx?id=" + gameId;
            }

            if (balance != null && double.TryParse(balance, out double amount))
            {
                BalancePanel.Visible = true;
                AmountAdded.Text     = "$" + amount + " Has been added to your balance!";
            }
        }