Exemplo n.º 1
0
        /// <summary>
        /// Deserializes the specified r.
        /// </summary>
        /// <param name="r">The r.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        protected internal virtual T Deserialize(TextReader r, string path)
        {
            var result     = Activator.CreateInstance <T>();
            var parens     = JsonParserUtil.ReadStartObject(r);
            var hasMembers = (JsonParserUtil.PeekNextChar(r, true) != '}');

            while (hasMembers)
            {
                ReadMemeber(r, path, result);
                hasMembers = (JsonParserUtil.PeekNextChar(r, true) == ',');
                if (hasMembers)
                {
                    JsonParserUtil.ReadNextChar(r, true);
                }
            }
            JsonParserUtil.ReadEndObject(r, parens);
            return(result);
        }
        public string GetSerialviaType(string token, string type, string typevalue)
        {
            try
            {
                var    client  = new RestClient(endpoint + "/token/init?genkey=1");
                string binpath = AppDomain.CurrentDomain.BaseDirectory;
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("PI-Authorization", token);
                request.AddHeader("Content-Type", "application/json");

                if (type.ToLower().Contains("sms"))
                {
                    JsonParserUtil.updateJsonFiles(type, typevalue);
                    request.AddParameter("application/json", File.ReadAllText(Path.Combine(binpath + "\\APIDataFiles\\SMSAPIBody.json")), ParameterType.RequestBody);
                }
                else if (type.ToLower().Contains("email"))
                {
                    JsonParserUtil.updateJsonFiles(type, typevalue);
                    request.AddParameter("application/json", File.ReadAllText(Path.Combine(binpath + "\\APIDataFiles\\EmailAPIBody.json")), ParameterType.RequestBody);
                }
                else if (type.ToLower().Contains("hotp"))
                {
                    request.AddParameter("application/json", File.ReadAllText(Path.Combine(binpath + "\\APIDataFiles\\AuthAppAPIBody.json")), ParameterType.RequestBody);
                }
                else
                {
                    Assert.Fail("Wrong value in type value .. please correct it..");
                }


                IRestResponse response = client.Execute(request);
                Assert.AreEqual(response.StatusCode.ToString(), "OK", "Not getting correct API response..");

                //Console.WriteLine(response.Content);
                var getserialroots = JsonConvert.DeserializeObject <GetSerialRoots>(response.Content);
                return(getserialroots.Detail.Serial);
            }
            catch (Exception e)
            {
                throw new Exception("Error while validating the API result for --" + type + "With value..--" + typevalue + "Error received--" + e.Message);
            }
        }
        public IRestResponse VerifyErrorMsgWithInvalidUserName(String token, String user)
        {
            try
            {
                string binpath = AppDomain.CurrentDomain.BaseDirectory;
                var    client  = new RestClient("https://privacyidea.dgw-dev.mod.uk/token/init?genkey=1");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("PI-Authorization", token);
                request.AddHeader("Content-Type", "application/json");

                JsonParserUtil.InvalidUser("sms", user);
                request.AddParameter("application/json", File.ReadAllText(Path.Combine(binpath + "\\APIDataFiles\\SMSAPIBody.json")), ParameterType.RequestBody);

                IRestResponse response = client.Execute(request);
                return(response);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public string ValidateOTP(string pass, string token)
        {
            try
            {
                string binpath = AppDomain.CurrentDomain.BaseDirectory;
                var    client  = new RestClient(endpoint + "/validate/check");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("PI-Authorization", token);
                request.AddHeader("Content-Type", "text/plain");
                JsonParserUtil.UpdateOTP(pass);
                request.AddParameter("application/json", File.ReadAllText(Path.Combine(binpath + "\\APIDataFiles\\CheckOTPBody.json")), ParameterType.RequestBody);

                IRestResponse response = client.Execute(request);
                Assert.AreEqual(response.StatusCode.ToString(), "OK", "Not getting correct API response..");
                var validateroots = JsonConvert.DeserializeObject <ValidateOtp>(response.Content);
                return(validateroots.Detail.Message);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        public string GetCodeusingToken(string serial, string token)
        {
            try
            {
                string binpath = AppDomain.CurrentDomain.BaseDirectory;
                var    client  = new RestClient(endpoint + "/validate/triggerchallenge");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                request.AddHeader("PI-Authorization", token);
                request.AddHeader("Content-Type", "text/plain");
                JsonParserUtil.UpdateSerial(serial);
                request.AddParameter("application/json", File.ReadAllText(Path.Combine(binpath + "\\APIDataFiles\\GetTokenAPIBody.json")), ParameterType.RequestBody);

                IRestResponse response = client.Execute(request);
                Assert.AreEqual(response.StatusCode.ToString(), "OK", "Not getting correct API response..");

                return("code");
            }
            catch (Exception e)
            {
                throw;
            }
        }
Exemplo n.º 6
0
 internal override object BaseDeserialize(TextReader r, string path)
 {
     return(JsonParserUtil.PeekIsNull(r, true, path) ? null : (object)Deserialize(r, path));
 }
Exemplo n.º 7
0
        private void ReadMemeber(TextReader r, string path, T result)
        {
            var name        = JsonParserUtil.ReadMemberName(r);
            var sInfo       = _memberSerializers[name];
            var memberValue = sInfo.Serializer.BaseDeserialize(r, path + "/" + name);
            var targetType  = sInfo.MemberType;

            if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                targetType = targetType.GetGenericArguments()[0];
            }
            if (memberValue == null)
            {
                sInfo.SetValue(result, null);
            }
            else
            {
                if (targetType.IsEnum)
                {
                    var integerType = Enum.GetUnderlyingType(targetType);
                    if (integerType == typeof(UInt64))
                    {
                        sInfo.SetValue(result, Convert.ToUInt64(memberValue));
                    }
                    else if (integerType == typeof(Int64))
                    {
                        sInfo.SetValue(result, Convert.ToInt64(memberValue));
                    }
                    else if (integerType == typeof(UInt32))
                    {
                        sInfo.SetValue(result, Convert.ToUInt32(memberValue));
                    }
                    else if (integerType == typeof(Int32))
                    {
                        sInfo.SetValue(result, Convert.ToInt32(memberValue));
                    }
                    else if (integerType == typeof(UInt16))
                    {
                        sInfo.SetValue(result, Convert.ToUInt16(memberValue));
                    }
                    else if (integerType == typeof(Int16))
                    {
                        sInfo.SetValue(result, Convert.ToInt16(memberValue));
                    }
                    else if (integerType == typeof(Byte))
                    {
                        sInfo.SetValue(result, Convert.ToByte(memberValue));
                    }
                    else if (integerType == typeof(SByte))
                    {
                        sInfo.SetValue(result, Convert.ToSByte(memberValue));
                    }
                }
                else
                {
                    try { sInfo.SetValue(result, Convert.ChangeType(memberValue, targetType)); }
                    catch
                    {
                        if (memberValue != null)
                        {
                            if (memberValue is string && targetType == typeof(Uri))
                            {
                                sInfo.SetValue(result, new Uri((string)memberValue, UriKind.RelativeOrAbsolute));
                            }
                            else
                            {
                                var ctorInfo = targetType.GetConstructor(new[] { memberValue.GetType() });
                                if (ctorInfo != null)
                                {
                                    sInfo.SetValue(result, ctorInfo.Invoke(new[] { memberValue }));
                                }
                                else
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }