Added input validation to the Authentication middleware (#5)
This PR contains the work done to improve the existing `AuthMiddleware` type to provide input validations with the `SecureValidationRule` validation rule and also, by generating the authentication information at initialization time. Reviewed-on: #5 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -29,6 +29,17 @@ struct NotNilValidationRule: InputValidationRule {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Definitions
|
||||
|
||||
extension InputValidationRule where Self == NotNilValidationRule {
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
/// A validation rule that checks whether an input is nil or not.
|
||||
static var notNil: Self { .init() }
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private extension NotNilValidationRule {
|
||||
@@ -43,7 +54,7 @@ private extension NotNilValidationRule {
|
||||
/// - Returns: A flag that indicates whether a given input has been validated or not.
|
||||
/// - Throws: An error of type ``InputValidatorError`` in case the validation failed.
|
||||
func validate(input: String?) throws -> Bool {
|
||||
guard let input else {
|
||||
guard input != nil else {
|
||||
throw InputValidationError.inputIsNil
|
||||
}
|
||||
|
||||
@@ -51,10 +62,3 @@ private extension NotNilValidationRule {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
extension InputValidationRule where Self == NotNilValidationRule {
|
||||
/// A validation rule that checks whether an input is nil or not.
|
||||
static var notNil: Self { .init() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user