Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webapp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-214
ul2024
webapp-lib
Commits
ff3fdf04
Commit
ff3fdf04
authored
6 months ago
by
Clément Pit-Claudel
Browse files
Options
Downloads
Patches
Plain Diff
tests: Simplify decorators suite
parent
79b1d16b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jvm/src/test/scala/cs214/webapp/DecoratorsSuite.scala
+14
-17
14 additions, 17 deletions
jvm/src/test/scala/cs214/webapp/DecoratorsSuite.scala
with
14 additions
and
17 deletions
jvm/src/test/scala/cs214/webapp/DecoratorsSuite.scala
+
14
−
17
View file @
ff3fdf04
package
cs214.webapp.server.web
import
cask.router.Result
import
cask.model.Request
import
io.undertow.util.Headers
import
cask.endpoints.WebsocketResult
import
io.undertow.server.HttpServerExchange
class
DecoratorsSuite
extends
munit
.
FunSuite
:
val
exchange
=
io
.
undertow
.
server
.
HttpServerExchange
(
null
)
val
request
=
Request
(
exchange
,
Nil
)
val
delegate
=
new
decorator
.
Delegate
:
def
apply
(
v1:
Map
[
String
,
Any
])
:
cask.router.Result
[
WebsocketResult
]
=
cask
.
router
.
Result
.
Success
:
cask.model.Response
(
"
OK
"
,
200
)
val
decorator
=
decorators
.
checkOriginHeader
()
def
decoratorStatusCode
:
Int
=
decorator
.
wrapFunction
(
request
,
delegate
)
match
case
Result
.
Success
(
resp
:
WebsocketResult.Response
[
?
])
=>
val
delegate
:
decorator.Delegate
=
_
=>
cask
.
router
.
Result
.
Success
:
cask.model.Response
(
"
OK
"
,
200
)
def
decoratorStatusCode
(
exchange
:
HttpServerExchange
)
:
Int
=
decorator
.
wrapFunction
(
cask
.
model
.
Request
(
exchange
,
Nil
),
delegate
)
match
case
cask
.
router
.
Result
.
Success
(
resp
:
WebsocketResult.Response
[
?
])
=>
resp
.
value
.
statusCode
case
_
=>
fail
(
"Unexpected return value from decorator"
)
test
(
"checkOriginHeader: Valid origin"
)
:
val
exchange
=
io
.
undertow
.
server
.
HttpServerExchange
(
null
)
exchange
.
getRequestHeaders
.
put
(
Headers
.
HOST
,
"example.com"
)
exchange
.
getRequestHeaders
.
put
(
Headers
.
ORIGIN
,
s
"http://example.com"
)
assertEquals
(
decoratorStatusCode
,
200
)
assertEquals
(
decoratorStatusCode
(
exchange
)
,
200
)
exchange
.
getRequestHeaders
.
put
(
Headers
.
ORIGIN
,
s
"https://example.com"
)
assertEquals
(
decoratorStatusCode
,
200
)
assertEquals
(
decoratorStatusCode
(
exchange
)
,
200
)
test
(
"checkOriginHeader: Invalid origin"
)
:
val
exchange
=
io
.
undertow
.
server
.
HttpServerExchange
(
null
)
exchange
.
getRequestHeaders
.
put
(
Headers
.
HOST
,
"example.com"
)
exchange
.
getRequestHeaders
.
put
(
Headers
.
ORIGIN
,
s
"http://cs-214.epfl.ch"
)
assertEquals
(
decoratorStatusCode
,
403
)
assertEquals
(
decoratorStatusCode
(
exchange
)
,
403
)
exchange
.
getRequestHeaders
.
put
(
Headers
.
ORIGIN
,
s
"https://cs-214.epfl.ch"
)
assertEquals
(
decoratorStatusCode
,
403
)
assertEquals
(
decoratorStatusCode
(
exchange
)
,
403
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment