• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tomdesair / tus-java-server / 29044436517

09 Jul 2026 07:28PM UTC coverage: 94.953% (+0.2%) from 94.787%
29044436517

push

github

web-flow
Implement creation-with-upload, CORS, and protocol compliance fixes (#108)

* Implement creation-with-upload (#62), CORS, and protocol compliance fixes

723 of 816 branches covered (88.6%)

Branch coverage included in aggregate %.

155 of 156 new or added lines in 19 files covered. (99.36%)

1986 of 2037 relevant lines covered (97.5%)

6.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/main/java/me/desair/tus/server/creation/validation/UploadMetadataValidator.java
1
package me.desair.tus.server.creation.validation;
2

3
import jakarta.servlet.http.HttpServletRequest;
4
import jakarta.servlet.http.HttpServletResponse;
5
import me.desair.tus.server.HttpHeader;
6
import me.desair.tus.server.HttpMethod;
7
import me.desair.tus.server.RequestValidator;
8
import me.desair.tus.server.exception.TusException;
9
import me.desair.tus.server.upload.UploadStorageService;
10
import me.desair.tus.server.util.Utils;
11
import org.apache.commons.codec.binary.Base64;
12
import org.apache.commons.lang3.StringUtils;
13

14
/**
15
 * Validator that ensures the Upload-Metadata header adheres to formatting guidelines and has valid
16
 * Base64 values.
17
 */
18
public class UploadMetadataValidator implements RequestValidator {
6✔
19

20
  @Override
21
  public void validate(
22
      HttpMethod method,
23
      HttpServletRequest request,
24
      UploadStorageService uploadStorageService,
25
      String ownerKey)
26
      throws TusException {
27

28
    String metadata = Utils.getHeader(request, HttpHeader.UPLOAD_METADATA);
8✔
29
    if (StringUtils.isNotBlank(metadata)) {
6✔
30
      String[] pairs = metadata.split(",");
8✔
31
      for (String pair : pairs) {
32✔
32
        pair = pair.trim();
6✔
33
        if (StringUtils.isBlank(pair)) {
6✔
34
          throw new TusException(
6✔
35
              HttpServletResponse.SC_BAD_REQUEST, "Upload-Metadata cannot contain empty pairs");
36
        }
37

38
        String[] keyValue = pair.split(" ");
8✔
39
        if (keyValue.length > 2) {
8✔
40
          throw new TusException(
6✔
41
              HttpServletResponse.SC_BAD_REQUEST,
42
              "Upload-Metadata key-value pairs must be separated by a single space");
43
        }
44

45
        String key = keyValue[0];
8✔
46
        if (StringUtils.isBlank(key)) {
6!
NEW
47
          throw new TusException(
×
48
              HttpServletResponse.SC_BAD_REQUEST, "Upload-Metadata key cannot be empty");
49
        }
50

51
        if (keyValue.length == 2) {
8✔
52
          String value = keyValue[1];
8✔
53
          if (!Base64.isBase64(value)) {
6✔
54
            throw new TusException(
6✔
55
                HttpServletResponse.SC_BAD_REQUEST,
56
                "Upload-Metadata value must be a valid Base64 encoded string");
57
          }
58
        }
59
      }
60
    }
61
  }
2✔
62

63
  @Override
64
  public boolean supports(HttpMethod method) {
65
    return HttpMethod.POST.equals(method);
8✔
66
  }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc