Skip to content

Commit

Permalink
fix: oops, check the user's actual month for validity
Browse files Browse the repository at this point in the history
(not the current month)

Closes #47
  • Loading branch information
pjenvey committed Aug 1, 2018
1 parent c4d2ff6 commit 8b4eb87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/db/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,13 @@ fn handle_user_result(
let item = data.item.ok_or((false, 104))?;
let mut user: DynamoDbUser = serde_dynamodb::from_hashmap(item).map_err(|_| (true, 104))?;

let user_month = user.current_month.clone();
let month = user_month.ok_or((true, 104))?;
if !messages_tables.contains(cur_month) {
let user_month = user.current_month.clone().ok_or((true, 104))?;
if !messages_tables.contains(&user_month) {
return Err((true, 105));
}
hello_response.check_storage = true;
hello_response.message_month = month.clone();
hello_response.rotate_message_table = *cur_month != month;
hello_response.rotate_message_table = user_month != *cur_month;
hello_response.message_month = user_month;
hello_response.reset_uaid = user
.record_version
.map_or(true, |rec_ver| rec_ver < USER_RECORD_VERSION);
Expand Down
30 changes: 27 additions & 3 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from autopush.db import (
get_month,
has_connected_this_month,
make_rotating_tablename,
Message,
)
from autopush.logging import begin_or_register
Expand Down Expand Up @@ -1056,7 +1057,6 @@ def test_broadcast_no_changes(self):

@inlineCallbacks
def test_webpush_monthly_rotation(self):
from autopush.db import make_rotating_tablename
client = yield self.quick_register()
yield client.disconnect()

Expand Down Expand Up @@ -1169,7 +1169,6 @@ def test_webpush_monthly_rotation(self):

@inlineCallbacks
def test_webpush_monthly_rotation_prior_record_exists(self):
from autopush.db import make_rotating_tablename
client = yield self.quick_register()
yield client.disconnect()

Expand Down Expand Up @@ -1264,7 +1263,6 @@ def test_webpush_monthly_rotation_prior_record_exists(self):

@inlineCallbacks
def test_webpush_monthly_rotation_no_channels(self):
from autopush.db import make_rotating_tablename
client = Client("ws://localhost:{}/".format(MP_CONNECTION_PORT))
yield client.connect()
yield client.hello()
Expand Down Expand Up @@ -1315,6 +1313,32 @@ def test_webpush_monthly_rotation_no_channels(self):
assert c["current_month"] == self.conn.db.current_msg_month
yield self.shut_down(client)

@inlineCallbacks
def test_webpush_monthly_rotation_old_user_dropped(self):
client = yield self.quick_register()
uaid = client.uaid
yield client.disconnect()

# Move the client back 2 months to the past
old_month = make_rotating_tablename(
prefix=self.conn.conf.message_table.tablename, delta=-3)
yield deferToThread(
self.conn.db.router.update_message_month,
client.uaid,
old_month
)
old_message = Message(old_month,
boto_resource=autopush.tests.boto_resource)

# Verify the move
c = yield deferToThread(self.conn.db.router.get_uaid, client.uaid)
assert c["current_month"] == old_month

# Connect the client and verify its uaid was dropped
yield client.connect()
yield client.hello()
assert client.uaid != uaid


class TestRustAndPythonWebPush(unittest.TestCase):
_endpoint_defaults = dict(
Expand Down

0 comments on commit 8b4eb87

Please sign in to comment.