Utilities { public static boolean validName(String name) { return !name.startsWith(".") && name.matches(VALID_NAME_PATTERN); }  static boolean validName(String name); static final String VALID_NAME_PATTERN; }
@Test public void validateNameReturnsTrueOnValidNames() throws Exception { assertThat(validName("hello")).isTrue(); assertThat(validName("hello_world")).isTrue(); assertThat(validName("Hello-World")).isTrue(); assertThat(validName("foo.yml")).isTrue(); assertThat(validName("I_am_secret.yml")).isTrue(); assertThat(validName("I-am-secret.yml")).isTrue(); }
@Test public void validateNameReturnsFalseOnInvalidNames() throws Exception { assertThat(validName("hello!")).isFalse(); assertThat(validName("hello world")).isFalse(); assertThat(validName("$$ bill yall")).isFalse(); assertThat(validName("blah/../../../etc/passwd")).isFalse(); assertThat(validName("bad/I-am-secret.yml")).isFalse(); assertThat(validName(".almostvalid")).isFalse(); assertThat(validName("bad\tI-am-secret.yml")).isFalse(); List<String> specialCharacters = Arrays.asList("&", "|", "(", ")", "[", "]", "{", "}", "^", ";", ",", "\\", "/", "<", ">", "\t", "\n", "\r", "`", "'", "\"", "?", "#", "%", "*", "+", "=", "\0", "\u0002", "\000"); for (String name : specialCharacters) { assertFalse("Failed character: \"" + name + '"', validName(name)); } }