-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-957747: Easy logging improvements (#1730)
- Loading branch information
1 parent
d4504f8
commit f39eff4
Showing
5 changed files
with
276 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.snowflake.client; | ||
|
||
import net.snowflake.client.core.Constants; | ||
|
||
public class RunningOnWin implements ConditionalIgnoreRule.IgnoreCondition { | ||
public boolean isSatisfied() { | ||
return Constants.getOS() == Constants.OS.WINDOWS; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/test/java/net/snowflake/client/config/SFPermissionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package net.snowflake.client.config; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.attribute.PosixFilePermissions; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import net.snowflake.client.ConditionalIgnoreRule; | ||
import net.snowflake.client.RunningOnWin; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class SFPermissionsTest { | ||
@Rule public ConditionalIgnoreRule rule = new ConditionalIgnoreRule(); | ||
|
||
@Parameterized.Parameters(name = "permission={0}") | ||
public static Set<Map.Entry<String, Boolean>> data() { | ||
Map<String, Boolean> testConfigFilePermissions = | ||
new HashMap<String, Boolean>() { | ||
{ | ||
put("rwx------", false); | ||
put("rw-------", false); | ||
put("r-x------", false); | ||
put("r--------", false); | ||
put("rwxrwx---", true); | ||
put("rwxrw----", true); | ||
put("rwxr-x---", false); | ||
put("rwxr-----", false); | ||
put("rwx-wx---", true); | ||
put("rwx-w----", true); | ||
put("rwx--x---", false); | ||
put("rwx---rwx", true); | ||
put("rwx---rw-", true); | ||
put("rwx---r-x", false); | ||
put("rwx---r--", false); | ||
put("rwx----wx", true); | ||
put("rwx----w-", true); | ||
put("rwx-----x", false); | ||
} | ||
}; | ||
return testConfigFilePermissions.entrySet(); | ||
} | ||
|
||
Path configFilePath = Paths.get("config.json"); | ||
String configJson = "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"logs\"}}"; | ||
String permission; | ||
Boolean isSucceed; | ||
|
||
public SFPermissionsTest(Map.Entry<String, Boolean> permission) { | ||
this.permission = permission.getKey(); | ||
this.isSucceed = permission.getValue(); | ||
} | ||
|
||
@Before | ||
public void createConfigFile() throws IOException { | ||
Files.write(configFilePath, configJson.getBytes()); | ||
} | ||
|
||
@After | ||
public void cleanupConfigFile() throws IOException { | ||
Files.deleteIfExists(configFilePath); | ||
} | ||
|
||
@Test | ||
@ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnWin.class) | ||
public void testLogDirectoryPermissions() throws IOException { | ||
// TODO: SNOW-1503722 Change to check for thrown exceptions | ||
// Don't run on Windows | ||
Files.setPosixFilePermissions(configFilePath, PosixFilePermissions.fromString(permission)); | ||
Boolean result = | ||
SFClientConfigParser.checkGroupOthersWritePermissions(configFilePath.toString()); | ||
if (isSucceed != result) { | ||
fail("testLogDirectoryPermissions failed. Expected " + isSucceed); | ||
} | ||
} | ||
} |
Oops, something went wrong.