-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup runtime tests in order to test cookie behavior on browser and C…
…ordova (which doesn't support cookies without workarounds)
- Loading branch information
menelike
committed
Oct 13, 2019
0 parents
commit e34ae23
Showing
16 changed files
with
942 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "packages/Meteor-Cookies"] | ||
path = packages/Meteor-Cookies | ||
url = https://github.com/VeliovGroup/Meteor-Cookies.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This file contains information which helps Meteor properly upgrade your | ||
# app when you run 'meteor update'. You should check it into version control | ||
# with your project. | ||
|
||
notices-for-0.9.0 | ||
notices-for-0.9.1 | ||
0.9.4-platform-file | ||
notices-for-facebook-graph-api-2 | ||
1.2.0-standard-minifiers-package | ||
1.2.0-meteor-platform-split | ||
1.2.0-cordova-changes | ||
1.2.0-breaking-changes | ||
1.3.0-split-minifiers-package | ||
1.4.0-remove-old-dev-bundle-link | ||
1.4.1-add-shell-server-package | ||
1.4.3-split-account-service-packages | ||
1.5-add-dynamic-import-package | ||
1.7-split-underscore-from-meteor-base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file contains a token that is unique to your project. | ||
# Check it into your repository along with the rest of this directory. | ||
# It can be used for purposes such as: | ||
# - ensuring you don't accidentally deploy one app on top of another | ||
# - providing package authors with aggregated statistics | ||
|
||
g3ylf5ny3q3.dno8tvbrwc5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Meteor packages used by this project, one per line. | ||
# Check this file (and the other files in this directory) into your repository. | ||
# | ||
# 'meteor add' and 'meteor remove' will edit this file for you, | ||
# but you can also edit it by hand. | ||
|
||
[email protected] # Shared foundation for all Meteor packages | ||
static-html # Define static page content in .html files | ||
[email protected] # CSS minifier run for production mode | ||
[email protected] # JS minifier run for production mode | ||
[email protected] # ECMAScript 5 compatibility for older browsers | ||
[email protected] # Enable ECMAScript2015+ syntax in app code | ||
[email protected] # Server-side component of the `meteor shell` command | ||
[email protected] # Serves a Meteor app over HTTP | ||
[email protected] # Support for server-side rendering | ||
ostrio:cookies | ||
http | ||
meteor-base | ||
browser-policy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
android | ||
browser | ||
ios | ||
server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.meteor | ||
packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<head> | ||
<title>ostrio:cookies test app</title> | ||
</head> | ||
|
||
<body> | ||
<h1>ostrio:cookies test app</h1> | ||
<ul id="output"> | ||
</ul> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import { Cookies } from "meteor/ostrio:cookies"; | ||
import { HTTP } from "meteor/http"; | ||
import { Meteor } from "meteor/meteor"; | ||
|
||
const attachMsg = (node) => { | ||
const list = document.getElementById("output"); | ||
list.appendChild(node); | ||
}; | ||
|
||
const createListItem = (msg, style) => { | ||
const node = document.createElement("li"); | ||
node.appendChild(document.createTextNode(msg)); | ||
node.setAttribute("style", style); | ||
return node; | ||
}; | ||
|
||
const assertEqual = (a, b, msg) => { | ||
const node = createListItem(msg, `color: ${a === b ? "green" : "red"};`); | ||
attachMsg(node); | ||
}; | ||
|
||
const runTests = async () => { | ||
const cookieValue = `${Date.now()}`; | ||
const cookieParam = `__TEST_COOKIE__=${cookieValue}`; | ||
const ___expectedCookies___ = encodeURI(cookieParam); | ||
const cookieResetPath = Meteor.absoluteUrl("/__cookie_reset"); | ||
const cookieTestPath = Meteor.absoluteUrl("/__cookie_match"); | ||
const cookies = new Cookies({ allowQueryStringCookies: true }); | ||
|
||
cookies.remove(); | ||
assertEqual(document.cookie, "", "cookie is empty"); | ||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieResetPath, | ||
{ | ||
params: { | ||
___removeCookie___: "__TEST_COOKIE__" | ||
}, | ||
beforeSend(xhr) { | ||
xhr.withCredentials = true; | ||
return true; | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual(res.statusCode, 200, "clear cookie request successful"); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
|
||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieTestPath, | ||
{ | ||
params: { | ||
___expectedCookies___: "undefined" | ||
}, | ||
beforeSend(xhr) { | ||
xhr.withCredentials = true; | ||
return true; | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual(res.statusCode, 200, "server did not receive cookie"); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
|
||
cookies.set("__TEST_COOKIE__", cookieValue); | ||
assertEqual(document.cookie, cookieParam, "set cookie on client"); | ||
|
||
if (Meteor.isCordova) { | ||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieTestPath, | ||
{ | ||
params: { | ||
___expectedCookies___: "undefined" | ||
}, | ||
beforeSend(xhr) { | ||
xhr.withCredentials = true; | ||
return true; | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual(res.statusCode, 200, "no cookie received from cordova"); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} else { | ||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieTestPath, | ||
{ | ||
params: { | ||
___expectedCookies___ | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual( | ||
res.statusCode, | ||
200, | ||
"server received cookie from browser" | ||
); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
await new Promise(resolve => cookies.send(resolve)); | ||
|
||
// in cordova cookies set by the server are invisible by the client | ||
// but are sent within requests if withCredentials is true | ||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieTestPath, | ||
{ | ||
params: { | ||
___expectedCookies___ | ||
}, | ||
beforeSend(xhr) { | ||
xhr.withCredentials = true; | ||
return true; | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual(res.statusCode, 200, "server received cookie after send()"); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
|
||
if (Meteor.isCordova) { | ||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieTestPath, | ||
{ | ||
params: { | ||
___expectedCookies___: "undefined" | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual( | ||
res.statusCode, | ||
200, | ||
"no cookie from cordova with withCredentials = false" | ||
); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} else { | ||
await new Promise(resolve => { | ||
HTTP.get( | ||
cookieTestPath, | ||
{ | ||
params: { | ||
___expectedCookies___ | ||
} | ||
}, | ||
(err, res) => { | ||
assertEqual( | ||
res.statusCode, | ||
200, | ||
"server received cookie from browser with withCredentials = false" | ||
); | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
attachMsg(createListItem("all tests run!")); | ||
}; | ||
|
||
console.log(document.readyState); | ||
|
||
const func = () => { | ||
if (document.readyState === "complete") { | ||
runTests().catch(console.error); | ||
} else { | ||
setTimeout(func, 10) | ||
} | ||
}; | ||
|
||
func(); |
Oops, something went wrong.