-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We used UUIDs without hyphens for a period in the past. Modify the BrokerController to allow those. Migrating would be ideal. But migrating IDs is not simple. We have a bigger DB migration planned in the future and will migrate IDs to a single type then.
- Loading branch information
1 parent
dabcf1f
commit c6bcd28
Showing
2 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/com/conveyal/analysis/controllers/ArgumentValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.conveyal.analysis.controllers; | ||
|
||
import com.conveyal.analysis.components.broker.Broker; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Tests that check how parameters received over the HTTP API are validated. | ||
* These validators should be fairly strict about what they accept, and should not tolerate the presence of things | ||
* like semicolons or double dashes that indicate attempts to corrupt or gain access to database contents. | ||
* | ||
* Arguably we should have another layer of input sanitization that not only refuses but logs anything that contains | ||
* characters or substrings that could be associated with an attempted attack, and that same validator should be | ||
* applied to every input (perhaps called from every other input validator). | ||
*/ | ||
public class ArgumentValidationTest { | ||
|
||
@Test | ||
void testIdValidation () { | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> { | ||
BrokerController.checkIdParameter("hello", "param"); | ||
}); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> { | ||
BrokerController.checkIdParameter("Robert'); DROP TABLE Students;--", "param"); | ||
// https://xkcd.com/327/ | ||
}); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> { | ||
BrokerController.checkIdParameter("0123456789012345", "param"); | ||
}); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> { | ||
BrokerController.checkIdParameter("0123456789ABCDEF67890ZZZZ5678901", "param"); | ||
}); | ||
Assertions.assertDoesNotThrow(() -> { | ||
BrokerController.checkIdParameter("0123456789abcDEF6789012345678901", "param"); | ||
}); | ||
Assertions.assertDoesNotThrow(() -> { | ||
String validUuid = UUID.randomUUID().toString(); | ||
BrokerController.checkIdParameter(validUuid, "param"); | ||
}); | ||
} | ||
|
||
|
||
} |