public void IsEmpty_UserNameAndPasswordSet_ReturnsFalse()
        {
            var credentials = new NetworkCredential("user", "pass");

            bool result = credentials.IsEmpty();

            Assert.IsFalse(result);
        }
        public void IsEmpty_EmptyUserPassword_ReturnsFalse()
        {
            var credentials = new NetworkCredential("12314", string.Empty);

            bool result = credentials.IsEmpty();

            Assert.IsFalse(result);
        }
        public void IsEmpty_EmptyUserName_ReturnsTrue()
        {
            var credentials = new NetworkCredential(string.Empty, "123123");

            bool result = credentials.IsEmpty();

            Assert.IsTrue(result);
        }
Example #4
0
        private static IEnumerable <BindingElement> CreateBindingElements(MessageVersion messageVersion, bool useTls, NetworkCredential credentials)
        {
            var encoding = new TextMessageEncodingBindingElement(messageVersion, new UTF8Encoding(false))
            {
                ReaderQuotas = { MaxStringContentLength = int.MaxValue }
            };

            yield return(encoding);

            HttpTransportBindingElement transport = CreateTransportBindingElement(useTls);

            transport.MaxReceivedMessageSize = int.MaxValue;
            transport.KeepAliveEnabled       = false;
            transport.MaxBufferSize          = int.MaxValue;
            transport.ProxyAddress           = null;
            transport.BypassProxyOnLocal     = true;
            transport.UseDefaultWebProxy     = false;
            transport.TransferMode           = TransferMode.StreamedResponse;
            transport.AuthenticationScheme   = credentials.IsEmpty() ? AuthenticationSchemes.Anonymous : AuthenticationSchemes.Basic;

            yield return(transport);
        }
Example #5
0
        public async Task <CredentialVerificationResult> VerifyCredentialAsync(NetworkCredential credential, CancellationToken cancelToken)
        {
            if (credential.IsEmpty())
            {
                return(CredentialVerificationResult.NoCredential);
            }
            if (credential.IsInvalid())
            {
                return(CredentialVerificationResult.SpellingError);
            }

            // check network

            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                return(CredentialVerificationResult.NetworkError);
            }

            // check web-service

            var webServiceIsUpAndRunning = await ServiceWrapper.CheckAsync();

            if (webServiceIsUpAndRunning == false)
            {
                return(CredentialVerificationResult.WebServiceDown);
            }

            using (var wrapper = new ServiceWrapper(cancelToken))
            {
                var service = wrapper.Service;
                // check web-service call

                try
                {
                    var posts = await service.GetNewDataAsync(new ChangeRequest
                    {
                        userName           = credential.UserName,
                        password           = credential.Password,
                        maxOutput          = 0,
                        messageRowVersion  = new byte[8],
                        ratingRowVersion   = new byte[8],
                        moderateRowVersion = new byte[8],
                        subscribedForums   = new RequestForumInfo[]
                        {
                            new RequestForumInfo
                            {
                                forumId        = 1,
                                isFirstRequest = true
                            }
                        }
                    });

                    if (posts.Body.GetNewDataResult.userId == 0)
                    {
                        return(CredentialVerificationResult.WrongCredential);
                    }
                    else
                    {
                        var userId = posts.Body.GetNewDataResult.userId;

                        var users = await service.GetUserByIdsAsync(new UserByIdsRequest
                        {
                            userName = credential.UserName,
                            password = credential.Password,
                            userIds  = new ArrayOfInt {
                                userId
                            },
                        });

                        var user = users.Body.GetUserByIdsResult.users.FirstOrDefault();
                        if (user == null)
                        {
                            return(CredentialVerificationResult.WrongCredential);
                        }

                        this.User = new UserModel
                        {
                            Id        = user.userId,
                            Alias     = user.userNick,
                            Name      = user.userName,
                            RealName  = user.realName,
                            Origin    = user.whereFrom,
                            Address   = user.homePage,
                            Email     = user.publicEmail,
                            Interests = user.specialization,
                            Signature = user.origin,
                        };
                        StoreUser();
                    }
                }
                catch (Exception)
                {
                    return(CredentialVerificationResult.WrongCredential);
                }
            }

            return(CredentialVerificationResult.Success);
        }
Example #6
0
        public void IsEmpty_LoginAndOrPasswordNotSet_ReturnsTrue()
        {
            var credential = new NetworkCredential();

            Assert.IsTrue(credential.IsEmpty());
        }
Example #7
0
        public void IsEmpty_LoginAndOrPasswordAreSet_ReturnsFalse(string login, string password)
        {
            var credential = new NetworkCredential(login, password);

            Assert.IsFalse(credential.IsEmpty());
        }