Skip to content

Commit

Permalink
Restrict the following DSLs to prevent sessions named child window or…
Browse files Browse the repository at this point in the history
… child tab
  • Loading branch information
bjuric committed Aug 20, 2024
1 parent 3185a30 commit 573e934
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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 <name>`
- `I switch to <name>`
- `I close the browser for <name>`

3.72.1
======
18 August 2024
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/gwen/web/eval/WebErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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("")}")

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 573e934

Please sign in to comment.