Skip to content

Commit

Permalink
Response to reviews - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
istreeter committed Nov 1, 2022
1 parent f533bce commit b907e1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ final case class YauaaEnrichment(cacheSize: Option[Int]) extends Enrichment {
* @return Attributes retrieved thanks to the user agent (if any), as self-describing JSON.
*/
def getYauaaContext(userAgent: String, headers: List[String]): SelfDescribingData[Json] =
SelfDescribingData(YauaaEnrichment.outputSchema, parseUserAgent(userAgent, headers).asJson)
SelfDescribingData(YauaaEnrichment.outputSchema, analyzeUserAgent(userAgent, headers).asJson)

/**
* Gets the map of attributes retrieved by YAUAA from the user agent.
* @return Map with all the fields extracted by YAUAA by parsing the user agent.
* If the input is null or empty, a map with just the DeviceClass set to Unknown is returned.
*/
def parseUserAgent(userAgent: String, headers: List[String]): Map[String, String] =
def analyzeUserAgent(userAgent: String, headers: List[String]): Map[String, String] =
userAgent match {
case null | "" =>
YauaaEnrichment.DefaultResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class YauaaEnrichmentSpec extends Specification with ValidatedMatchers {

"YAUAA enrichment should" >> {
"return default value for null" >> {
yauaaEnrichment.parseUserAgent(null, Nil) shouldEqual YauaaEnrichment.DefaultResult
yauaaEnrichment.analyzeUserAgent(null, Nil) shouldEqual YauaaEnrichment.DefaultResult
}

"return default value for empty user agent" >> {
yauaaEnrichment.parseUserAgent("", Nil) shouldEqual YauaaEnrichment.DefaultResult
yauaaEnrichment.analyzeUserAgent("", Nil) shouldEqual YauaaEnrichment.DefaultResult
}

"detect correctly DeviceClass" >> {
Expand Down Expand Up @@ -187,14 +187,14 @@ class YauaaEnrichmentSpec extends Specification with ValidatedMatchers {
"use client hint headers to aid parsing" >> {
val clientHintHeader =
"""Sec-CH-UA-Full-Version-List: "Chromium";v="106.0.5249.119", "Google Chrome";v="106.0.5249.119", "Not;A=Brand";v="99.0.0.0""""
yauaaEnrichment.parseUserAgent(uaChrome106, Nil)("agentNameVersion") shouldEqual "Chrome 106"
yauaaEnrichment.parseUserAgent(uaChrome106, List(clientHintHeader))("agentNameVersion") shouldEqual "Chrome 106.0.5249.119"
yauaaEnrichment.analyzeUserAgent(uaChrome106, Nil)("agentNameVersion") shouldEqual "Chrome 106"
yauaaEnrichment.analyzeUserAgent(uaChrome106, List(clientHintHeader))("agentNameVersion") shouldEqual "Chrome 106.0.5249.119"
}

/** Resembles the case when `ua` was sent as a field in the tp2 payload */
"Prioritize explicitly passed user agent over an http header" >> {
val headers = List("User-Agent: curl/7.54")
yauaaEnrichment.parseUserAgent(uaFirefox, headers)("agentName") shouldEqual "Firefox"
yauaaEnrichment.analyzeUserAgent(uaFirefox, headers)("agentName") shouldEqual "Firefox"
}

"create a JSON with the schema 1-0-4 and the data" >> {
Expand Down Expand Up @@ -246,15 +246,15 @@ class YauaaEnrichmentSpec extends Specification with ValidatedMatchers {
"never add __SyntaxError__ to the context" >> {
val ua =
"useragent=Mozilla/5.0 (Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 OPR/25.0.1620.0 OMI/4.3.18.7.Dominik.0 VSTVB MB100 HbbTV/1.2.1 (; PANASONIC; MB100; 0.1.34.28; ;) SmartTvA/3.0.0 UID (00:09:DF:A7:74:6B/MB100/PANASONIC/0.1.34.28)"
yauaaEnrichment.parseUserAgent(ua, Nil).contains("__SyntaxError__") shouldEqual false
yauaaEnrichment.analyzeUserAgent(ua, Nil).contains("__SyntaxError__") shouldEqual false
}
}

/** Helper to check that a certain field of a parsed user agent has the expected value. */
def checkYauaaParsingForField(expectedResults: Map[String, String], fieldName: String) =
expectedResults.map {
case (userAgent, expectedField) =>
yauaaEnrichment.parseUserAgent(userAgent, Nil)(decapitalize(fieldName)) shouldEqual expectedField
yauaaEnrichment.analyzeUserAgent(userAgent, Nil)(decapitalize(fieldName)) shouldEqual expectedField
}.toList

"decapitalize should" >> {
Expand Down

0 comments on commit b907e1f

Please sign in to comment.