import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Objects;
assertEquals(8443, httpsPort);
}
+ @Test
+ public void shouldReturnConfigurationUpdateInterval() throws IOException {
+ // when
+ int updateFrequency = fromTemporaryConfiguration("collector.dynamic.config.update.frequency=10")
+ .configurationUpdateFrequency();
+
+ // then
+ assertEquals(10, updateFrequency);
+ }
+
+ @Test
+ public void shouldReturnDefaultConfigurationUpdateInterval() throws IOException {
+ // when
+ int updateFrequency = fromTemporaryConfiguration()
+ .configurationUpdateFrequency();
+
+ // then
+ assertEquals(5, updateFrequency);
+ }
+
@Test
public void shouldReturnLocationOfThePasswordFile() throws IOException {
// when
String passwordFileLocation = fromTemporaryConfiguration("collector.keystore.passwordfile=/somewhere/password").keystorePasswordFileLocation();
// then
- assertEquals("/somewhere/password", passwordFileLocation);
+ assertEquals(sanitizePath("/somewhere/password"), passwordFileLocation);
}
@Test
String passwordFileLocation = fromTemporaryConfiguration().keystorePasswordFileLocation();
// then
- assertEquals("./etc/passwordfile", passwordFileLocation);
+ assertEquals(sanitizePath("etc/passwordfile"), passwordFileLocation);
}
@Test
.keystoreFileLocation();
// then
- assertEquals("/somewhere/keystore", keystoreFileLocation);
+ assertEquals(sanitizePath("/somewhere/keystore"), keystoreFileLocation);
}
@Test
String keystoreFileLocation = fromTemporaryConfiguration().keystoreFileLocation();
// then
- assertEquals("../etc/keystore", keystoreFileLocation);
+ assertEquals(sanitizePath("etc/keystore"), keystoreFileLocation);
}
@Test
public void shouldReturnDMAAPConfigFileLocation() throws IOException {
// when
- String dmaapConfigFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapFile").cambriaConfigurationFileLocation();
+ String dmaapConfigFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapFile").dMaaPConfigurationFileLocation();
// then
- assertEquals("/somewhere/dmaapFile", dmaapConfigFileLocation);
+ assertEquals(sanitizePath("/somewhere/dmaapFile"), dmaapConfigFileLocation);
}
@Test
public void shouldReturnDefaultDMAAPConfigFileLocation() throws IOException {
// when
- String dmaapConfigFileLocation = fromTemporaryConfiguration().cambriaConfigurationFileLocation();
+ String dmaapConfigFileLocation = fromTemporaryConfiguration().dMaaPConfigurationFileLocation();
// then
- assertEquals("./etc/DmaapConfig.json", dmaapConfigFileLocation);
+ assertEquals(sanitizePath("etc/DmaapConfig.json"), dmaapConfigFileLocation);
}
@Test
@Test
public void shouldReturnValidCredentials() throws IOException {
// when
- String userToBase64PasswordDelimitedByCommaSeparatedByPipes = fromTemporaryConfiguration(
- "header.authlist=pasza,123jsad1|someoneelse,12asd31"
+ Map<String, String> allowedUsers = fromTemporaryConfiguration(
+ "header.authlist=pasza,c2ltcGxlcGFzc3dvcmQNCg==|someoneelse,c2ltcGxlcGFzc3dvcmQNCg=="
).validAuthorizationCredentials();
// then
- assertEquals("pasza,123jsad1|someoneelse,12asd31", userToBase64PasswordDelimitedByCommaSeparatedByPipes);
+ assertEquals(allowedUsers.get("pasza").get(), "simplepassword");
+ assertEquals(allowedUsers.get("someoneelse").get(), "simplepassword");
}
@Test
public void shouldbyDefaultThereShouldBeNoValidCredentials() throws IOException {
// when
- String userToBase64PasswordDelimitedByCommaSeparatedByPipes = fromTemporaryConfiguration().
+ Map<String, String> userToBase64PasswordDelimitedByCommaSeparatedByPipes = fromTemporaryConfiguration().
validAuthorizationCredentials();
// then
- assertNull(userToBase64PasswordDelimitedByCommaSeparatedByPipes);
+ assertTrue(userToBase64PasswordDelimitedByCommaSeparatedByPipes.isEmpty());
}
-
@Test
public void shouldReturnIfEventTransformingIsEnabled() throws IOException {
// when
public void shouldReturnCambriaConfigurationFileLocation() throws IOException {
// when
String cambriaConfigurationFileLocation = fromTemporaryConfiguration("collector.dmaapfile=/somewhere/dmaapConfig")
- .cambriaConfigurationFileLocation();
+ .dMaaPConfigurationFileLocation();
// then
- assertEquals("/somewhere/dmaapConfig", cambriaConfigurationFileLocation);
+ assertEquals(sanitizePath("/somewhere/dmaapConfig"), cambriaConfigurationFileLocation);
}
@Test
public void shouldReturnDefaultCambriaConfigurationFileLocation() throws IOException {
// when
String cambriaConfigurationFileLocation = fromTemporaryConfiguration()
- .cambriaConfigurationFileLocation();
+ .dMaaPConfigurationFileLocation();
// then
- assertEquals("./etc/DmaapConfig.json", cambriaConfigurationFileLocation);
+ assertEquals(sanitizePath("etc/DmaapConfig.json"), cambriaConfigurationFileLocation);
}
private static ApplicationSettings fromTemporaryConfiguration(String... fileLines)
File tempConfFile = File.createTempFile("doesNotMatter", "doesNotMatter");
Files.write(tempConfFile.toPath(), Arrays.asList(fileLines));
tempConfFile.deleteOnExit();
- return new ApplicationSettings(new String[]{"-c", tempConfFile.toString()}, args -> processCmdLine(args));
+ return new ApplicationSettings(new String[]{"-c", tempConfFile.toString()}, args -> processCmdLine(args), "");
}
-
+ private String sanitizePath(String path) {
+ return Paths.get(path).toString();
+ }
}
\ No newline at end of file