[Test] public void set_Path_SiteData() { var tmFileStorage = new TM_FileStorage(); var expectedPath = tmFileStorage.path_XmlDatabase().pathCombine(TMConsts.TM_SERVER_DEFAULT_NAME_SITEDATA); tmFileStorage.set_Path_SiteData(); Assert.AreEqual(tmFileStorage.Path_SiteData, expectedPath); Assert.True(tmFileStorage.Path_SiteData.dirExists()); // try with a different Name value var tempName = 10.randomLetters(); tmFileStorage.Server.siteData_Config().Name = tempName; tmFileStorage.set_Path_SiteData(); Assert.IsTrue(tmFileStorage.Path_SiteData.contains(tempName)); //check bad data handling tmFileStorage.Server.siteData_Config().Name = null; tmFileStorage.set_Path_SiteData(); Assert.IsTrue(tmFileStorage.Path_SiteData.contains(TMConsts.TM_SERVER_DEFAULT_NAME_SITEDATA)); tmFileStorage.Server.siteData_Config().Name = "aaa:bbb"; // will fail to create the SiteData folder and force memory mode tmFileStorage.set_Path_SiteData(); Assert.IsNull(tmFileStorage.Path_SiteData); }
public void TM_hook_Events_TM_Xml_Database_RestrictedTo_Anonymous() { var tmFileStorage = new TM_FileStorage(loadData: false); Assert.NotNull(tmFileStorage); var result = tmFileStorage.hook_Events_TM_Xml_Database(); }
public static TM_FileStorage delete_Database(this TM_FileStorage tmFileStorage) { tmFileStorage.assert_Not_Null() .path_XmlDatabase().assert_Not_Null() .assert_Is_Not_Equal_To(tmFileStorage.WebRoot); if (tmFileStorage.path_XmlDatabase().dirExists()) // check if the folder exists { //Assert.IsNotEmpty(tmDatabase.path_XmlDatabase().files()); tmFileStorage.path_XmlDatabase().files(true).files_Attribute_ReadOnly_Remove(); // make all files writable tmFileStorage.waitForComplete_Save_GuidanceItemsCache(); tmFileStorage.clear_GuidanceItemsCache(); Files.deleteFolder(tmFileStorage.path_XmlDatabase(), true); // delete all files recusively tmFileStorage.path_XmlDatabase().folder_Wait_For_Deleted(); tmFileStorage.path_XmlDatabase().assert_Folder_Doesnt_Exist(); Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists()); // ensure the deletion happened Assert.IsEmpty(tmFileStorage.path_XmlDatabase().files()); Assert.IsEmpty(tmFileStorage.tmXmlDatabase().Cached_GuidanceItems); Assert.IsFalse(tmFileStorage.getCacheLocation().fileExists()); "[Test][TM_Xml_Database][delete_Database]TM database files were deleted from: {0}".info(tmFileStorage.path_XmlDatabase()); } return(tmFileStorage); }
public static string Get_Path_To_File(this TM_FileStorage tmFileStorage, string fileKey) { UserRole.ReadArticles.demand(); var filePath = tmFileStorage.path_XmlLibraries().pathCombine("_Images").pathCombine(fileKey); if (filePath.fileExists()) { return(filePath); } var splitedFileKey = fileKey.split("/"); if (splitedFileKey.size() == 2) { var item = splitedFileKey[0].trim(); var fileName = splitedFileKey[1].trim(); if (item.isGuid()) { return(tmFileStorage.Get_Path_To_File(item.guid(), fileName)); } return(tmFileStorage.Get_Path_To_File(item, fileName)); } foreach (var library in tmFileStorage.tmXmlDatabase().tmLibraries()) { filePath = tmFileStorage.Get_Path_To_File(library.Caption, fileKey); if (filePath.notNull()) { return(filePath); } } return(null); }
public static TM_FileStorage setGuidanceExplorerObjects(this TM_FileStorage tmFileStorage) { var pathXmlLibraries = tmFileStorage.Path_XmlLibraries; tmFileStorage.GuidanceExplorers_Paths.Clear(); return(tmFileStorage.guidanceExplorers_XmlFormat(tmFileStorage.getGuidanceExplorerObjects(pathXmlLibraries))); }
// this is a (bit) time consumining (less 1s for 8000 files), so it should only be done once (this is another good cache target) public static void populateGuidanceItemsFileMappings(this TM_FileStorage tmFileStorage) { var tmFileStorate = TM_FileStorage.Current; tmFileStorate.GuidanceItems_FileMappings.Clear(); var o2Timer = new O2Timer("[TM_Xml_Database] populateGuidanceExplorersFileMappings").start(); foreach (var filePath in tmFileStorate.Path_XmlLibraries.files(true, "*.xml")) { var fileId = filePath.fileName().remove(".xml"); if (fileId.isGuid()) { //"[populateGuidanceItemsFileMappings] loading GuidanceItem ID {0}".info(fileId); var guid = fileId.guid(); if (tmFileStorate.GuidanceItems_FileMappings.hasKey(guid)) { "[TM_Xml_Database] [populateGuidanceItemsFileMappings] duplicate GuidanceItem ID found {0}".error(guid); } else { tmFileStorate.GuidanceItems_FileMappings.Add(guid, filePath); } } } o2Timer.stop(); "[TM_Xml_Database] [populateGuidanceItemsFileMappings] There are {0} files mapped in GuidanceItems_FileMappings".info(tmFileStorate.GuidanceItems_FileMappings.size()); }
public static string getXmlFilePathForGuidanceId(this TM_FileStorage tmFileStorage, Guid guidanceItemId, Guid libraryId) { var tmFileStorate = TM_FileStorage.Current; //first see if we already have this mapping if (tmFileStorate.GuidanceItems_FileMappings.hasKey(guidanceItemId)) { //"in getXmlFilePathForGuidanceId, found id in current mappings: {0}".info( guidanceItemId); return(tmFileStorate.GuidanceItems_FileMappings[guidanceItemId]); } //then update the GuidanceItems_FileMappings dictionary if (libraryId == Guid.Empty) { "[getXmlFilePathForGuidanceId] When creating a new GuidanceItem a libraryId must be provided".error(); return(null); } var tmLibrary = tmFileStorage.tmXmlDatabase().tmLibrary(libraryId); if (tmLibrary == null) { "[getXmlFilePathForGuidanceId] When creating a new GuidanceItem could not find library for libraryId: {0}".error(libraryId); return(null); } var libraryPath = tmFileStorage.xmlDB_Path_Library_RootFolder(tmLibrary); var newArticleFolder = libraryPath.pathCombine(TMConsts.DEFAULT_ARTICLE_FOLDER_NAME); var xmlPath = newArticleFolder.createDir() .pathCombine("{0}.xml".format(guidanceItemId)); "in getXmlFilePathForGuidanceId, no previous mapping found so adding new GuidanceItems_FileMappings for :{0}".info(xmlPath); tmFileStorate.GuidanceItems_FileMappings.add(guidanceItemId, xmlPath); //add it to the file_mappings dictionary so that we know it for next time return(xmlPath); }
/*public void Install_LibraryFromZip_TopVulns() // not public anymore * { * var topVulnsZipFile = DownloadLibraryIntoTempFolder("Lib_Top_Vulnerabilities.zip", * "https://github.com/TMContent/Lib_Top_Vulnerabilities/archive/master.zip"); * Install_LibraryFromZip(topVulnsZipFile,"Top Vulnerabilities"); * } */ public static string install_LibraryFromZip_Docs(this TM_FileStorage tmFileStorage) { var topVulnsZipFile = tmFileStorage.downloadLibraryIntoTempFolder("Lib_Docs.zip", "https://github.com/TMContent/Lib_Docs/archive/master.zip"); return(tmFileStorage.install_LibraryFromZip(topVulnsZipFile, "TM Documentation")); }
public static string install_LibraryFromZip_OWASP(this TM_FileStorage tmFileStorage) { var owaspZipFile = tmFileStorage.downloadLibraryIntoTempFolder("Lib_OWASP.zip", "https://github.com/TMContent/Lib_OWASP/archive/master.zip"); return(tmFileStorage.install_LibraryFromZip(owaspZipFile, "OWASP")); }
[Test] public void set_Path_XmlDatabase__UsingFileStorage_On_Custom_WebRoot() { var tmFileStorage = new TM_FileStorage(false); //Assert.AreEqual(tmFileStorage.WebRoot, AppDomain.CurrentDomain.BaseDirectory); tmFileStorage.WebRoot = "_tmp_webRoot".tempDir().info(); tmFileStorage.WebRoot.delete_Folder(); Assert.IsFalse(tmFileStorage.WebRoot.dirExists()); tmFileStorage.set_Path_XmlDatabase(); Assert.IsTrue(tmFileStorage.path_XmlDatabase().dirExists(), "db ctor should create a library folder"); var usingAppDataFolder = TM_Status.Current.TM_Database_Location_Using_AppData; "*** DB path: {0}".info(tmFileStorage.path_XmlDatabase()); "*** Lib path: {0}".info(tmFileStorage.Path_XmlLibraries); "*** Current WebRoot: {0}".debug(tmFileStorage.WebRoot); "*** Current WebRoot exists: {0}".debug(tmFileStorage.WebRoot.dirExists()); "*** TM_Status.Current.TM_Database_Location_Using_AppData: {0}".debug(TM_Status.Current.TM_Database_Location_Using_AppData); Assert.AreEqual(usingAppDataFolder, tmFileStorage.WebRoot.dirExists(), "db ctor should not create a Web Root (if it doesn't exist)"); Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains("App_Data")); Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains(tmFileStorage.WebRoot)); Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains(PublicDI.config.O2TempDir)); tmFileStorage.delete_Database(); Assert.AreEqual(usingAppDataFolder, tmFileStorage.WebRoot.dirExists(), "if not usingAppDataFolder the TM_Server.WebRoot shouldn't exist"); Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists(), "should had been deleted"); }
[SetUp] public void setup() { this.tmProxy_Refresh(); tmFileStorage = tmProxy.TmFileStorage.assert_Not_Null(); tmServer = tmProxy.TmServer.assert_Not_Null(); path_SiteData = tmFileStorage.path_SiteData(); }
public static UserActivity logTBotActivity(this TM_FileStorage tmFileStorage, string action, string detail) { if (tmFileStorage.notNull()) { return(tmFileStorage.UserData.logTBotActivity(action, detail)); } return(null); }
[Test] public void tm_Server_Load__In_Memory() { var tmFileStorage = new TM_FileStorage(false); var tmServer_defaultData = new TM_Server(); //.setDefaultData(); Assert.NotNull(tmFileStorage.Server); Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_defaultData.toXml()); // check if the value matches a new object of type TM_Server }
public TM_UserData_Git(TM_FileStorage tmFileStorage) { Current = this; FileStorage = tmFileStorage; UserData = tmFileStorage.userData(); NGit_Author_Name = TMConsts.NGIT_DEFAULT_AUTHOR_NAME; NGit_Author_Email = TMConsts.NGIT_DEFAULT_AUTHOR_EMAIL; }
public void TM_hook_Events_TM_Xml_Database_RestrictedTo_Editor() { var tmFileStorage = new TM_FileStorage(loadData: false); Assert.NotNull(tmFileStorage); UserGroup.Reader.assert(); var result = tmFileStorage.hook_Events_TM_Xml_Database(); }
public static TM_FileStorage guidanceExplorers_XmlFormat(this TM_FileStorage tmFileStorage, Dictionary <Guid, guidanceExplorer> guidanceExplorers) { if (tmFileStorage.tmXmlDatabase().notNull()) { tmFileStorage.tmXmlDatabase().GuidanceExplorers_XmlFormat = guidanceExplorers; } return(tmFileStorage); }
public TM_WebServices(bool disable_Csrf_Check) { tmXmlDatabase = TM_Xml_Database.Current; tmFileStorage = TM_FileStorage.Current; userData = TM_UserData.Current; tmAuthentication = new TM_Authentication(this).mapUserRoles(disable_Csrf_Check); GZip.setGZipCompression_forAjaxRequests(); }
public static TM_FileStorage saveVirtualArticles(this TM_FileStorage tmFileStorage) { var virtualArticlesFile = tmFileStorage.getVirtualArticlesFile(); var virtualArticles = tmFileStorage.tmXmlDatabase().getVirtualArticles().Values.toList(); virtualArticles.saveAs(virtualArticlesFile); return(tmFileStorage); }
public static List <VirtualArticleAction> loadVirtualArticles_FromDisk(this TM_FileStorage tmFileStorage) { var virtualArticlesFile = tmFileStorage.getVirtualArticlesFile(); if (virtualArticlesFile.fileExists()) { return(virtualArticlesFile.load <List <VirtualArticleAction> >()); } return(new List <VirtualArticleAction>()); }
public static TM_UserData_Git setup_UserData_Git_Support(this TM_FileStorage tmFileStorage) { if (tmFileStorage.userData().notNull()) { var userDataGit = new TM_UserData_Git(tmFileStorage); userDataGit.syncWithGit(); return(userDataGit); } return(null); }
public void library_Deleted_LibraryNotExist() { UserGroup.Admin.assert(); var tmFileStorage = new TM_FileStorage(loadData: false); Assert.NotNull(tmFileStorage); var lib = tmFileStorage.load_Libraries(); var result = tmFileStorage.library_Deleted(new TM_Library()); Assert.IsFalse(result); }
public void Setup() { context = HttpContextFactory.Context.mock(); handleUrlRequest = new HandleUrlRequest(); tmFileStorage = new TM_FileStorage(false) { Path_XmlDatabase = "_siteData".tempDir() }; Assert.IsTrue(tmFileStorage.Path_XmlDatabase.dirExists()); }
public static string Get_Path_To_File(this TM_FileStorage tmFileStorage, Guid itemGuid, string fileName) { UserRole.ReadArticles.demand(); var library = tmFileStorage.tmXmlDatabase().tmLibrary(itemGuid); if (library.notNull()) { return(tmFileStorage.Get_Path_To_File(library.Caption, fileName)); } return(null); }
[ReadArticles] public static string xmlDB_guidanceItemXml(this TM_FileStorage tmFileStorage, Guid guidanceItemId) { UserRole.ReadArticles.demand(); if (guidanceItemId == Guid.Empty) { return(null); } var guidanceXmlPath = tmFileStorage.getXmlFilePathForGuidanceId(guidanceItemId); return(guidanceXmlPath.fileContents());//.xmlFormat(); }
[Admin] public static string xmlDB_guidanceItemPath(this TM_FileStorage tmFileStorage, Guid guidanceItemId) { UserRole.Admin.demand(); if (guidanceItemId != Guid.Empty) { if (tmFileStorage.guidanceItems_FileMappings().hasKey(guidanceItemId)) { return(tmFileStorage.guidanceItems_FileMappings()[guidanceItemId]); } } return(null); }
public override void testFixtureSetUp() { base.testFixtureSetUp(); this.tmProxy_Refresh() .tmProxy.assert_Not_Null(); tmFileStorage = tmProxy.TmFileStorage.assert_Not_Null(); ieTeamMentor = this.new_IE_TeamMentor_Hidden(true); ie = ieTeamMentor.ie; }
public static Dictionary <Guid, guidanceExplorer> getGuidanceExplorerObjects(this TM_FileStorage tmFileStorage, string pathXmlLibraries) { var guidanceExplorers = new Dictionary <Guid, guidanceExplorer>(); var guidanceExplorersXmlFiles = pathXmlLibraries.getGuidanceExplorerFilesInPath(); foreach (var xmlFile in guidanceExplorersXmlFiles) { tmFileStorage.addGuidanceExplorerObject(guidanceExplorers, xmlFile); } return(guidanceExplorers); }
[Test] public void tm_Server_Load_UsingFileStorage() { var tmFileStorage = new TM_FileStorage(false); var baseReadOnlyDir = "_tmp_webRoot".tempDir(); var webRootVirualPath = @"site\wwwroot"; // simulates use of AppData tmFileStorage.WebRoot = baseReadOnlyDir.pathCombine(webRootVirualPath).createDir(); tmFileStorage.set_Path_XmlDatabase() .set_Path_UserData() .tmServer_Load(); var tmServerFile = tmFileStorage.tmServer_Location(); var expectedLocation = tmFileStorage.Path_XmlDatabase.pathCombine(TMConsts.TM_SERVER_FILENAME); Assert.IsNotNull(tmFileStorage.path_XmlDatabase()); Assert.IsTrue(TM_Status.Current.TM_Database_Location_Using_AppData); Assert.NotNull(tmFileStorage.Server); Assert.IsTrue(tmServerFile.fileExists()); Assert.AreEqual(tmServerFile, expectedLocation); // Assert.Ignore("TO FIX (Refactor Side Effect"); // Assert.Ignore("TO FIX (Refactor Side Effect"); var tmServer_withDefaultData = new TM_Server().setDefaultData(); Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); //make a change, saved it and ensure it gets loaded ok var tmpName1 = 10.randomLetters(); var tmpName2 = 10.randomLetters(); tmFileStorage.Server.UserData_Configs.first().Name = tmpName1; tmFileStorage.tmServer_Save(); tmFileStorage.Server.UserData_Configs.first().Name = tmpName2; tmFileStorage.tmServer_Load(); Assert.AreEqual(tmFileStorage.Server.UserData_Configs.first().Name, tmpName1); Assert.AreNotEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); //Try loading up an corrupted tmServer (whcih will default to load a default TM_Server "aaaa".saveAs(tmServerFile); tmFileStorage.tmServer_Load(); Assert.AreNotEqual(tmFileStorage.Server.UserData_Configs.first().Name, tmpName1); Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); Files.deleteFolder(baseReadOnlyDir, true); Assert.IsFalse(baseReadOnlyDir.dirExists()); //tmXmlDatabase.delete_Database(); }
public void TM_hook_Events_TM_Xml_Database() { var tmFileStorage = new TM_FileStorage(loadData: false); Assert.NotNull(tmFileStorage); UserGroup.Admin.assert(); var result = tmFileStorage.hook_Events_TM_Xml_Database(); Assert.AreEqual(result.TMXmlDatabase.Events.Article_Deleted.Count, 1); Assert.AreEqual(result.TMXmlDatabase.Events.Article_Saved.Count, 1); Assert.AreEqual(result.TMXmlDatabase.Events.GuidanceExplorer_Save.Count, 1); Assert.AreEqual(result.TMXmlDatabase.Events.Articles_Cache_Updated.Count, 2); }
public static bool loadDataIntoMemory(this TM_FileStorage tmFileStorage) { if (tmFileStorage.path_XmlDatabase().dirExists().isFalse()) { "[TM_Xml_Database] in loadDataIntoMemory, provided pathXmlDatabase didn't exist: {0}".error(tmFileStorage.path_XmlDatabase()); return(false); } tmFileStorage.loadLibraryDataFromDisk(); //tmXmlDatabase.setupGitSupport(); //tmXmlDatabase.UserData.loadTmUserData(); return(true); }