public TM_FileStorage(bool loadData) { Server = new TM_Server(); TMXmlDatabase = new TM_Xml_Database(); UserData = new TM_UserData(); GuidanceExplorers_Paths = new Dictionary <guidanceExplorer, string>(); GuidanceItems_FileMappings = new Dictionary <Guid, string>(); if (loadData) { Current = this; this.set_WebRoot() // defines where the web root will exist .set_Path_XmlDatabase() // the WebRoot is used to calculate the root of the XML Database .tmServer_Load() // the TM_Server is loaded from the root of the Path_XmlDatabase .set_Path_UserData() // the Path_UserData are Path_SiteData are both .set_Path_SiteData() // set based on info from TM_Server and Path_XmlDatabase .tmConfig_Load() // tm TM_Config is loaded from the root of the UserData .set_Path_XmlLibraries() // the Path_XmlLibraries is set based on info from TM_Config and Path_XmlDatabase .load_UserData() // after all is configured we can load the users .load_Libraries(); // and libraries this.hook_Events_TM_UserData() // hook events to FileStorage handlers so that actions on TeamMentor.Database .hook_Events_TM_Xml_Database(); // and TeamMentor.UserData are saved or deleted from disk } }
public void TM_UserData_Ctor() { Assert.IsFalse(userData.UsingFileStorage); Assert.AreEqual(TM_UserData.Current, userData); Assert.IsNull(TM_UserData.GitPushThread); var userData2 = new TM_UserData(true); Assert.IsNull(userData2.Path_UserData); Assert.IsNull(userData2.Path_UserData_Base); Assert.IsNull(userData2.Git_UserData); Assert.IsNull(userData2.NGit); Assert.IsFalse(userData2.AutoGitCommit); //set by ResetData Assert.IsTrue(userData2.UsingFileStorage); Assert.AreEqual(userData2.FirstScriptToInvoke, TMConsts.USERDATA_FIRST_SCRIPT_TO_INVOKE); Assert.AreEqual(userData2.Path_WebRootFiles, TMConsts.USERDATA_PATH_WEB_ROOT_FILES); Assert.AreEqual(userData2.AutoGitCommit, TMConfig.Current.Git.AutoCommit_UserData); Assert.IsEmpty(userData2.TMUsers); Assert.IsNotNull(userData2.SecretData); userData = new TM_UserData(); // restore userData to the version that doesn't use the FileStorage Assert.IsFalse(userData.UsingFileStorage); Assert.AreEqual(TM_UserData.Current, userData); Assert.AreNotEqual(TM_UserData.Current, userData2); }
public void setup() { TM_FileStorage.Current = null; tmUserData = new TM_UserData(); Assert.NotNull(tmUserData); Assert.NotNull(tmUserData.Events); }
public static List <int> createTmUsers(this TM_UserData userData, List <NewUser> newUsers) { UserRole.ManageUsers.demand(); if (newUsers.isNull()) { return(new List <int>()); } return(newUsers.Select(newUser => userData.createTmUser(newUser)).toList()); }
public static TM_UserData delete_All_Users(this TM_UserData tmUserData) { foreach (var tmUser in tmUserData.tmUsers()) { tmUser.deleteTmUser(); } Assert.IsEmpty(tmUserData.tmUsers()); return(tmUserData); }
public void setup() { UserGroup.Admin.assert(); tmDatabase = new TM_Xml_Database(); tmUserData = new TM_UserData(); Assert.NotNull(tmDatabase); Assert.NotNull(tmDatabase.Events); }
public TM_UserData_InMemory() { userData = new TM_UserData(); 1.set_DEFAULT_PBKDF2_INTERACTIONS(); // improve performance of tests that create users SendEmails.Disable_EmailEngine = true; // Disable Email engine by default // check the TM_UserData Assert.IsEmpty(userData.validSessions(), "There should be no sessions"); Assert.IsEmpty(userData.TMUsers, "There should be no users"); }
public void setDatabase() { UserGroup.Admin.assert(); tmXmlDatabase = new TM_Xml_Database(); tmXmlDatabase.setup(); tmUserData = new TM_UserData(); tmUserData.createDefaultAdminUser(); UserGroup.None.assert(); }
public void setUp() { //create temp repo with no Admin user userData = new TM_UserData(true) { Path_UserData = "nonGitRepo".tempDir() }; userData.SetUp(); nGit = userData.NGit; Assert.AreEqual(1, nGit.commits().size(), "there should be one commit of the TMSecretData.config file"); }
public void setUp() { //create temp repo with no Admin user userData = new TM_UserData(true) { Path_UserData = "nonGitRepo".tempDir() }; userData.SetUp(); nGit = userData.NGit; Assert.AreEqual(2, nGit.commits().size(), "there should be two commits here"); }
public static int createDefaultAdminUser(this TM_UserData userData) { try { //var tmServer = userData.tmServer(); if (userData.isNull()) { return(-1); } //if(userData.tmServer().Users_Create_Default_Admin.isFalse()) // return -1; var tmConfig = TMConfig.Current; lock (tmConfig) { var defaultAdminUser_Name = tmConfig.TMSecurity.Default_AdminUserName; var defaultAdminUser_Pwd = tmConfig.TMSecurity.Default_AdminPassword; var defaultAdminUser_Email = tmConfig.TMSecurity.Default_AdminEmail; var adminUser = userData.tmUser(defaultAdminUser_Name); if (adminUser.notNull()) { if (adminUser.SecretData.PasswordHash.notValid() || tmConfig.OnInstallation.ForceDefaultAdminPassword) { "[createDefaultAdminUser] reseting password since passwordHash was not valid and ForceDefaultAdminPassword was set".error(); adminUser.SecretData.PasswordHash = adminUser.createPasswordHash(defaultAdminUser_Pwd); adminUser.event_User_Updated(); //adminUser.saveTmUser(); } if (adminUser.GroupID != (int)UserGroup.Admin) { "[createDefaultAdminUser] admin user was not admin (changed to admin)".error(); adminUser.GroupID = (int)UserGroup.Admin; adminUser.event_User_Updated(); //adminUser.saveTmUser(); } return(adminUser.UserID); } "[createDefaultAdminUser] admin user didn't exist (creating it)".debug(); var userId = userData.newUser(defaultAdminUser_Name, defaultAdminUser_Pwd, defaultAdminUser_Email, 1); adminUser = userId.tmUser(); adminUser.AccountStatus.ExpirationDate = DateTime.Now.AddYears(10); // default to setting the expiry value to 10 years in the future adminUser.event_User_Updated(); //adminUser.saveTmUser(); return(userId); } } catch (Exception ex) { ex.log("[TM_UserData][createDefaultAdminUser]"); return(-1); } }
public static int newUser(this TM_UserData userData, string username, string password, string email, string firstname, string lastname, string note, string title, string company, string country, string state, List <UserTag> userTags, int groupId) { if (userData.isNull()) { return(-1); } var userId = Math.Abs(Guid.NewGuid().hash()); "Creating new user: {0} with id {1}".debug(username, userId); if (groupId < 1) //set default user type { groupId = 2; //by default new users are of type 2 (i.e. Reader) } else { UserRole.ManageUsers.demand(); // only users with UserRole.ManageUsers should be able to create non-default users } var tmUser = new TMUser { UserID = userId, UserName = username, FirstName = firstname, LastName = lastname, Company = (company), Country = country, State = state, GroupID = groupId, Title = title, EMail = email ?? "", UserTags = userTags }; var tmConfig = TMConfig.Current; tmUser.AccountStatus.UserEnabled = tmConfig.newAccountsEnabled(); tmUser.AccountStatus.ExpirationDate = tmConfig.currentExpirationDate(); tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password); userData.TMUsers.Add(tmUser); if (TMConfig.Current.windowsAuthentication_Enabled().isFalse()) { SendEmails.SendNewUserEmails("New user created: {0}".format(tmUser.UserName), tmUser); } tmUser.logUserActivity("New User", ""); // this will trigger tmUser.event_User_Updated(); //tmUser.event_User_Updated(); //tmUser.saveTmUser(); //userData.triggerGitCommit(); return(userId); }
[Test] public void TM_UserData_Ctor() { TM_FileStorage.Current = null; var userData = new TM_UserData(); Assert.AreEqual(TM_UserData.Current, userData); Assert.IsEmpty(userData.TMUsers); Assert.NotNull(userData.SecretData); Assert.NotNull(userData.Events); Assert.IsNull(TM_UserData.GitPushThread); Assert.IsNull(new TMUser().user_XmlFile_Name()); }
public void SetupDatabase() { 1.set_DEFAULT_PBKDF2_INTERACTIONS(); // improve performance of tests that create users tmXmlDatabase = new TM_Xml_Database(); userData = tmXmlDatabase.UserData; tmConfig = TMConfig.Current = new TMConfig(); Assert.IsNull(tmXmlDatabase.Path_XmlDatabase, "Path_XmlDatabase"); // null since we are running TM memory (default setting) Assert.IsNull(tmXmlDatabase.Path_XmlLibraries, "Path_XmlLibraries"); // null since we are running TM memory (default setting) Assert.IsEmpty(tmXmlDatabase.Cached_GuidanceItems, "Cached_GuidanceItems"); Assert.IsEmpty(tmXmlDatabase.UserData.validSessions(), "ActiveSessions"); Assert.AreEqual(tmXmlDatabase.UserData.TMUsers.size(), 1, "TMUsers"); // there should be admin }
public TM_XmlDatabase_FileStorage() { SendEmails.Disable_EmailEngine = true; UserGroup.Admin.assert(); tmFileStorage = new TM_FileStorage(); tmXmlDatabase = tmFileStorage.TMXmlDatabase; //new TM_Xml_Database().setup(); userData = tmFileStorage.UserData; tmServer = tmFileStorage.Server; tmConfig = TMConfig.Current; CheckDatabaseSetup(); UserGroup.None.assert(); }
public static int createTmUser(this TM_UserData userData, NewUser newUser) { if (newUser.isNull()) { return(0); } // ensure the email is lowercase (will fail validation otherwise) newUser.Email = newUser.Email.lower(); //validate user against the DataContract specificed in the NewUser class if (newUser.validation_Failed()) { return(0); } if (newUser.UserTags.notEmpty()) { foreach (var userTag in newUser.UserTags) { if (userTag.validation_Failed()) { return(0); } } } // if there is a groupId provided we must check if the user has the manageUsers Priviledge if (newUser.GroupId != 0) { UserRole.ManageUsers.demand(); } // Check if there is already a user with the provided username or email if (newUser.Username.tmUser().notNull() || newUser.Email.tmUser_FromEmail().notNull()) { userData.logTBotActivity("User Creation Fail", "Username ('{0}') or Email ('{1})already existed".format(newUser.Username, newUser.Email)); return(0); } // Create user return(userData.newUser(newUser.Username, newUser.Password, newUser.Email, newUser.Firstname, newUser.Lastname, newUser.Note, newUser.Title, newUser.Company, newUser.Country, newUser.State, newUser.UserTags, newUser.GroupId)); }
public static List <int> createTmUsers(this TM_UserData userData, string batchUserData) { if (batchUserData.valid().isFalse()) { return(new List <int>()); } var newUsers = new List <NewUser>(); foreach (var line in batchUserData.fix_CRLF().split_onLines()) { var newUser = new NewUser(); //return _newUser; var items = line.split(","); newUser.Username = items.size() > 0 ? items[0].trim() : ""; newUser.Password = items.size() > 1 ? items[1].trim() : ""; newUser.Firstname = items.size() > 2 ? items[2].trim() : ""; newUser.Lastname = items.size() > 3 ? items[3].trim() : ""; newUser.GroupId = items.size() > 4 ? items[4].trim().toInt() : 0; //default values newUser.Company = "..."; newUser.Country = "..."; newUser.Email = "{0}@randomm.xyz".format(10.randomLetters()); newUser.Note = "(Batch user created)"; newUser.State = "..."; newUser.Title = "..."; if (newUser.validation_Failed()) { "[createTmUsers] failed validation for user data:{0}".error(newUser.toXml()); newUsers.Add(null); } else { newUsers.Add(newUser); } } return(userData.createTmUsers(newUsers)); }
[SetUp][Admin] public void setUp() { UserGroup.Admin.assert(); //create TM_FileStorage on temp Custom_WebRoot for this TestFixture TM_FileStorage.Custom_WebRoot = "custom_WebRoot".tempDir(); tmFileStorage = new TM_FileStorage(false); tmFileStorage.set_WebRoot() .set_Path_XmlDatabase() .tmServer_Load() .set_Path_UserData() .load_UserData(); tmFileStorage.hook_Events_TM_UserData(); tmXmlDatabase = tmFileStorage.TMXmlDatabase.assert_Not_Null(); userData = tmFileStorage.UserData.assert_Not_Null(); tmServer = tmFileStorage.Server.assert_Not_Null(); tmFileStorage.Path_XmlDatabase.assert_Folder_Exists(); tmFileStorage.Path_UserData.assert_Folder_Exists(); userDataGit = tmFileStorage.setup_UserData_Git_Support(); // adds Git Support for UserData repos tmFileStorage.Path_UserData.isGitRepository().assert_True(); Assert.NotNull(tmFileStorage.Server.userData_Config()); userData.createDefaultAdminUser(); userDataGit.triggerGitCommit(); nGit = userDataGit.NGit; nGit.commits().assert_Size_Is(2, "there should be two commits here"); UserGroup.None.assert(); }
public void Issue_826__No_lenght_constraint_on_User_Tags_SigupResponse() { var userData = new TM_UserData(); var newUser = new NewUser().with_Random_Data(); newUser.validate().asStringList().assert_Is_Empty(); var userTag_Ok = new UserTag { Key = 254.randomLetters(), Value = 254.randomLetters() }; var userTag_Fail = new UserTag { Key = 256.randomLetters(), Value = 256.randomLetters() }; userTag_Ok.validate().assert_Empty(); userTag_Fail.validate().assert_Not_Empty(); newUser.UserTags.add(userTag_Ok); userData.createTmUserResponse(newUser).UserCreated.assert_Is_Not(0); newUser.UserTags.add(userTag_Fail); userData.createTmUser(newUser).assert_Is(0); }
public static int newUser(this TM_UserData userData, string username, string password) { var randomEmail = "{0}@{1}.{2}".format(7.randomLetters(), 5.randomLetters(), 2.randomLetters()).lower(); return(userData.newUser(username, password, randomEmail, 0)); }
public void setup() { tmFileStorage = new TM_FileStorage(false); tmUserData = tmFileStorage.UserData; }
public static int newUser(this TM_UserData userData, string username, string password, string email, int groupId) { return(userData.newUser(username, password, email, "...", "...", "...", "...", "...", "...", "...", null, groupId)); }
public void setup() { tmConfig.WindowsAuthentication.Enabled = false; windowsAuthentication = new WindowsAuthentication(); userData = new TM_UserData(); }
public static Signup_Result createTmUserResponse(this TM_UserData userData, NewUser newUser) { var sigupResponse = new Signup_Result(); var tmConfig = TMConfig.Current; // ensure the email is lowercase (will fail validation otherwise) if (newUser.isNull()) { userData.logTBotActivity("User Creation Fail", "TEAM Mentor user is null"); sigupResponse.Signup_Status = Signup_Result.SignupStatus.Signup_Error; sigupResponse.UserCreated = 0; sigupResponse.Simple_Error_Message = tmConfig.TMErrorMessages.General_SignUp_Error_Message; return(sigupResponse); } newUser.Email = newUser.Email.lower(); //Validating if Username has not been already registered. if (newUser.Username.tmUser().notNull()) { userData.logTBotActivity("User Creation Fail", "Username ('{0}') already exist in TEAM Mentor".format(newUser.Username)); return(GetErrorMessage("Username", tmConfig.TMErrorMessages.SignUpUsernameAlreadyExist)); } //Email check (length, null, valid) if (newUser.Email.notNull() && newUser.Email.Length > 256) { userData.logTBotActivity("User Creation Fail", "Input rejected because email address ('{0}') is larger than 256 characters".format(newUser.Email)); return(GetErrorMessage("Email", tmConfig.TMErrorMessages.Email_Address_Is_Invalid)); } //Check email format if (newUser.valid_Email_Address().isFalse()) { userData.logTBotActivity("User Creation Fail", "Input rejected because email address ('{0}') is not valid".format(newUser.Email)); return(GetErrorMessage("Email", tmConfig.TMErrorMessages.Email_Address_Is_Invalid)); } if (newUser.Email.tmUser_FromEmail().notNull()) { userData.logTBotActivity("User Creation Fail", "Email ('{0}') already existed".format(newUser.Email)); return(GetErrorMessage("Email", tmConfig.TMErrorMessages.SignUpEmailAlreadyExist)); } //Validate Password Length. if (newUser.Password.Length < 8 || newUser.Password.Length > 256) { userData.logTBotActivity("User Creation Fail", "Password must be 8 to 256 character long but was {0}".format(newUser.Password.Length)); return(GetErrorMessage("Password", tmConfig.TMErrorMessages.PasswordLengthErrorMessage)); } //Password complexity if (!Regex.IsMatch(newUser.Password, ValidationRegex.PasswordComplexity)) { userData.logTBotActivity("User Creation Fail", "Password {0} does not meet complexity requirements.".format(newUser.Password)); return(GetErrorMessage("Password", tmConfig.TMErrorMessages.PasswordComplexityErroMessage)); } //validate user against the DataContract specificed in the NewUser class if (newUser.validation_Failed()) { return(ValidationFailed(tmConfig, newUser)); } if (newUser.UserTags.notEmpty()) { foreach (var userTag in newUser.UserTags) { if (userTag.validation_Failed()) { return(UserTags_Validation(tmConfig, userTag)); } } } // if there is a groupId provided we must check if the user has the manageUsers Priviledge if (newUser.GroupId != 0) { UserRole.ManageUsers.demand(); } var userCreated = userData.newUser(newUser.Username, newUser.Password, newUser.Email, newUser.Firstname, newUser.Lastname, newUser.Note, newUser.Title, newUser.Company, newUser.Country, newUser.State, newUser.UserTags, newUser.GroupId); if (userCreated > 0) { sigupResponse.UserCreated = userCreated; sigupResponse.Signup_Status = Signup_Result.SignupStatus.Signup_Ok; } else { userData.logTBotActivity("User Creation Fail", "Error occurred creating user".format(newUser.ToString())); sigupResponse.UserCreated = userCreated; sigupResponse.Signup_Status = Signup_Result.SignupStatus.Validation_Failed; sigupResponse.Simple_Error_Message = tmConfig.TMErrorMessages.General_SignUp_Error_Message; } return(sigupResponse); }
public static TMUser createUser(this TM_UserData userData) { return(userData.newUser().tmUser()); }
public static int newUser(this TM_UserData userData) { return(userData.newUser("test_user_{0}".format(5.randomLetters()))); }
public static int newUser(this TM_UserData userData, string username) { return(userData.newUser(username, 5.randomLetters())); }
public static int newUser(this TM_UserData userData, string username, string password, string email) { return(userData.newUser(username, password, email, 0)); }
public void SecretData_Via_TM_UserData() { var userData = new TM_UserData(); Assert.NotNull(userData.SecretData, "new TM_UserData should create new TM_SecretData object"); }