Skip to content

Commit

Permalink
No payload is not an authentic player (#430)
Browse files Browse the repository at this point in the history
* No payload should not be authentic player

* unless no payload necessary
  • Loading branch information
blunket authored and nicolodavis committed Jul 16, 2019
1 parent 621cc80 commit fd70ed5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/master/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export const isActionFromAuthenticPlayer = ({
return true;
}

if (!action.payload) {
return true;
}

const hasCredentials = Object.keys(gameMetadata.players).some(key => {
return !!(
gameMetadata.players[key] && gameMetadata.players[key].credentials
Expand All @@ -81,6 +77,10 @@ export const isActionFromAuthenticPlayer = ({
return true;
}

if (!action.payload) {
return false;
}

if (!action.payload.credentials) {
return false;
}
Expand Down
32 changes: 16 additions & 16 deletions src/master/master.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,22 +439,6 @@ describe('isActionFromAuthenticPlayer', () => {
});
});

describe('when action contains no payload', () => {
beforeEach(() => {
action = {};
});

test('the action is authentic', async () => {
const result = isActionFromAuthenticPlayer({
action,
gameMetadata,
playerID,
});

expect(result).toBeTruthy();
});
});

describe('when game has no credentials', () => {
beforeEach(() => {
gameMetadata = {
Expand All @@ -476,6 +460,22 @@ describe('isActionFromAuthenticPlayer', () => {
});

describe('when game has credentials', () => {
describe('when action contains no payload', () => {
beforeEach(() => {
action = {};
});

test('the action is not authentic', async () => {
const result = isActionFromAuthenticPlayer({
action,
gameMetadata,
playerID,
});

expect(result).toBeFalsy();
});
});

describe('when action contains no credentials', () => {
beforeEach(() => {
action = {
Expand Down

0 comments on commit fd70ed5

Please sign in to comment.