public void Userods_CheckUserAndPassword_LockoutAfterUserHasLoggedInButPasswordIsNotCorrectAfter5Attempts() { //First, setup the test scenario. long group1 = UserGroupT.CreateUserGroup("usergroup1"); bool isAccountLocked = false; Userod myUser = UserodT.CreateUser(MethodBase.GetCurrentMethod().Name + DateTime.Now.Ticks, "reallystrongpassword", userGroupNumbers: new List <long>() { group1 }); //Make 5 bad password attempts for (int i = 1; i < 6; i++) { ODException.SwallowAnyException(() => { Userods.CheckUserAndPassword(myUser.UserName, "passwordguess#" + i, false); }); } try { //the 6th bad attempt should kick us with a message saying that our account has been locked. Userods.CheckUserAndPassword(myUser.UserName, "passwordguess#6", false); } catch (Exception e) { if (e.Message.Contains("Account has been locked due to failed log in attempts")) { isAccountLocked = true; } } //Get our updated user from the DB. myUser = Userods.GetUserByNameNoCache(myUser.UserName); //Assert that we got to 5 failed attempts and that the account has been locked. Assert.AreEqual(5, myUser.FailedAttempts); Assert.AreEqual(true, isAccountLocked); }
public void Userods_CheckUserAndPassoword_UpdateFailedAttemptsFromOtherMethods() { //First, setup the test scenario. long group1 = UserGroupT.CreateUserGroup("usergroup1"); Userod myUser = UserodT.CreateUser(MethodBase.GetCurrentMethod().Name + DateTime.Now.Ticks, "reallystrongpassword", userGroupNumbers: new List <long>() { group1 }); Security.CurUser = myUser; Security.PasswordTyped = "passwordguess#1"; CredentialsFailedAfterLoginEvent.Fired += CredentialsFailedAfterLoginEvent_Fired1; RunTestsAgainstMiddleTier(new OpenDentBusiness.WebServices.OpenDentalServerMockIIS(user: myUser.UserName, password: myUser.Password)); //try once with the wrong password. Failed attempt should get incremented to 1. ODException.SwallowAnyException(() => { Userods.CheckUserAndPassword(myUser.UserName, "passwordguess#1", false); }); //Get our updated user from the DB. RunTestsAgainstDirectConnection(); myUser = Userods.GetUserByNameNoCache(myUser.UserName); //Assert that we only have 1 failed attempt. Assert.AreEqual(1, myUser.FailedAttempts); //now wait for another method to get called RunTestsAgainstMiddleTier(new OpenDentBusiness.WebServices.OpenDentalServerMockIIS(user: myUser.UserName, password: myUser.Password)); ODException.SwallowAnyException(() => { Computers.UpdateHeartBeat(Environment.MachineName, false); }); RunTestsAgainstDirectConnection(); //Get our updated user from the DB. myUser = Userods.GetUserByNameNoCache(myUser.UserName); //Assert that we only have 1 failed attempt. Assert.AreEqual(1, myUser.FailedAttempts); }
public void Userods_CheckUserAndPassoword_UpdateFailedAttemptsTo5() { //First, setup the test scenario. long group1 = UserGroupT.CreateUserGroup("usergroup1"); Userod myUser = UserodT.CreateUser(MethodBase.GetCurrentMethod().Name + DateTime.Now.Ticks, "reallystrongpassword", userGroupNumbers: new List <long>() { group1 }); CredentialsFailedAfterLoginEvent.Fired += CredentialsFailedAfterLoginEvent_Fired1; Security.CurUser = myUser; Security.PasswordTyped = "passwordguess#1"; RunTestsAgainstMiddleTier(); //try with 5 incorrect passwords. Failed attempt should get incremented to 5. for (int i = 1; i < 6; i++) { ODException.SwallowAnyException(() => { try { Userods.CheckUserAndPassword(myUser.UserName, "passwordguess#" + i, false); } catch (Exception e) { } }); } //Get our updated user from the DB. RunTestsAgainstDirectConnection(); myUser = Userods.GetUserByNameNoCache(myUser.UserName); //Assert that there are 5 failed attempts. Assert.AreEqual(5, myUser.FailedAttempts); }
public void OrthoCases_UpdateDatesByLinkedProc_UpdateBandingAndDebondDates() { Prefs.UpdateString(PrefName.OrthoDebondCodes, "D8070"); Userod user = UserodT.CreateUser(); Security.CurUser = user; Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure bandingProc = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.C, "", 0); Procedure debondProc = ProcedureT.CreateProcedure(pat, "D8070", ProcStat.C, "", 0, procDate: DateTime.Today.AddDays(2)); long orthoCaseNum = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc); OrthoProcLinks.LinkProcForActiveOrthoCase(debondProc); OrthoProcLink bandingProcLink = OrthoProcLinks.GetByType(orthoCaseNum, OrthoProcType.Banding); OrthoProcLink debondProcLink = OrthoProcLinks.GetByType(orthoCaseNum, OrthoProcType.Debond); OrthoCase orthoCase = OrthoCases.GetOne(orthoCaseNum); Assert.AreEqual(orthoCase.BandingDate, DateTime.Today); bandingProc.ProcDate = DateTime.Today.AddDays(1); OrthoCases.UpdateDatesByLinkedProc(bandingProcLink, bandingProc); orthoCase = OrthoCases.GetOne(orthoCaseNum); Assert.AreEqual(orthoCase.BandingDate, DateTime.Today.AddDays(1)); Assert.AreEqual(orthoCase.DebondDate, DateTime.Today.AddDays(2)); debondProc.ProcDate = DateTime.Today.AddDays(3); OrthoCases.UpdateDatesByLinkedProc(debondProcLink, debondProc); orthoCase = OrthoCases.GetOne(orthoCaseNum); Assert.AreEqual(orthoCase.BandingDate, DateTime.Today.AddDays(1)); Assert.AreEqual(orthoCase.DebondDate, DateTime.Today.AddDays(3)); }
public void OrthoCases_Delete_DeleteOrthoCaseAndAssociatedObjects() { Prefs.UpdateString(PrefName.OrthoBandingCodes, "D8080"); Prefs.UpdateString(PrefName.OrthoDebondCodes, "D8070"); Prefs.UpdateString(PrefName.OrthoVisitCodes, "D8060"); Userod user = UserodT.CreateUser(); Security.CurUser = user; Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure bandingProc = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.C, "", 0); Procedure visitProc = ProcedureT.CreateProcedure(pat, "D8060", ProcStat.C, "", 0); Procedure debondProc = ProcedureT.CreateProcedure(pat, "D8070", ProcStat.C, "", 0); long orthoCaseNum = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc); OrthoProcLinks.LinkProcForActiveOrthoCase(visitProc); OrthoProcLinks.LinkProcForActiveOrthoCase(debondProc); OrthoCase orthoCase = OrthoCases.GetOne(orthoCaseNum); OrthoPlanLink schedulePlanLink = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum, OrthoPlanLinkType.OrthoSchedule); long orthoscheduleNum = schedulePlanLink.FKey; OrthoSchedule orthoSchedule = OrthoSchedules.GetOne(schedulePlanLink.FKey); List <OrthoProcLink> listAllProcLinks = OrthoProcLinks.GetManyByOrthoCase(orthoCaseNum); OrthoCases.Delete(orthoCase.OrthoCaseNum, orthoSchedule, schedulePlanLink, listAllProcLinks); orthoCase = OrthoCases.GetOne(orthoCaseNum); schedulePlanLink = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum, OrthoPlanLinkType.OrthoSchedule); orthoSchedule = OrthoSchedules.GetOne(orthoscheduleNum); listAllProcLinks = OrthoProcLinks.GetManyByOrthoCase(orthoCaseNum); Assert.AreEqual(orthoCase, null); Assert.AreEqual(schedulePlanLink, null); Assert.AreEqual(orthoSchedule, null); Assert.AreEqual(listAllProcLinks.Count, 0); }
public static void CreateUnitTestUser() { if (Userods.GetUserByName(UnitTestUserName, false) == null) { UserodT.CreateUser(UnitTestUserName, UnitTestPassword, new List <long> { 1 }); } }
private void SetCurrentUserWOCommandQueryPerm(string userGroupName) { long group1 = UserGroupT.CreateUserGroup(userGroupName); Userod userWOCommandPerm = UserodT.CreateUser(MethodBase.GetCurrentMethod().Name + DateTime.Now.Ticks, userGroupNumbers: new List <long>() { group1 }); Security.CurUser = userWOCommandPerm; }
public void OrthoCases_Activate_ActivateAnOrthoCaseAndDeactivateOthersForPat() { Userod user = UserodT.CreateUser(); Security.CurUser = user; Patient pat = PatientT.CreatePatient(MethodBase.GetCurrentMethod().Name); Procedure bandingProc1 = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.TP, "", 0); Procedure bandingProc2 = ProcedureT.CreateProcedure(pat, "D8080", ProcStat.TP, "", 0); long orthoCaseNum1 = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc1); long orthoCaseNum2 = OrthoCaseT.InsertForFormOrthoCase(pat.PatNum, 2000, 1200, 0, 800, DateTime.Today, false, DateTime.Today.AddMonths(12), 1000, 400, 60, bandingProc2); OrthoCase orthoCase2 = OrthoCases.GetOne(orthoCaseNum2); OrthoPlanLink schedulePlanLink2 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum2, OrthoPlanLinkType.OrthoSchedule); OrthoSchedule orthoSchedule2 = OrthoSchedules.GetOne(schedulePlanLink2.FKey); //Set one OrthoCase inactive. Now orthoCase1 is active and orthoCase2 is inactive. OrthoCases.SetActiveState(orthoCase2, schedulePlanLink2, orthoSchedule2, false); OrthoCase orthoCase1 = OrthoCases.GetOne(orthoCaseNum1); OrthoPlanLink schedulePlanLink1 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum1, OrthoPlanLinkType.OrthoSchedule); OrthoSchedule orthoSchedule1 = OrthoSchedules.GetOne(schedulePlanLink1.FKey); orthoCase2 = OrthoCases.GetOne(orthoCaseNum2); schedulePlanLink2 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum2, OrthoPlanLinkType.OrthoSchedule); orthoSchedule2 = OrthoSchedules.GetOne(schedulePlanLink2.FKey); Assert.AreEqual(orthoCase1.IsActive, true); Assert.AreEqual(schedulePlanLink1.IsActive, true); Assert.AreEqual(orthoSchedule1.IsActive, true); Assert.AreEqual(orthoCase2.IsActive, false); Assert.AreEqual(schedulePlanLink2.IsActive, false); Assert.AreEqual(orthoSchedule2.IsActive, false); //Active orthoCase2 which should inactivate orthoCase1 OrthoCases.Activate(orthoCase2, pat.PatNum); orthoCase1 = OrthoCases.GetOne(orthoCaseNum1); schedulePlanLink1 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum1, OrthoPlanLinkType.OrthoSchedule); orthoSchedule1 = OrthoSchedules.GetOne(schedulePlanLink1.FKey); orthoCase2 = OrthoCases.GetOne(orthoCaseNum2); schedulePlanLink2 = OrthoPlanLinks.GetOneForOrthoCaseByType(orthoCaseNum2, OrthoPlanLinkType.OrthoSchedule); orthoSchedule2 = OrthoSchedules.GetOne(schedulePlanLink2.FKey); Assert.AreEqual(orthoCase1.IsActive, false); Assert.AreEqual(schedulePlanLink1.IsActive, false); Assert.AreEqual(orthoSchedule1.IsActive, false); Assert.AreEqual(orthoCase2.IsActive, true); Assert.AreEqual(schedulePlanLink2.IsActive, true); Assert.AreEqual(orthoSchedule2.IsActive, true); }
public static void SetupClass(TestContext testContext) { _defRegionN = DefT.CreateDefinition(DefCat.Regions, "RegionN", "RegionN"); _defRegionS = DefT.CreateDefinition(DefCat.Regions, "RegionS", "RegionS"); _clinicN = ClinicT.CreateClinic("ClinicN", regionDef: _defRegionN); _clinicNW = ClinicT.CreateClinic("ClinicNW", regionDef: _defRegionN); _clinicS = ClinicT.CreateClinic("ClinicS", regionDef: _defRegionS); _patN = PatientT.CreatePatient("Tasks", clinicNum: _clinicN.ClinicNum, lName: _clinicN.Description, fName: "Patient"); _patS = PatientT.CreatePatient("Tasks", clinicNum: _clinicS.ClinicNum, lName: _clinicS.Description, fName: "Patient"); _userA = UserodT.CreateUser(userName: "******", clinicNum: _clinicN.ClinicNum, isClinicIsRestricted: false); _userNW = UserodT.CreateUser(userName: "******", clinicNum: _clinicNW.ClinicNum, isClinicIsRestricted: true); Userods.RefreshCache(); List <UserClinic> listUserClinics = new List <UserClinic>() { new UserClinic(_clinicNW.ClinicNum, _userNW.UserNum) }; if (UserClinics.Sync(listUserClinics, _userNW.UserNum)) //Either syncs new list, or clears old list if no longer restricted. { UserClinics.RefreshCache(); } }
public void Userods_CheckUserAndPassword_IncreaseFailedAttemptsAfterUserHasLoggedInButPasswordIsNotCorrect() { //First, setup the test scenario. //This test is intended to be tested on middle tier. long group1 = UserGroupT.CreateUserGroup("usergroup1"); Userod myUser = UserodT.CreateUser(MethodBase.GetCurrentMethod().Name + DateTime.Now.Ticks, "reallystrongpassword", userGroupNumbers: new List <long>() { group1 }); RunTestsAgainstMiddleTier(new OpenDentBusiness.WebServices.OpenDentalServerMockIIS(user: myUser.UserName, password: myUser.Password)); Security.CurUser = myUser; Security.PasswordTyped = "passwordguess#1"; CredentialsFailedAfterLoginEvent.Fired += CredentialsFailedAfterLoginEvent_Fired1; //make a single bad password attempt. ODException.SwallowAnyException(() => { Userods.CheckUserAndPassword(myUser.UserName, "passwordguess#1", false); }); //Get our user from the DB RunTestsAgainstDirectConnection(); myUser = Userods.GetUserByNameNoCache(myUser.UserName); //Asssert that the failed attempt got incremented correctly. Assert.AreEqual(1, myUser.FailedAttempts); }
public void AlertItems_CreateAlertsForNewWebmail() { //Test Sections: //Create 5 users, part of 2 providers. //Test adding an email for each provider, then clear alerts table. //Test adding 4 emails for each provider //Test adding 3 additional emails for 1 provider //Test marking 2 emails as read for 1 provider //Test marking all emails as read for 1 provider EmailMessageT.ClearEmailMessageTable(); //Clear out the emailmessage table List <Userod> listTestUsers = new List <Userod>(); //Create or reuse 5 users, and set their provnum to 1 or 2. There'll be 3 provnum=1 and 2 provnum=2 //In queries always filter by usernum because there may be users left over from other/old tests. for (int i = 0; i < 5; i++) { Userod user = UserodT.CreateUser(); user.ProvNum = i % 2 + 1; listTestUsers.Add(user); Userods.Update(user); } listTestUsers = listTestUsers.Distinct().ToList(); long examplePatnum = 2; //Patnum can be anything, needed for webmail. //Create one email for each provider. foreach (long provnum in listTestUsers.Select(x => x.ProvNum).Distinct()) { EmailMessageT.CreateWebMail(provnum, examplePatnum); } AlertItems_CreateAlertsForWebmailMethodCall(); //Count the total # of alertitem entries, not what the description is. string alertCount = DataCore.GetScalar("SELECT COUNT(*) FROM alertitem WHERE UserNum IN (" + string.Join(",", listTestUsers.Select(x => POut.Long(x.UserNum))) + ") AND Type=" + POut.Int((int)AlertType.WebMailRecieved)); Assert.AreEqual("5", alertCount); // //Clear out ALERT table and add some new emails AlertItemT.ClearAlertItemTable(); foreach (long provnum in listTestUsers.Select(x => x.ProvNum).Distinct()) { EmailMessageT.CreateWebMail(provnum, examplePatnum); EmailMessageT.CreateWebMail(provnum, examplePatnum); EmailMessageT.CreateWebMail(provnum, examplePatnum); EmailMessageT.CreateWebMail(provnum, examplePatnum); } //This section tests adding more unread emails, and changing the description of the alertitem Userod selectedUser = listTestUsers.First(); AlertItems_CreateAlertsForWebmailMethodCall(); alertCount = DataCore.GetScalar("SELECT Description FROM alertitem WHERE Type=" + POut.Int((int)AlertType.WebMailRecieved) + " AND UserNum=" + selectedUser.UserNum); Assert.AreEqual("5", alertCount); // //Add 3 more unread emails. EmailMessageT.CreateWebMail(selectedUser.ProvNum, examplePatnum); EmailMessageT.CreateWebMail(selectedUser.ProvNum, examplePatnum); EmailMessageT.CreateWebMail(selectedUser.ProvNum, examplePatnum); AlertItems_CreateAlertsForWebmailMethodCall(); alertCount = DataCore.GetScalar("SELECT Description FROM alertitem WHERE Type=" + POut.Int((int)AlertType.WebMailRecieved) + " AND UserNum=" + selectedUser.UserNum); Assert.AreEqual("8", alertCount); // //Mark 2 of the emails as read, to decrease the amount of unread emails string command = "UPDATE emailmessage SET SentOrReceived=" + POut.Int((int)EmailSentOrReceived.WebMailRecdRead) + " WHERE SentOrReceived=" + POut.Int((int)EmailSentOrReceived.WebMailReceived) + " AND ProvNumWebMail=" + POut.Long(selectedUser.ProvNum) + " LIMIT 2"; DataCore.NonQ(command); AlertItems_CreateAlertsForWebmailMethodCall(); alertCount = DataCore.GetScalar("SELECT Description FROM alertitem WHERE Type=" + POut.Int((int)AlertType.WebMailRecieved) + " AND UserNum=" + selectedUser.UserNum); Assert.AreEqual("6", alertCount); // //Now we mark all of this user's emails as read, as if that user has read all of their webmail. command = "UPDATE emailmessage SET SentOrReceived=" + POut.Int((int)EmailSentOrReceived.WebMailRecdRead) + " WHERE SentOrReceived=" + POut.Int((int)EmailSentOrReceived.WebMailReceived) + " AND ProvNumWebMail=" + POut.Long(selectedUser.ProvNum); DataCore.NonQ(command); AlertItems_CreateAlertsForWebmailMethodCall(); alertCount = DataCore.GetScalar("SELECT COUNT(*) FROM alertitem WHERE Type=" + POut.Int((int)AlertType.WebMailRecieved) + " AND UserNum=" + selectedUser.UserNum); Assert.AreEqual("0", alertCount); }
public void AlertItems_GetUniqueAlerts_Addclinic() { //This test will check the funcionality of alert items which are marked to show in all clinics(AlertItem.ClinicNum==-1). //Expected behaviour is that a user subscribed to all alert categories, and all clinics(AlertSub.ClinicNum==-1), //will see the alert no matter which clinic they are in. //In addition, when a new clinic is added, the user will be able to see alerts in that new clinic without the need to reenter //FormUserEdit and select "All" again under clinics for alert subscriptions. //Clear AlertSub table. AlertSubT.ClearAlertSubTable(); //Create Users Userod userAdmin = UserodT.CreateUser(); Userod userNormal = UserodT.CreateUser(); //Create Clinics List <Clinic> listClinics = new List <Clinic>(); for (int i = 0; i < 2; i++) { listClinics.Add(ClinicT.CreateClinic()); } //Create AlertItems //First alert Item is an alert item for all clinics(ClinicNum==-1). CreateAlertItem(true); //Second AlertItem is an AlertItem for HQ(ClinicNum==0). CreateAlertItem(false); List <AlertCategory> listAlertCats = AlertCategories.GetDeepCopy(); List <AlertSub> listAlertSubOld = new List <AlertSub>(); List <AlertSub> listAlertSubNew = new List <AlertSub>(); foreach (AlertCategory alertCat in listAlertCats) { AlertSub alSub = new AlertSub(userAdmin.UserNum, -1, alertCat.AlertCategoryNum); listAlertSubNew.Add(alSub); } AlertSubs.Sync(listAlertSubNew, listAlertSubOld); //Check number of alerts which will display in headquarters clinic. //Call CheckUniqueAlerts for user subscribed to all alert categories List <List <AlertItem> > listUniqueAlertsAll = AlertItems.GetUniqueAlerts(userAdmin.UserNum, 0); List <List <AlertItem> > listUniqueAlertsOne = AlertItems.GetUniqueAlerts(userNormal.UserNum, 0); //Assert lists are correct //UserAdmin should see two alerts, one for the generic headquarters alert and one for the eConnector all clinics alert. Assert.AreEqual(2, listUniqueAlertsAll.Count()); //UserNormal is not subscribed to any clinics or alert categories and should not see any alerts. Assert.AreEqual(0, listUniqueAlertsOne.Count()); //Add clinic listClinics.Add(ClinicT.CreateClinic()); //Check that alert for all clinics is included for userAdmin(subscribed to all clinics) listUniqueAlertsAll = AlertItems.GetUniqueAlerts(userAdmin.UserNum, listClinics.LastOrDefault().ClinicNum); Assert.AreEqual(1, listUniqueAlertsAll.Count()); //Check new clinic for user who is not subscribed to all alerts. listUniqueAlertsOne = AlertItems.GetUniqueAlerts(userNormal.UserNum, listClinics.LastOrDefault().ClinicNum); Assert.AreEqual(0, listUniqueAlertsOne.Count()); //Add new alert for new clinic only. CreateAlertItem(false, listClinics.LastOrDefault().ClinicNum); //Check that userAdmin sees new alert item in new clinic. Should have 2, one all clinic econnector alert and the new clinic specific alert. listUniqueAlertsAll = AlertItems.GetUniqueAlerts(userAdmin.UserNum, listClinics.LastOrDefault().ClinicNum); Assert.AreEqual(2, listUniqueAlertsAll.Count()); //Check that userNormal sees no alerts in new clinic, as they are not subscribed to any alert categories, nor clinics. listUniqueAlertsOne = AlertItems.GetUniqueAlerts(userNormal.UserNum, listClinics.LastOrDefault().ClinicNum); Assert.AreEqual(0, listUniqueAlertsOne.Count()); }