@Test public void testKeepFilePermissions() throws Exception { String storageLocation = getStoragePathForNewFile(); String storagePassword = "cspassword"; String aliasName = "testalias"; String aliasValue = "secret"; String aliasName2 = "testalias2"; String aliasValue2 = "secret2"; Path storagePath = Paths.get(storageLocation); Assume.assumeTrue(storagePath.getFileSystem().supportedFileAttributeViews().contains("posix") || storagePath.getFileSystem().supportedFileAttributeViews().contains("acl")); String[] args = { "--location=" + storageLocation, "--create", "--add", aliasName, "--secret", aliasValue, "--summary", "--password", storagePassword }; executeCommandAndCheckStatus(args); CredentialStore store = getCredentialStoreStorageFromExistsFile(storageLocation, storagePassword); checkAliasSecretValue(store, aliasName, aliasValue); assertTrue("Credetial store location is created", Files.exists(storagePath)); Map<String, Object> originalPermissions = CredentialStoreCommand.readAttributesForPreservation(storagePath); changeExecutable(storagePath); Map<String, Object> locationPermissionsBeforeFlush = CredentialStoreCommand.readAttributesForPreservation(storagePath); Assert.assertNotEquals("Attributes are different to the original file", originalPermissions, locationPermissionsBeforeFlush); String[] args2 = { "--location=" + storageLocation, "--create", "--add", aliasName2, "--secret", aliasValue2, "--summary", "--password", storagePassword }; executeCommandAndCheckStatus(args2); store = getCredentialStoreStorageFromExistsFile(storageLocation, storagePassword); checkAliasSecretValue(store, aliasName2, aliasValue2); Map<String, Object> locationPermissionsAfterFlush = CredentialStoreCommand.readAttributesForPreservation(storagePath); assertEquals("Attributes to preserve are the same", locationPermissionsBeforeFlush, locationPermissionsAfterFlush); }
public static Map<String, Object> readAttributesForPreservation(Path path) throws IOException { Map<String, Object> attrs = new HashMap<>(); if (Files.exists(path)) { Set<String> supportedViews = path.getFileSystem().supportedFileAttributeViews(); if (supportedViews.contains("posix")) { readAttributesForView(path, "posix:", "posix:permissions", attrs); } if (supportedViews.contains("dos")) { readAttributesForView(path, "dos:", "dos:readonly,hidden,archive,system", attrs); } if (supportedViews.contains("acl")) { readAttributesForView(path, "acl:", "acl:acl", attrs); } } return attrs; }
CredentialStoreCommand extends Command { public static Map<String, Object> readAttributesForPreservation(Path path) throws IOException { Map<String, Object> attrs = new HashMap<>(); if (Files.exists(path)) { Set<String> supportedViews = path.getFileSystem().supportedFileAttributeViews(); if (supportedViews.contains("posix")) { readAttributesForView(path, "posix:", "posix:permissions", attrs); } if (supportedViews.contains("dos")) { readAttributesForView(path, "dos:", "dos:readonly,hidden,archive,system", attrs); } if (supportedViews.contains("acl")) { readAttributesForView(path, "acl:", "acl:acl", attrs); } } return attrs; } }
CredentialStoreCommand extends Command { public static Map<String, Object> readAttributesForPreservation(Path path) throws IOException { Map<String, Object> attrs = new HashMap<>(); if (Files.exists(path)) { Set<String> supportedViews = path.getFileSystem().supportedFileAttributeViews(); if (supportedViews.contains("posix")) { readAttributesForView(path, "posix:", "posix:permissions", attrs); } if (supportedViews.contains("dos")) { readAttributesForView(path, "dos:", "dos:readonly,hidden,archive,system", attrs); } if (supportedViews.contains("acl")) { readAttributesForView(path, "acl:", "acl:acl", attrs); } } return attrs; } CredentialStoreCommand(); }
CredentialStoreCommand extends Command { public static Map<String, Object> readAttributesForPreservation(Path path) throws IOException { Map<String, Object> attrs = new HashMap<>(); if (Files.exists(path)) { Set<String> supportedViews = path.getFileSystem().supportedFileAttributeViews(); if (supportedViews.contains("posix")) { readAttributesForView(path, "posix:", "posix:permissions", attrs); } if (supportedViews.contains("dos")) { readAttributesForView(path, "dos:", "dos:readonly,hidden,archive,system", attrs); } if (supportedViews.contains("acl")) { readAttributesForView(path, "acl:", "acl:acl", attrs); } } return attrs; } CredentialStoreCommand(); static Map<String, Object> readAttributesForPreservation(Path path); static void setAttributesForPreservation(Path path, Map<String, Object> attrs); @Override void execute(String[] args); @Override void help(); }
CredentialStoreCommand extends Command { public static Map<String, Object> readAttributesForPreservation(Path path) throws IOException { Map<String, Object> attrs = new HashMap<>(); if (Files.exists(path)) { Set<String> supportedViews = path.getFileSystem().supportedFileAttributeViews(); if (supportedViews.contains("posix")) { readAttributesForView(path, "posix:", "posix:permissions", attrs); } if (supportedViews.contains("dos")) { readAttributesForView(path, "dos:", "dos:readonly,hidden,archive,system", attrs); } if (supportedViews.contains("acl")) { readAttributesForView(path, "acl:", "acl:acl", attrs); } } return attrs; } CredentialStoreCommand(); static Map<String, Object> readAttributesForPreservation(Path path); static void setAttributesForPreservation(Path path, Map<String, Object> attrs); @Override void execute(String[] args); @Override void help(); static int ACTION_NOT_DEFINED; static int ALIAS_NOT_FOUND; static int GENERAL_CONFIGURATION_ERROR; static final String RSA_ALGORITHM; static final String DSA_ALGORITHM; static final String EC_ALGORITHM; static final String CREDENTIAL_STORE_COMMAND; static final String STORE_LOCATION_PARAM; static final String IMPLEMENTATION_PROPERTIES_PARAM; static final String CREDENTIAL_STORE_PASSWORD_PARAM; static final String CREDENTIAL_STORE_TYPE_PARAM; static final String SALT_PARAM; static final String ITERATION_PARAM; static final String PASSWORD_CREDENTIAL_VALUE_PARAM; static final String ADD_ALIAS_PARAM; static final String CHECK_ALIAS_PARAM; static final String ALIASES_PARAM; static final String REMOVE_ALIAS_PARAM; static final String CREATE_CREDENTIAL_STORE_PARAM; static final String HELP_PARAM; static final String PRINT_SUMMARY_PARAM; static final String ENTRY_TYPE_PARAM; static final String OTHER_PROVIDERS_PARAM; static final String DEBUG_PARAM; static final String CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM; static final String GENERATE_KEY_PAIR_PARAM; static final String ALGORITHM_PARAM; static final String SIZE_PARAM; static final String EXPORT_KEY_PAIR_PUBLIC_KEY_PARAM; static final String IMPORT_KEY_PAIR_PARAM; static final String PRIVATE_KEY_LOCATION_PARAM; static final String PUBLIC_KEY_LOCATION_PARAM; static final String PRIVATE_KEY_STRING_PARAM; static final String PUBLIC_KEY_STRING_PARAM; static final String KEY_PASSPHRASE_PARAM; }