From 573e9341d7716016ba3c7fab8cbe6d5eabfd6138 Mon Sep 17 00:00:00 2001 From: Branko Juric Date: Tue, 20 Aug 2024 14:12:45 +1000 Subject: [PATCH] Restrict the following DSLs to prevent sessions named child window or child tab --- CHANGELOG | 8 ++++++++ build.sbt | 2 +- src/main/scala/gwen/web/eval/WebErrors.scala | 5 +++++ .../gwen/web/eval/lambda/unit/OpenOrCloseBrowser.scala | 4 ++++ .../gwen/web/eval/lambda/unit/StartBrowserSession.scala | 2 ++ .../web/eval/lambda/unit/SwitchToBrowserSession.scala | 2 ++ 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8b6d229b..d40bbb15 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,11 @@ +3.72.2 +====== +20 August 2024 +- Restrict the following DSLs to prevent sessions named "child window" or "child tab" + - `I start a browser for ` + - `I switch to ` + - `I close the browser for ` + 3.72.1 ====== 18 August 2024 diff --git a/build.sbt b/build.sbt index f95e2940..a01b8b8a 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ enablePlugins(GitVersioning) // gwen core & web versions val gwenVersion = "3.61.4" -val gwenWebVersion = "3.72.1" +val gwenWebVersion = "3.72.2" git.baseVersion := gwenWebVersion git.useGitDescribe := true diff --git a/src/main/scala/gwen/web/eval/WebErrors.scala b/src/main/scala/gwen/web/eval/WebErrors.scala index 4bbfa297..3ed11ed0 100644 --- a/src/main/scala/gwen/web/eval/WebErrors.scala +++ b/src/main/scala/gwen/web/eval/WebErrors.scala @@ -43,6 +43,7 @@ object WebErrors { def invalidActionError(action: ElementAction) = throw new InvalidActionException(action) def invalidSelectorTypeError(selectorType: String) = throw new InvalidSelectorTypeException(selectorType) def multipleBrowserSettingsError(settingsFiles: List[File]) = throw new MultipleBrowserSettingsException(settingsFiles) + def illegalSessionNameError(name: String, msg: Option[String]) = throw new IllegalSessionNameException(name, msg) /** Thrown when a locator binding error is detected . */ class LocatorBindingException(msg: String) extends GwenException(msg) @@ -89,4 +90,8 @@ object WebErrors { /** Thrown when more than one browser setting file is active.*/ class MultipleBrowserSettingsException(settingsFiles: List[File]) extends GwenException(s"Multiple browser settings provided (only 1 expected): ${settingsFiles.mkString(", ")}") + /** Thrown when an unsupported web driver is detected. */ + class IllegalSessionNameException(name: String, msg: Option[String]) + extends GwenException(s"Illegal (reserved) browser session name: $name${msg.map(m => s". $m").getOrElse("")}") + } \ No newline at end of file diff --git a/src/main/scala/gwen/web/eval/lambda/unit/OpenOrCloseBrowser.scala b/src/main/scala/gwen/web/eval/lambda/unit/OpenOrCloseBrowser.scala index 0576fb81..e395a728 100644 --- a/src/main/scala/gwen/web/eval/lambda/unit/OpenOrCloseBrowser.scala +++ b/src/main/scala/gwen/web/eval/lambda/unit/OpenOrCloseBrowser.scala @@ -17,6 +17,7 @@ package gwen.web.eval.lambda.unit import gwen.web.eval.WebContext +import gwen.web.eval.WebErrors import gwen.core.behavior.BehaviorType import gwen.core.eval.lambda.UnitStep @@ -28,6 +29,9 @@ import scala.util.chaining._ class OpenOrCloseBrowser(open: Boolean, name: Option[String], behaviorType: BehaviorType) extends UnitStep[WebContext] { override def apply(parent: GwenNode, step: Step, ctx: WebContext): Step = { + name.filter(_.matches("child (window|tab)")) foreach { n => + WebErrors.illegalSessionNameError(n, None) + } step tap { _ => checkStepRules(step, behaviorType, ctx) if (open) { diff --git a/src/main/scala/gwen/web/eval/lambda/unit/StartBrowserSession.scala b/src/main/scala/gwen/web/eval/lambda/unit/StartBrowserSession.scala index d545d8e4..5a3b0724 100644 --- a/src/main/scala/gwen/web/eval/lambda/unit/StartBrowserSession.scala +++ b/src/main/scala/gwen/web/eval/lambda/unit/StartBrowserSession.scala @@ -17,6 +17,7 @@ package gwen.web.eval.lambda.unit import gwen.web.eval.WebContext +import gwen.web.eval.WebErrors import gwen.core.behavior.BehaviorType import gwen.core.eval.lambda.UnitStep @@ -28,6 +29,7 @@ import scala.util.chaining._ class StartBrowserSession(name: String) extends UnitStep[WebContext] { override def apply(parent: GwenNode, step: Step, ctx: WebContext): Step = { + if (name.matches("child (window|tab)")) WebErrors.illegalSessionNameError(name, None) step tap { _ => checkStepRules(step, BehaviorType.Action, ctx) ctx.close(name) diff --git a/src/main/scala/gwen/web/eval/lambda/unit/SwitchToBrowserSession.scala b/src/main/scala/gwen/web/eval/lambda/unit/SwitchToBrowserSession.scala index 194cc5b4..90c2aef0 100644 --- a/src/main/scala/gwen/web/eval/lambda/unit/SwitchToBrowserSession.scala +++ b/src/main/scala/gwen/web/eval/lambda/unit/SwitchToBrowserSession.scala @@ -17,6 +17,7 @@ package gwen.web.eval.lambda.unit import gwen.web.eval.WebContext +import gwen.web.eval.WebErrors import gwen.core.behavior.BehaviorType import gwen.core.eval.lambda.UnitStep @@ -28,6 +29,7 @@ import scala.util.chaining._ class SwitchToBrowserSession(name: String) extends UnitStep[WebContext] { override def apply(parent: GwenNode, step: Step, ctx: WebContext): Step = { + if (name.matches("child (window|tab)")) WebErrors.illegalSessionNameError(name, Some(s"Did you instead mean to call: I switch to the $name")) step tap { _ => checkStepRules(step, BehaviorType.Action, ctx) ctx.switchToSession(name)