Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,32 @@ public void init() {
}

@After
public void shutdown() throws InterruptedException {
public void shutdown() {
terminate(threadPool);
}

public void testStore_ConfiguredWithUnreadableFile() throws Exception {
Path xpackConf = env.configFile();
Files.createDirectories(xpackConf);
Path file = xpackConf.resolve("users");
Path configDir = env.configFile();
Files.createDirectories(configDir);
Path file = configDir.resolve("users");

// writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);

Settings fileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder().put("files.users", file.toAbsolutePath()).build();
RealmConfig config = getRealmConfig(fileSettings);
RealmConfig config = getRealmConfig();
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
FileUserPasswdStore store = new FileUserPasswdStore(config, watcherService);
assertThat(store.usersCount(), is(0));
}

public void testStore_AutoReload() throws Exception {
Path users = getDataPath("users");
Path xpackConf = env.configFile();
Files.createDirectories(xpackConf);
Path file = xpackConf.resolve("users");
Path configDir = env.configFile();
Files.createDirectories(configDir);
Path file = configDir.resolve("users");
Files.copy(users, file, StandardCopyOption.REPLACE_EXISTING);
final Hasher hasher = Hasher.resolve(settings.get("xpack.security.authc.password_hashing.algorithm"));
Settings fileSettings = randomBoolean() ? Settings.EMPTY : Settings.builder().put("files.users", file.toAbsolutePath()).build();
RealmConfig config = getRealmConfig(fileSettings);
RealmConfig config = getRealmConfig();
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
final CountDownLatch latch = new CountDownLatch(1);

Expand Down Expand Up @@ -120,23 +118,19 @@ public void testStore_AutoReload() throws Exception {
assertThat(result.getUser(), is(user));
}

private RealmConfig getRealmConfig(Settings fileSettings) {
private RealmConfig getRealmConfig() {
final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier("file", "file-test");
return new RealmConfig(identifier, settings, env, threadPool.getThreadContext());
}

public void testStore_AutoReload_WithParseFailures() throws Exception {
Path users = getDataPath("users");
Path xpackConf = env.configFile();
Files.createDirectories(xpackConf);
Path testUsers = xpackConf.resolve("users");
Path confDir = env.configFile();
Files.createDirectories(confDir);
Path testUsers = confDir.resolve("users");
Files.copy(users, testUsers, StandardCopyOption.REPLACE_EXISTING);

Settings fileSettings = Settings.builder()
.put("files.users", testUsers.toAbsolutePath())
.build();

RealmConfig config = getRealmConfig(fileSettings);
RealmConfig config = getRealmConfig();
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
final CountDownLatch latch = new CountDownLatch(1);

Expand Down Expand Up @@ -192,6 +186,7 @@ public void testParseFile_Empty() throws Exception {
Path empty = createTempFile();
Logger logger = CapturingLogger.newCapturingLogger(Level.DEBUG, null);
Map<String, char[]> users = FileUserPasswdStore.parseFile(empty, logger, Settings.EMPTY);
assertThat(users, notNullValue());
assertThat(users.isEmpty(), is(true));
List<String> events = CapturingLogger.output(logger.getName(), Level.DEBUG);
assertThat(events.size(), is(1));
Expand Down