Skip to content

Commit ff374d4

Browse files
authored
Merge pull request #65 from StatelessStudio/v0.4.2
V0.4.2
2 parents 8a07ab8 + 03826f1 commit ff374d4

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# PointyApi Changelog
22

3+
## [0.4.2] Dec-26-2018
4+
5+
Fixed onlySelf() on GET
6+
7+
### Fixes
8+
- onlySelf() on GET should not be authorized by default
9+
- onlySelf() should filter GET arrays
10+
311
## [0.4.1] Dec-23-2018
412

513
Fixed count parameter

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pointyapi",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"author": "stateless-studio",
55
"license": "MIT",
66
"scripts": {

src/guards-auth/only-self.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ export async function onlySelf(
5050
userKeys
5151
);
5252
}
53-
else {
53+
else if (request.payload instanceof Array) {
54+
// Filter payload
55+
request.payload = request.payload.filter((result) => {
56+
return isSelf(
57+
result,
58+
request.user,
59+
request.payloadType,
60+
request.userType,
61+
bodyKeys,
62+
userKeys
63+
);
64+
});
65+
5466
authorized = true;
5567
}
5668
}

test/spec/chat/chat/chat-get.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,49 @@ describe('[Chat] Chat API Get', async () => {
261261
.catch((error) => fail(JSON.stringify(error)));
262262
});
263263

264+
it(`does not return chats the user does not own`, async () => {
265+
const user = await http
266+
.post('/api/v1/user', {
267+
fname: 'Chat',
268+
lname: 'Hacker',
269+
username: 'chatHacker',
270+
password: 'password123',
271+
272+
})
273+
.catch((error) =>
274+
fail('Could not create base user: ' + JSON.stringify(error))
275+
);
276+
277+
const token = await http
278+
.post('/api/v1/auth', {
279+
__user: 'chatHacker',
280+
password: 'password123'
281+
})
282+
.catch((error) =>
283+
fail('Could not create User API Token' + JSON.stringify(error))
284+
);
285+
286+
if (token) {
287+
await http
288+
.get(
289+
'/api/v1/chat',
290+
{
291+
__search: '',
292+
__whereAnyOf: {
293+
to: this.user.body.id,
294+
from: this.user.body.id
295+
}
296+
},
297+
[ 200 ],
298+
token.body['token']
299+
)
300+
.then((result) => {
301+
expect(result.body['length']).toBe(0);
302+
})
303+
.catch((error) => fail(JSON.stringify(error)));
304+
}
305+
});
306+
264307
it('can count', async () => {
265308
await http
266309
.get(

0 commit comments

Comments
 (0)