public void LoginHPIDTest_ReturnsFault()
        {
            SettingRepository.SetSettingsRepositoryData(new List <AdmSettings>()
            {
                new AdmSettings {
                    ParamName = "HPIDEnabled", StringValue = "true"
                }
            });

            RESTAPIProfileController api = new RESTAPIProfileController();
            RESTAPILoginCredentials  req = new RESTAPILoginCredentials()
            {
                UserName = "",
                Password = "",
                CallerId = "",
                Platform = "",
                Locale   = ""
            };
            GetProfileResponse profileRes = new GetProfileResponse()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("Profile", "", "")
                }
            };

            hpidMock.Setup(x => x.GetCustomerProfileByTestLogin(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <APIMethods>())).Returns(profileRes);
            RESTAPILoginResponse response = api.Login(req);

            Assert.IsTrue(response.ErrorList.Count == 1);
            Assert.AreEqual(response.ErrorList.First().Origin, "Profile");
        }
        public void LoginTest_SessionTimeOutResponse()
        {
            DateTime loginDate = new DateTime(2019, 11, 28, 05, 06, 00);

            RESTAPIProfileController api = new RESTAPIProfileController();
            RESTAPILoginCredentials  req = new RESTAPILoginCredentials()
            {
                UserName = "",
                Password = "",
                CallerId = "",
                Platform = "",
                Locale   = "pl-PL"
            };
            GetProfileResponse profileRes = new GetProfileResponse()
            {
                Credentials = new AccessCredentials()
                {
                    UserID = 1000, SessionToken = "sessionToken", CallerId = "callerId"
                },
                CustomerProfileObject = new CustomerProfile()
                {
                    ActiveHealth = true
                },
                LoginDate = loginDate
            };

            hpidMock.Setup(x => x.GetCustomerProfileByTestLogin(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <APIMethods>())).Returns(profileRes);

            //customerMock.Setup(x => x.GetCustomerProfile(It.IsAny<UserAuthenticationInterchange>(), It.IsAny<bool>())).Returns(profileRes);

            RESTAPILoginResponse response = api.Login(req);

            Assert.IsNotNull(response.TimeOut);
            Assert.AreEqual("2019-11-28T06:06:00Z", response.TimeOut);
        }
        public void LoginTest_ReturnsFault()
        {
            RESTAPIProfileController api = new RESTAPIProfileController();
            RESTAPILoginCredentials  req = new RESTAPILoginCredentials()
            {
                UserName = "",
                Password = "",
                CallerId = "",
                Platform = "",
                Locale   = ""
            };
            GetProfileResponse profileRes = new GetProfileResponse()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("Profile", "", "")
                }
            };

            //customerMock.Setup(x => x.GetCustomerProfile(It.IsAny<UserAuthenticationInterchange>(), It.IsAny<bool>())).Returns(profileRes);
            hpidMock.Setup(x => x.GetCustomerProfileByTestLogin(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <APIMethods>())).Returns(profileRes);

            RESTAPILoginResponse response = api.Login(req);

            Assert.IsTrue(response.ErrorList.Count == 1);
            Assert.AreEqual(response.ErrorList.First().Origin, "Profile");
        }
        public void LoginTest_ReturnSsessionToken()
        {
            RESTAPIProfileController api = new RESTAPIProfileController();
            RESTAPILoginCredentials  req = new RESTAPILoginCredentials()
            {
                UserName = "",
                Password = "",
                CallerId = "",
                Platform = "",
                Locale   = "en-US"
            };
            GetProfileResponse profileRes = new GetProfileResponse()
            {
                Credentials = new AccessCredentials()
                {
                    UserID = 1000, SessionToken = "sessionToken", CallerId = "callerId"
                },
                CustomerProfileObject = new CustomerProfile()
                {
                    ActiveHealth = true
                }
            };

            hpidMock.Setup(x => x.GetCustomerProfileByTestLogin(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <APIMethods>())).Returns(profileRes);

            //customerMock.Setup(x => x.GetCustomerProfile(It.IsAny<UserAuthenticationInterchange>(), It.IsAny<bool>())).Returns(profileRes);
            RESTAPILoginResponse response = api.Login(req);

            Assert.IsTrue(response.SessionToken.Equals("sessionToken"));
        }
        public void LoginTest_ReturnsValidCredentials_CallRegisterMobile()
        {
            RESTAPIProfileController api = new RESTAPIProfileController();
            RESTAPILoginCredentials  req = new RESTAPILoginCredentials()
            {
                UserName    = "",
                Password    = "",
                CallerId    = "callerId",
                Platform    = "PLATFORM",
                DeviceToken = "deviceToken"
            };
            GetProfileResponse profileRes = new GetProfileResponse()
            {
                Credentials = new AccessCredentials()
                {
                    UserID = 1000, SessionToken = "sessionToken"
                },
                CustomerProfileObject = new CustomerProfile()
                {
                    ActiveHealth = true
                }
            };

            hpidMock.Setup(x => x.GetCustomerProfileByTestLogin(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <APIMethods>())).Returns(profileRes);

            //customerMock.Setup(x => x.GetCustomerProfile(It.IsAny<UserAuthenticationInterchange>(), It.IsAny<bool>())).Returns(profileRes);

            RESTAPILoginResponse response = api.Login(req);

            Assert.IsTrue(response.ErrorList.Count == 0);
        }
        public void AuthenticateTest_MobileDeviceError()
        {
            GetProfileResponse response = new GetProfileResponse()
            {
                Credentials           = new Credentials.AccessCredentials(),
                CustomerProfileObject = new CustomerProfile()
            };

            authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response);

            ResponseBase res = new ResponseBase()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("", "", "")
                }
            };

            RESTAPIAuthCredentials req = new RESTAPIAuthCredentials()
            {
                DeviceToken = "SDILASNP",
                Platform    = "platform"
            };
            RESTAPILoginResponse expectedResponse = acontroler.Authenticate(req);

            Assert.IsTrue(expectedResponse.ErrorList.Count == 0);

            authMock.Verify(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>()), Times.Once);
        }
        public void AuthenticateTest_EmptyOrNullDevicetoken()
        {
            GetProfileResponse response = new GetProfileResponse()
            {
                Credentials           = new Credentials.AccessCredentials(),
                CustomerProfileObject = new CustomerProfile()
                {
                    ActiveHealth = true
                }
            };

            authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response);

            ResponseBase res = new ResponseBase();

            RESTAPIAuthCredentials req = new RESTAPIAuthCredentials()
            {
                Platform = "ios"
            };

            RESTAPILoginResponse expectedResponse = acontroler.Authenticate(req);

            Assert.IsTrue(expectedResponse.ErrorList.Count == 1);
            Assert.IsNotNull(expectedResponse.ErrorList.Where(x => x.ReturnCode == Faults.EmptyOrNullDevicetoken.ReturnCode));
        }
        public RESTAPILoginResponse Login(RESTAPILoginCredentials req)
        {
            GetProfileResponse            response           = new GetProfileResponse();
            UserAuthenticationInterchange hppAuthInterchange = new UserAuthenticationInterchange()
            {
                UserName          = req.UserName,
                Password          = req.Password,
                CallerId          = req.CallerId,
                Token             = null,
                LanguageCode      = req.LanguageCode,
                CountryCode       = req.CountryCode,
                UseCaseGroup      = req.ClientViewer,
                Platform          = req.Platform,
                ClientApplication = UserAuthenticationInterchange.MapPlatformToClientApplication(req.Platform)
            };

            if (SettingRepository.Get <bool>("TESTLoginEnabled", true))
            {
                response = HPIDUtils.GetCustomerProfileByTestLogin(hppAuthInterchange, false, APIMethods.None);
            }
            else
            {
                if (SettingRepository.Get <bool>("HPIDEnabled", true))
                {
                    response = HPIDUtils.GetCustomerProfileByLogin(hppAuthInterchange, false, APIMethods.None);
                }
                //else
                //{
                //    response = customerUtils.GetCustomerProfile(hppAuthInterchange, false);
                //}
            }

            RESTAPILoginResponse loginResponse = new RESTAPILoginResponse();

            if (response.ErrorList.Count == 0)
            {
                loginResponse.UserID       = response.Credentials.UserID;
                loginResponse.SessionToken = response.Credentials.SessionToken;
                loginResponse.CallerId     = response.Credentials.CallerId;

                loginResponse.Roles        = response.Credentials.Roles;
                loginResponse.Locale       = response.CustomerProfileObject.Locale;
                loginResponse.FirstName    = response.CustomerProfileObject.FirstName;
                loginResponse.LastName     = response.CustomerProfileObject.LastName;
                loginResponse.Emailaddress = response.CustomerProfileObject.EmailAddress;

                if (response.LoginDate.HasValue)
                {
                    //loginResponse.TimeOut = DateTimeFormatUtils.GetIso8601String(response.LoginDate.Value.AddMinutes(SettingRepository.Get<int>("MaxSessionTimeMinutes", 2)));
                }
                loginResponse.Status = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Success);
            }
            else
            {
                loginResponse.ErrorList = response.ErrorList;
                loginResponse.Status    = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Failure);
            }
            return(loginResponse);
        }
예제 #9
0
        public RESTAPILoginResponse Authenticate(RESTAPIAuthCredentials req)
        {
            UserAuthenticationInterchange hppAuthInterchange = new UserAuthenticationInterchange()
            {
                CallerId     = req.CallerId,
                LanguageCode = req.LanguageCode,
                CountryCode  = req.CountryCode,
                Platform     = req.Platform,
                ClientId     = req.ClientId,
                UserId       = req.UserId
            };

            SetClientAppInfo(req.Platform, hppAuthInterchange);

            GetProfileResponse response = new GetProfileResponse();

            if (SettingRepository.Get <bool>("TESTLoginEnabled", true))
            {
                //response = HPIDUtils.GetCustomerProfileByTestLogin(hppAuthInterchange, false, APIMethods.None);
                response = HPIDUtils.GetCustomerProfileByDefaultUserLogin(response, hppAuthInterchange, false, APIMethods.None);
            }
            else
            {
                response = AuthUtils.GetCustomerProfileByAuthentication(hppAuthInterchange, false, req.AccessCode, req.RedirectUrl, APIMethods.POSTAuthenticate, req.ClientId);
            }

            RESTAPILoginResponse loginResponse = new RESTAPILoginResponse();

            if (response.ErrorList.Count == 0)
            {
                loginResponse.UserID       = response.Credentials.UserID;
                loginResponse.SessionToken = response.Credentials.SessionToken;
                loginResponse.CallerId     = response.Credentials.CallerId;
                loginResponse.Roles        = response.Credentials.Roles;
                loginResponse.Locale       = response.CustomerProfileObject.Locale;
                loginResponse.FirstName    = response.CustomerProfileObject.FirstName;
                loginResponse.LastName     = response.CustomerProfileObject.LastName;
                loginResponse.Emailaddress = response.CustomerProfileObject.EmailAddress;
                loginResponse.Status       = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Success);

                //if (string.IsNullOrEmpty(req.DeviceToken))
                //{
                //    loginResponse.ErrorList.Add(Faults.EmptyOrNullDevicetoken);
                //}
                if (response.LoginDate.HasValue)
                {
                    //loginResponse.TimeOut = DateTimeFormatUtils.GetIso8601String(response.LoginDate.Value.AddMinutes(SettingRepository.Get<int>("MaxSessionTimeMinutes", 60)));
                }
            }
            else
            {
                loginResponse.Status    = Enum.GetName(typeof(ResponseStatusType), ResponseStatusType.Failure);
                loginResponse.ErrorList = response.ErrorList;
            }

            return(loginResponse);
        }
        public void AuthenticateTest_NoCustomerProfileFound()
        {
            GetProfileResponse response = new GetProfileResponse()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("", "", "")
                }
            };

            authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response);

            RESTAPILoginResponse expectedResponse = acontroler.Authenticate(new RESTAPIAuthCredentials());

            Assert.IsTrue(expectedResponse.ErrorList.Count == 1);

            authMock.Verify(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>()), Times.Once);
        }
        public void AuthenticateTest_PassingClientId()
        {
            GetProfileResponse response = new GetProfileResponse()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("", "", "")
                }
            };

            authMock.Setup(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.IsAny <string>())).Returns(response);

            RESTAPIAuthCredentials request = new RESTAPIAuthCredentials();
            string clientId = "theClientId";

            request.ClientId = clientId;

            RESTAPILoginResponse expectedResponse = acontroler.Authenticate(request);

            authMock.Verify(x => x.GetCustomerProfileByAuthentication(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <APIMethods>(), It.Is <string>(s => s == clientId)), Times.Once);
        }
        public void LoginTest_ReturnsValidCredentials_MobileFault()
        {
            RESTAPIProfileController api = new RESTAPIProfileController();
            RESTAPILoginCredentials  req = new RESTAPILoginCredentials()
            {
                UserName = "",
                Password = "",
                CallerId = "",
                Platform = ""
            };
            GetProfileResponse profileRes = new GetProfileResponse()
            {
                Credentials = new AccessCredentials()
                {
                    UserID = 1000, SessionToken = "sessionToken", CallerId = "CallerId"
                },
                CustomerProfileObject = new CustomerProfile()
                {
                    ActiveHealth = true
                }
            };

            hpidMock.Setup(x => x.GetCustomerProfileByTestLogin(It.IsAny <UserAuthenticationInterchange>(), It.IsAny <bool>(), It.IsAny <APIMethods>())).Returns(profileRes);

            // customerMock.Setup(x => x.GetCustomerProfile(It.IsAny<UserAuthenticationInterchange>(), It.IsAny<bool>())).Returns(profileRes);
            ResponseBase mobileResponse = new ResponseBase()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("", "", "")
                }
            };
            RESTAPILoginResponse response = api.Login(req);

            Assert.IsTrue(response.ErrorList.Count == 0);
            Assert.IsTrue(response.UserID == 1000);
            Assert.AreEqual(response.SessionToken, "sessionToken");
            Assert.AreEqual(response.CallerId, "CallerId");
        }