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

feat: port register command to Rust #1222

Merged
merged 1 commit into from
May 11, 2018
Merged

feat: port register command to Rust #1222

merged 1 commit into from
May 11, 2018

Conversation

bbangert
Copy link
Member

Closes #1190

@bbangert bbangert force-pushed the feat/issue-1190 branch 2 times, most recently from e35e230 to 715f2e5 Compare May 10, 2018 16:49
@codecov-io
Copy link

codecov-io commented May 10, 2018

Codecov Report

Merging #1222 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1222   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          60      60           
  Lines       10197   10190    -7     
======================================
- Hits        10197   10190    -7
Impacted Files Coverage Δ
autopush/tests/test_rs_integration.py 100% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update af272df...4ff1743. Read the comment docs.

alexcrichton
alexcrichton previously approved these changes May 10, 2018
@@ -733,17 +733,15 @@ where
}
}
Either::A(ClientMessage::Register { channel_id, key }) => {
data.srv.metrics.incr("ua.command.register").ok();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was also an associated log.info here in python

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we never used it and I don't know why we bothered logging it.

message_table_name: &str,
) -> MyFuture<UpdateItemOutput> {
let chid = channel_id.hyphenated().to_string();
let expiry = (time::get_time().sec as u64) + MAX_EXPIRY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer util::sec_since_epoch

let key_digest = hash::hash(hash::MessageDigest::sha256(), &raw_key)
.chain_err(|| "Error creating message digest for key")?;
base.extend(key_digest.iter());
let encrypted = self.opts.fernet.encrypt(&base);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's trim_matches('=') the result of fernet.encrypt here and below (like the python code), just to be super safe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python one only strips the encrypted value once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant below as in the else block


def process(self, command):
# type: (Register) -> Union[RegisterResponse, RegisterErrorResponse]
valid, msg = _validate_chid(command.channel_id)
Copy link
Member

@pjenvey pjenvey May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have _validate_chid here to mimick websocket.py's validation of the channel_id sent in register (that it's hyphenated).

Now I'm wondering if this check is bogus: because the rust side parses the register command now. It's deserializing it into ClientMessage::Register channel_id: Uuid. Does serde's deserialization allow non hyphenated uuids to pass through unnoticed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, it does pass it through: https://docs.rs/uuid/0.6.3/src/uuid/serde_support.rs.html#16-56

parse() is parse_str(): "Parses a Uuid from a string of hexadecimal digits with optional hyphens."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, serde will allow hypenated or not to pass through.

@bbangert bbangert force-pushed the feat/issue-1190 branch 2 times, most recently from be1ef64 to 2d1f97b Compare May 10, 2018 23:17
@pjenvey pjenvey merged commit 616248a into master May 11, 2018
@pjenvey pjenvey deleted the feat/issue-1190 branch May 11, 2018 00:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants