use of org.junit.jupiter.api.condition.EnabledOnOs in project OpenGrok by OpenGrok.
the class PathUtilsTest method shouldHandleLinksToCanonicalChildrenOfAllowedLinks.
@Test
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
public void shouldHandleLinksToCanonicalChildrenOfAllowedLinks() throws IOException, ForbiddenSymlinkException {
// Create real directories
File sourceRoot = createTemporaryDirectory("srcroot");
assertTrue(sourceRoot.isDirectory(), sourceRoot + " should be a dir");
File realDir1 = createTemporaryDirectory("realdir1");
assertTrue(realDir1.isDirectory(), realDir1 + " should be a dir");
File realDir1b = new File(realDir1, "b");
assertTrue(realDir1b.mkdir(), realDir1b + " should be created");
// Create symlink #1 to realdir1/ in source root.
final String SYMLINK1 = "symlink1";
File symlink1 = new File(sourceRoot, SYMLINK1);
Files.createSymbolicLink(symlink1.toPath(), realDir1.toPath());
assertTrue(symlink1.exists(), symlink1 + " should exist");
// Create symlink #2 to realdir1/b in source root.
final String SYMLINK2 = "symlink2";
File symlink2 = new File(realDir1b, SYMLINK2);
Files.createSymbolicLink(symlink2.toPath(), realDir1b.toPath());
assertTrue(symlink2.exists(), symlink2 + " should exist");
// Test symlink2 v. realDir1 canonical with validation and an allowed symlink1
Set<String> allowedSymLinks = new HashSet<>();
allowedSymLinks.add(symlink1.getPath());
String realDir1Canon = realDir1.getCanonicalPath();
String rel = relativeToCanonical(symlink2.toString(), realDir1Canon, allowedSymLinks, null);
assertEquals("b", rel, "symlink2 should be allowed implicitly as a canonical child of symlink1");
}
use of org.junit.jupiter.api.condition.EnabledOnOs in project OpenGrok by OpenGrok.
the class FileHistoryCacheTest method testStoreAndTryToGetIgnored.
/**
* Test history when activating PathAccepter for ignoring files.
*/
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
@Test
void testStoreAndTryToGetIgnored() throws Exception {
env.getIgnoredNames().add("f:Make*");
File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
Repository repo = RepositoryFactory.getRepository(reposRoot);
History historyToStore = repo.getHistory(reposRoot);
cache.store(historyToStore, repo);
// test reindex history
History historyNull = new History();
cache.store(historyNull, repo);
// test get history for single file
File makefile = new File(reposRoot, "Makefile");
assertTrue(makefile.exists(), "" + makefile + " should exist");
History retrievedHistory = cache.get(makefile, repo, true);
assertNull(retrievedHistory, "history for Makefile should be null");
// Gross that we can break encapsulation, but oh well.
env.getIgnoredNames().clear();
cache.store(historyToStore, repo);
retrievedHistory = cache.get(makefile, repo, true);
assertNotNull(retrievedHistory, "history for Makefile should not be null");
}
use of org.junit.jupiter.api.condition.EnabledOnOs in project OpenGrok by OpenGrok.
the class FileHistoryCacheTest method testStoreTouchGet.
/**
* {@link FileHistoryCache#get(File, Repository, boolean)} should not disturb history cache
* if run between repository update and reindex.
*/
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
@Test
void testStoreTouchGet() throws Exception {
File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
Repository repo = RepositoryFactory.getRepository(reposRoot);
History historyToStore = repo.getHistory(reposRoot);
cache.store(historyToStore, repo);
// This makes sure that the file which contains the latest revision has indeed been created.
assertEquals("9:8b340409b3a8", cache.getLatestCachedRevision(repo));
File file = new File(reposRoot, "main.c");
assertTrue(file.exists());
FileTime fileTimeBeforeImport = Files.getLastModifiedTime(file.toPath());
History historyBeforeImport = cache.get(file, repo, false);
MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export.txt").toURI()).toString());
FileTime fileTimeAfterImport = Files.getLastModifiedTime(file.toPath());
assertTrue(fileTimeBeforeImport.compareTo(fileTimeAfterImport) < 0);
// This get() call basically mimics a request through the UI or API.
History historyAfterImport = cache.get(file, repo, false);
assertNotNull(historyAfterImport);
assertNotEquals(historyBeforeImport, historyAfterImport);
// Simulates reindex, or at least its first part when history cache is updated.
repo.createCache(cache, cache.getLatestCachedRevision(repo));
// This makes sure that the file which contains the latest revision has indeed been created.
assertEquals("11:bbb3ce75e1b8", cache.getLatestCachedRevision(repo));
/*
* The history should not be disturbed.
* Make sure that get() retrieved the history from cache. Mocking/spying static methods
* (FileHistoryCache#readCache() in this case) is tricky so use the cache hits metric.
*/
double cacheHitsBeforeGet = cache.getFileHistoryCacheHits();
History historyAfterReindex = cache.get(file, repo, false);
double cacheHitsAfterGet = cache.getFileHistoryCacheHits();
assertNotNull(historyAfterReindex);
assertEquals(historyAfterImport, historyAfterReindex);
assertEquals(1, cacheHitsAfterGet - cacheHitsBeforeGet);
}
use of org.junit.jupiter.api.condition.EnabledOnOs in project logging-log4j2 by apache.
the class NetUtilsTest method testToUriWindowsWithBackslashes.
@Test
@EnabledOnOs(OS.WINDOWS)
public void testToUriWindowsWithBackslashes() {
final String config = "file:///D:\\path\\to\\something/on/windows";
final URI uri = NetUtils.toURI(config);
assertNotNull(uri, "The URI should not be null.");
assertEquals("file:///D:/path/to/something/on/windows", uri.toString(), "The URI is not correct.");
}
use of org.junit.jupiter.api.condition.EnabledOnOs in project logging-log4j2 by apache.
the class NetUtilsTest method testToUriWindowsAbsolutePath.
@Test
@EnabledOnOs(OS.WINDOWS)
public void testToUriWindowsAbsolutePath() {
final String config = "D:\\path\\to\\something\\on\\windows";
final URI uri = NetUtils.toURI(config);
assertNotNull(uri, "The URI should not be null.");
assertEquals("file:/D:/path/to/something/on/windows", uri.toString(), "The URI is not correct.");
}
Aggregations