vttranlina commented on a change in pull request #517:
URL: https://github.com/apache/james-project/pull/517#discussion_r663674253
##########
File path:
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/http/BasicAuthenticationStrategy.scala
##########
@@ -40,8 +40,30 @@ import scala.jdk.CollectionConverters._
import scala.util.{Failure, Success, Try}
object UserCredential {
- type BasicAuthenticationHeaderValue = String Refined MatchesRegex["Basic
[\\d\\w=]++"]
- type CredentialsAsString = String Refined MatchesRegex[".*:.*"]
+ type BasicAuthenticationHeaderValue = String Refined
BasicAuthenticationHeaderValueConstraint
+
+ type CredentialsAsString = String Refined CredentialsAsStringConstraint
+
+ case class CredentialsAsStringConstraint()
+ case class BasicAuthenticationHeaderValueConstraint()
+
+ private val charMatcher: CharMatcher = CharMatcher.inRange('a', 'z')
+ .or(CharMatcher.inRange('0', '9'))
+ .or(CharMatcher.inRange('A', 'Z'))
+ .or(CharMatcher.is('_'))
+ .or(CharMatcher.is('='))
+ .or(CharMatcher.is('-'))
+ .or(CharMatcher.is('#'))
+
+ implicit val validateCredentialsAsString: Validate.Plain[String,
CredentialsAsStringConstraint] =
+ Validate.fromPredicate(s => s.contains(':'),
+ _ => "Credential string must contains ':'",
+ CredentialsAsStringConstraint())
+
+ implicit val validateBasicAuthenticationHeaderValueConstraint:
Validate.Plain[String, BasicAuthenticationHeaderValueConstraint] =
+ Validate.fromPredicate(s => s.startsWith("Basic ") &&
charMatcher.matchesAllOf(s.substring(6)),
+ _ => "Must start with 'Basic' prefix then be only letter or digits",
Review comment:
'Basic' or 'Basic '
Ignore if it is unnecessary :D
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]