[TEST] Cleanup FileUserPasswdStoreTests (#35329)
The file realm has not supported custom filenames/locations since at least 5.0, but this test still tried to configure them. Remove all configuration of file locations, and cleaned up a few other warnings and deprecations
This commit is contained in:
parent
a4d979cfc8
commit
566979cc31
|
@ -63,20 +63,19 @@ public class FileUserPasswdStoreTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void shutdown() throws InterruptedException {
|
public void shutdown() {
|
||||||
terminate(threadPool);
|
terminate(threadPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStore_ConfiguredWithUnreadableFile() throws Exception {
|
public void testStore_ConfiguredWithUnreadableFile() throws Exception {
|
||||||
Path xpackConf = env.configFile();
|
Path configDir = env.configFile();
|
||||||
Files.createDirectories(xpackConf);
|
Files.createDirectories(configDir);
|
||||||
Path file = xpackConf.resolve("users");
|
Path file = configDir.resolve("users");
|
||||||
|
|
||||||
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8
|
// 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);
|
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();
|
||||||
RealmConfig config = getRealmConfig(fileSettings);
|
|
||||||
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
||||||
FileUserPasswdStore store = new FileUserPasswdStore(config, watcherService);
|
FileUserPasswdStore store = new FileUserPasswdStore(config, watcherService);
|
||||||
assertThat(store.usersCount(), is(0));
|
assertThat(store.usersCount(), is(0));
|
||||||
|
@ -84,13 +83,12 @@ public class FileUserPasswdStoreTests extends ESTestCase {
|
||||||
|
|
||||||
public void testStore_AutoReload() throws Exception {
|
public void testStore_AutoReload() throws Exception {
|
||||||
Path users = getDataPath("users");
|
Path users = getDataPath("users");
|
||||||
Path xpackConf = env.configFile();
|
Path configDir = env.configFile();
|
||||||
Files.createDirectories(xpackConf);
|
Files.createDirectories(configDir);
|
||||||
Path file = xpackConf.resolve("users");
|
Path file = configDir.resolve("users");
|
||||||
Files.copy(users, file, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(users, file, StandardCopyOption.REPLACE_EXISTING);
|
||||||
final Hasher hasher = Hasher.resolve(settings.get("xpack.security.authc.password_hashing.algorithm"));
|
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();
|
||||||
RealmConfig config = getRealmConfig(fileSettings);
|
|
||||||
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@ -120,23 +118,19 @@ public class FileUserPasswdStoreTests extends ESTestCase {
|
||||||
assertThat(result.getUser(), is(user));
|
assertThat(result.getUser(), is(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
private RealmConfig getRealmConfig(Settings fileSettings) {
|
private RealmConfig getRealmConfig() {
|
||||||
final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier("file", "file-test");
|
final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier("file", "file-test");
|
||||||
return new RealmConfig(identifier, settings, env, threadPool.getThreadContext());
|
return new RealmConfig(identifier, settings, env, threadPool.getThreadContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStore_AutoReload_WithParseFailures() throws Exception {
|
public void testStore_AutoReload_WithParseFailures() throws Exception {
|
||||||
Path users = getDataPath("users");
|
Path users = getDataPath("users");
|
||||||
Path xpackConf = env.configFile();
|
Path confDir = env.configFile();
|
||||||
Files.createDirectories(xpackConf);
|
Files.createDirectories(confDir);
|
||||||
Path testUsers = xpackConf.resolve("users");
|
Path testUsers = confDir.resolve("users");
|
||||||
Files.copy(users, testUsers, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(users, testUsers, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
Settings fileSettings = Settings.builder()
|
RealmConfig config = getRealmConfig();
|
||||||
.put("files.users", testUsers.toAbsolutePath())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
RealmConfig config = getRealmConfig(fileSettings);
|
|
||||||
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@ -192,6 +186,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
|
||||||
Path empty = createTempFile();
|
Path empty = createTempFile();
|
||||||
Logger logger = CapturingLogger.newCapturingLogger(Level.DEBUG, null);
|
Logger logger = CapturingLogger.newCapturingLogger(Level.DEBUG, null);
|
||||||
Map<String, char[]> users = FileUserPasswdStore.parseFile(empty, logger, Settings.EMPTY);
|
Map<String, char[]> users = FileUserPasswdStore.parseFile(empty, logger, Settings.EMPTY);
|
||||||
|
assertThat(users, notNullValue());
|
||||||
assertThat(users.isEmpty(), is(true));
|
assertThat(users.isEmpty(), is(true));
|
||||||
List<String> events = CapturingLogger.output(logger.getName(), Level.DEBUG);
|
List<String> events = CapturingLogger.output(logger.getName(), Level.DEBUG);
|
||||||
assertThat(events.size(), is(1));
|
assertThat(events.size(), is(1));
|
||||||
|
|
Loading…
Reference in New Issue