Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 162ff07

Browse files
authored
Merge pull request #100 from SpringRoll/release/1.8.1
Release/1.8.1
2 parents 5effaf5 + 7961c59 commit 162ff07

File tree

8 files changed

+142
-46
lines changed

8 files changed

+142
-46
lines changed

app/public/js/embed.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/routes/api/games.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var router = require('express').Router(),
44
Group = require('../../models/group'),
55
Game = require('../../models/game'),
66
cache = require('../../helpers/cache'),
7+
log = require('../../helpers/logger'),
78
response = require('../../helpers/response');
89

910
router.use(function(req, res, next) {
@@ -26,7 +27,15 @@ router.get('/', cache, function(req, res) {
2627
.isToken();
2728

2829
if (req.validationErrors()) {
29-
return response.call(res, 'Invalid Arguments');
30+
let message = '';
31+
req.validationErrors().forEach(error => {
32+
message += `${error.msg}: ${error.param}. `;
33+
});
34+
35+
return res.status(422).send({
36+
success: false,
37+
error: message.trim()
38+
});
3039
}
3140

3241
var status = req.query.status || 'prod';
@@ -72,10 +81,19 @@ router.get('/', cache, function(req, res) {
7281
}
7382
],
7483
function(err, games) {
75-
if (err) {
76-
return response.call(res, err);
77-
} else if (games.length === 0) {
78-
return response.call(res, 'No games');
84+
if (err === 'No token' || err === 'Invalid token') {
85+
log.warn(err + ' request for api/games');
86+
return res.status(403).send({
87+
success: false,
88+
error: err
89+
});
90+
} else if (err) {
91+
log.warn(err);
92+
93+
return res.status(400).send({
94+
success: false,
95+
error: err
96+
});
7997
}
8098

8199
games = games.reduce((filteredGames, game) => {
@@ -96,11 +114,10 @@ router.get('/', cache, function(req, res) {
96114
return filteredGames;
97115
}, []);
98116

99-
if (games.length <= 0) {
100-
return response.call(res, 'No games');
101-
}
102-
103-
response.call(res, err, games);
117+
return res.send({
118+
success: true,
119+
data: games
120+
});
104121
}
105122
);
106123
});

app/routes/api/release.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,19 @@ router.get('/:slugOrBundleId', cache, function(req, res) {
174174
.checkQuery('version')
175175
.optional()
176176
.isSemver();
177+
177178
if (req.validationErrors()) {
178-
return response.call(res, 'Invalid arguments');
179+
let message = '';
180+
req.validationErrors().forEach(error => {
181+
message += `${error.msg}: ${error.param}. `;
182+
});
183+
184+
return res.status(422).send({
185+
success: false,
186+
error: message.trim()
187+
});
179188
}
189+
180190
Release.getByGame(
181191
req.params.slugOrBundleId,
182192
{
@@ -187,7 +197,30 @@ router.get('/:slugOrBundleId', cache, function(req, res) {
187197
token: req.query.token,
188198
debug: req.query.debug
189199
},
190-
response.bind(res)
200+
function(err, release) {
201+
if (err === null && release !== null) {
202+
// if there's no error and a release was found
203+
return res.send({ success: true, data: release });
204+
} else if (err === null && release === null) {
205+
// no release was found, so it's a 404
206+
log.warn(`No release found for slug "${req.params.slugOrBundleId}"`);
207+
return res.status(404).send({ success: false, data: null });
208+
}
209+
210+
if (err === 'Invalid game slug') {
211+
// If the slug doesn't exist, it's a 404
212+
log.warn(`Invalid game slug "${req.params.slugOrBundleId}"`);
213+
return res.status(404).send({ success: false, error: err });
214+
} else if (err === 'Token is required') {
215+
// If the request was for a dev game without a token, it's a 403
216+
log.warn(`Request for game "${req.params.slugOrBundleId}" without token`);
217+
return res.status(403).send({ success: false, error: err });
218+
} else {
219+
// Otherwise, we don't know what it is so it's probably a 500
220+
log.warn(err);
221+
return res.status(500).send({ success: false, data: null });
222+
}
223+
}
191224
);
192225
});
193226

npm-shrinkwrap.json

Lines changed: 35 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"babel-loader": "^8.0.6",
1414
"bootstrap-sass": "^3.4.1",
1515
"chai": "^4.2.0",
16-
"chromedriver": "^77.0.0",
16+
"chromedriver": "^79.0.0",
1717
"concurrently": "^4.1.0",
1818
"css-loader": "^2.1.1",
1919
"exports-loader": "^0.7.0",
@@ -74,7 +74,7 @@
7474
"passport": "^0.2.1",
7575
"passport-local": "^1.0.0",
7676
"semver": "^5.0.1",
77-
"springroll-container": "git+https://github.com/SpringRoll/SpringRollContainer.git",
77+
"springroll-container": "github:SpringRoll/SpringRollContainer#develop",
7878
"uuid": "^3.2.1"
7979
},
8080
"scripts": {

test/api/games.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,21 @@ describe('api/games', () => {
8181

8282
expect(response.headers.get('Cache-Control')).to.equal(null);
8383
});
84+
85+
it('should return a 422 if the provided input is invalid', async function() {
86+
const response = await fetch(`${API_GAMES_URL}?token=invalid&status=invalid`);
87+
88+
expect(response.status).to.equal(422);
89+
});
90+
91+
it('should return a 403 if dev games are requested without a token', async function() {
92+
const response = await fetch(`${API_GAMES_URL}?status=dev`);
93+
expect(response.status).to.equal(403);
94+
});
95+
96+
it('should return a 403 if the provided token is a not a real token', async function() {
97+
const response = await fetch(`${API_GAMES_URL}?status=dev&token=1234567890123456789012345678901234567890`);
98+
expect(response.status).to.equal(403);
99+
});
84100
});
85101
});

test/api/release.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ describe('api/release', () => {
6262
const response = await fetch(`http://localhost:3000/api/release/${game.slug}?status=dev`);
6363
expect(response.headers.get('Cache-Control')).to.equal(null);
6464
});
65+
66+
it('should respond with a 404 if a request is made for a slug that does not exist', async function() {
67+
const response = await fetch(`http://localhost:3000/api/release/dont-exists`);
68+
expect(response.status).to.equal(404);
69+
});
70+
71+
it('should respond with a 404 if a request is made for a game that does not have a prod release', async function() {
72+
const game = await dataMakers.makeGame('dev');
73+
const response = await fetch(`http://localhost:3000/api/release/${game.slug}`);
74+
expect(response.status).to.equal(404);
75+
});
76+
77+
it('should respond with a 403 if a request is made for a dev release without a token', async function() {
78+
const game = await dataMakers.makeGame('dev');
79+
const response = await fetch(`http://localhost:3000/api/release/${game.slug}?status=dev`);
80+
const json = await response.json();
81+
82+
expect(response.status).to.equal(403);
83+
});
84+
85+
it('should respond with a 422 if the request had invalid fields', async function() {
86+
const response = await fetch('http://localhost:3000/api/release/doesntmatter?status=NOPE&token=tooshort');
87+
expect(response.status).to.equal(422);
88+
});
6589
});
6690

6791
describe('POST', () => {

test/pages/embed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Embed Pages', () => {
4747

4848
const text = await alert.getText();
4949
await alert.accept();
50-
expect(text).to.equal('Invalid arguments');
50+
expect(text).to.equal('Invalid value: token.');
5151
});
5252

5353
it('should allow valid tokens to view dev releases of a game', async () => {

0 commit comments

Comments
 (0)