SecretValidation { public static boolean isValidSecretKey(String key) { Preconditions.checkNotNull(key); return key.length() <= MAX_SECRET_KEY_LENGTH && SECRET_KEY_PATTERN.matcher(key).matches(); } private  SecretValidation(); static boolean isValidSecretKey(String key); static boolean isValidSecretValue(String value); static boolean isValidSecret(String key, String value);  }
@Test public void isValidSecretKey() throws Exception { assertThat(SecretValidation.isValidSecretKey(""), is(false)); assertThat(SecretValidation.isValidSecretKey("."), is(false)); assertThat(SecretValidation.isValidSecretKey("0"), is(false)); assertThat(SecretValidation.isValidSecretKey("0.foo"), is(false)); assertThat(SecretValidation.isValidSecretKey("0234"), is(false)); assertThat(SecretValidation.isValidSecretKey("0bar"), is(false)); assertThat(SecretValidation.isValidSecretKey("012bar"), is(false)); assertThat(SecretValidation.isValidSecretKey("foo.0"), is(false)); assertThat(SecretValidation.isValidSecretKey("foo.1"), is(false)); assertThat(SecretValidation.isValidSecretKey("foo.1.baz"), is(false)); assertThat(SecretValidation.isValidSecretKey("foo..baz"), is(false)); assertThat(SecretValidation.isValidSecretKey("\u2603"), is(false)); assertThat(SecretValidation.isValidSecretKey("\uD83D\uDCA9"), is(false)); assertThat(SecretValidation.isValidSecretKey("r\u00e4ksm\u00f6rg\u00e5s"), is(false)); assertThat(SecretValidation.isValidSecretKey("f"), is(true)); assertThat(SecretValidation.isValidSecretKey("foo"), is(true)); assertThat(SecretValidation.isValidSecretKey("foo.b"), is(true)); assertThat(SecretValidation.isValidSecretKey("foo.bar"), is(true)); assertThat(SecretValidation.isValidSecretKey("foo.bar.baz"), is(true)); assertThat(SecretValidation.isValidSecretKey("a1.b2c.d3"), is(true)); }