Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
3414de67
Commit
3414de67
authored
Jun 11, 2021
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Attempt to test the CORS behavior
parent
ee5298e3
Branches
Branches containing commit
No related tags found
1 merge request
!87
Add tests for CORS behavior
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/Stripe.hs
+62
-0
62 additions, 0 deletions
test/Stripe.hs
with
62 additions
and
0 deletions
test/Stripe.hs
+
62
−
0
View file @
3414de67
...
...
@@ -16,6 +16,10 @@ import Test.Tasty.HUnit
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Control.Monad.Trans.Except
(
runExceptT
)
...
...
@@ -29,6 +33,21 @@ import Web.Stripe.Types
(
Currency
(
USD
,
AED
)
)
import
Network.Wai.Test
(
SRequest
(
SRequest
)
,
runSession
,
request
,
srequest
,
defaultRequest
,
assertHeader
,
setPath
)
import
Network.Wai
(
requestMethod
,
requestHeaders
)
import
PaymentServer.Persistence
(
memory
)
...
...
@@ -40,6 +59,14 @@ import PaymentServer.Processors.Stripe
)
import
PaymentServer.Issuer
(
trivialIssue
)
import
PaymentServer.Server
(
paymentServerApp
)
import
FakeStripe
(
withFakeStripe
,
chargeOkay
...
...
@@ -48,7 +75,42 @@ import FakeStripe
tests
::
TestTree
tests
=
testGroup
"Stripe"
[
chargeTests
,
corsTests
]
corsTests
::
TestTree
corsTests
=
testGroup
"CORS"
[
testCase
"a request with the wrong content-type receives a CORS-enabled response"
$
assertCORSHeader
"POST"
textPlain
validChargeBytes
,
testCase
"a request without a valid charge in the body receives a CORS-enabled response"
$
assertCORSHeader
"POST"
applicationJSON
invalidChargeBytes
,
testCase
"a request with the wrong request method receives a CORS-enabled response"
$
assertCORSHeader
"GET"
applicationJSON
validChargeBytes
,
testCase
"a request with a valid charge in the body receives a CORS-enabled response"
$
assertCORSHeader
"POST"
applicationJSON
validChargeBytes
]
where
textPlain
=
[(
"content-type"
,
"text/plain"
)]
applicationJSON
=
[(
"content-type"
,
"application/json"
)]
validChargeBytes
=
"{
\"
token
\"
:
\"
abcdef
\"
,
\"
voucher
\"
:
\"
lmnopqrst
\"
,
\"
amount
\"
:
\"
650
\"
,
\"
currency
\"
:
\"
USD
\"
}"
invalidChargeBytes
=
"[1, 2, 3]"
assertCORSHeader
method
headers
body
=
withFakeStripe
(
return
chargeOkay
)
$
\
stripeConfig
->
do
db
<-
memory
let
origins
=
[
"example.invalid"
]
let
app
=
paymentServerApp
origins
stripeConfig
trivialIssue
db
let
path
=
"/v1/stripe/charge"
let
theRequest
=
setPath
defaultRequest
{
requestMethod
=
method
,
requestHeaders
=
headers
}
path
let
theSRequest
=
SRequest
theRequest
body
(
flip
runSession
)
app
$
do
response
<-
srequest
theSRequest
liftIO
$
print
response
assertHeader
"Access-Control-Allow-Origin"
"example.invalid"
response
chargeTests
::
TestTree
chargeTests
=
...
...
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