Skip to content

Commit b5b0cae

Browse files
committed
Additional testing on PostURIValidator for upload URI regex support
1 parent fd2f975 commit b5b0cae

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The first step is to create a `TusFileUploadService` object using its constructo
4040

4141
* `withUploadURI(String)`: Set the relative URL under which the main tus upload endpoint will be made available, for example `/files/upload`. Optionally, this URI may contain regex parameters in order to support endpoints that contain URL parameters, for example `/users/[0-9]+/files/upload`.
4242
* `withMaxUploadSize(Long)`: Specify the maximum number of bytes that can be uploaded per upload. If you don't call this method, the maximum number of bytes is `Long.MAX_VALUE`.
43-
* `withStoragePath(String)`: If you're using the default filesystem-based storage service, you can use this method to specify the path where to store the uploaded bytes and upload information.
43+
* `withStoragePath(String)`: If you're using the default file system-based storage service, you can use this method to specify the path where to store the uploaded bytes and upload information.
4444
* `withChunkedTransferDecoding`: You can enable or disable the decoding of chunked HTTP requests by this library. Enable this feature in case the web container in which this service is running does not decode chunked transfers itself. By default, chunked decoding via this library is disabled (as modern frameworks tend to already do this for you).
4545
* `withThreadLocalCache(Boolean)`: Optionally you can enable (or disable) an in-memory (thread local) cache of upload request data to reduce load on the storage backend and potentially increase performance when processing upload requests.
4646
* `withUploadExpirationPeriod(Long)`: You can set the number of milliseconds after which an upload is considered as expired and available for cleanup.
@@ -49,7 +49,7 @@ The first step is to create a `TusFileUploadService` object using its constructo
4949
* `disableTusExtension(String)`: Disable the `TusExtension` for which the `getName()` method matches the provided string. The default extensions have names "creation", "checksum", "expiration", "concatenation", "termination" and "download". You cannot disable the "core" feature.
5050

5151

52-
For now this library only provides filesystem-based storage and locking options. You can however provide your own implementation of a `UploadStorageService` and `UploadLockingService` using the methods `withUploadStorageService(UploadStorageService)` and `withUploadLockingService(UploadLockingService)` in order to support different types of upload storage.
52+
For now this library only provides file system-based storage and locking options. You can however provide your own implementation of a `UploadStorageService` and `UploadLockingService` using the methods `withUploadStorageService(UploadStorageService)` and `withUploadLockingService(UploadLockingService)` in order to support different types of upload storage.
5353

5454
### 2. Processing an upload
5555
To process an upload request you have to pass the current `javax.servlet.http.HttpServletRequest` and `javax.servlet.http.HttpServletResponse` objects to the `me.desair.tus.server.TusFileUploadService.process()` method. Typical places were you can do this are inside Servlets, Filters or REST API Controllers (see [examples](#quick-start-and-examples)).

src/main/java/me/desair/tus/server/TusFileUploadService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public TusFileUploadService withUploadLockingService(UploadLockingService upload
130130
}
131131

132132
/**
133-
* If you're using the default filesystem-based storage service, you can use this method to
133+
* If you're using the default file system-based storage service, you can use this method to
134134
* specify the path where to store the uploaded bytes and upload information.
135135
*
136136
* @param storagePath The file system path where uploads can be stored (temporarily)
@@ -192,9 +192,9 @@ public TusFileUploadService withDownloadFeature() {
192192
}
193193

194194
/**
195-
* Add a custom (application-specific) extension that implements the `me.desair.tus.server.TusExtension` interface.
196-
* For example you can add your own extension that checks authentication and authorization policies within your
197-
* application for the user doing the upload.
195+
* Add a custom (application-specific) extension that implements the {@link me.desair.tus.server.TusExtension}
196+
* interface. For example you can add your own extension that checks authentication and authorization policies
197+
* within your application for the user doing the upload.
198198
*
199199
* @param feature The custom extension implementation
200200
* @return The current service

src/test/java/me/desair/tus/server/creation/validation/PostURIValidatorTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,38 @@ public void validateInvalidUrl() throws Exception {
6666

6767
//Expect PostOnInvalidRequestURIException
6868
}
69+
70+
@Test
71+
public void validateMatchingRegexUrl() throws Exception {
72+
servletRequest.setRequestURI("/users/1234/files/upload");
73+
when(uploadStorageService.getUploadURI()).thenReturn("/users/[0-9]+/files/upload");
74+
75+
try {
76+
validator.validate(HttpMethod.POST, servletRequest, uploadStorageService, null);
77+
} catch (Exception ex) {
78+
fail();
79+
}
80+
81+
//No Exception is thrown
82+
}
83+
84+
@Test(expected = PostOnInvalidRequestURIException.class)
85+
public void validateInvalidRegexUrl() throws Exception {
86+
servletRequest.setRequestURI("/users/abc123/files/upload");
87+
when(uploadStorageService.getUploadURI()).thenReturn("/users/[0-9]+/files/upload");
88+
89+
validator.validate(HttpMethod.POST, servletRequest, uploadStorageService, null);
90+
91+
//Expect PostOnInvalidRequestURIException
92+
}
93+
94+
@Test(expected = PostOnInvalidRequestURIException.class)
95+
public void validateInvalidRegexUrlPatchUrl() throws Exception {
96+
servletRequest.setRequestURI("/users/1234/files/upload/7669c72a-3f2a-451f-a3b9-9210e7a4c02f");
97+
when(uploadStorageService.getUploadURI()).thenReturn("/users/[0-9]+/files/upload");
98+
99+
validator.validate(HttpMethod.POST, servletRequest, uploadStorageService, null);
100+
101+
//Expect PostOnInvalidRequestURIException
102+
}
69103
}

0 commit comments

Comments
 (0)