@Test
  public void testNamedBlobPutWithViolatedBlobName() throws Exception {
    Account testAccount = new ArrayList<>(accountService.getAllAccounts()).get(1);
    Container testContainer = new ArrayList<>(testAccount.getAllContainers()).get(1);

    List<String> invalidBlobNames = Arrays.asList(
        "file  name.txt",         // consecutive spaces
        "  startsWithSpaces",     // leading spaces
        "endsWithSpaces  ",       // trailing spaces
        "file\u0000name.txt",     // null byte
        "line\nbreak.txt",        // newline
        "tab\tname.txt",          // tab
        "file|name.txt",          // |
        "invalid<name>.txt",      // <
        "slash\\backslash.txt",   // \
        "curly{name}.txt",        // {
        "quote\"name.txt",        // "
        "caret^name.txt",         // ^
        "percent%name.txt",       // %
        "tick`name.txt",          // `
        "brackets[name].txt",     // [ and ]
        "tilde~name.txt",         // ~
        "hash#name.txt",          // #
        "../secret.txt",          // path traversal
        "./relative.txt",
        "foo/../bar.txt",
        "foo/./bar.txt"
    );

    ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes(10));
    List<ByteBuffer> body = new LinkedList<>();
    body.add(content);
    body.add(null);

    for (String blobName : invalidBlobNames) {
      String encodedBlobName = URLEncoder.encode(blobName, StandardCharsets.UTF_8.toString()).replace("+", "%20");

      String namedBlobPathUri = NAMED_BLOB_PREFIX + SLASH + testAccount.getName() +
          SLASH + testContainer.getName() + SLASH + encodedBlobName;

      JSONObject headers = new JSONObject()
          .put(RestUtils.Headers.TARGET_ACCOUNT_NAME, testAccount.getName())
          .put(RestUtils.Headers.TARGET_CONTAINER_NAME, testContainer.getName());

      setAmbryHeadersForPut(headers, -1, testContainer.isCacheable(),
          "test", "application/octet-stream", "owner", null, null, null);

      RestRequest restRequest = createRestRequest(RestMethod.PUT, namedBlobPathUri, headers, body);
      verifyOperationFailure(restRequest, RestServiceErrorCode.BadRequest);
    }
  }
Test blob name validation logic.
@throws Exception
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendRestRequestServiceTest.java