Skip to content

[Qt] add verifySize() function to PaymentServer - #5665

Merged
jgarzik merged 1 commit into
bitcoin:masterfrom
Diapolo:pr_size
Sep 15, 2015
Merged

[Qt] add verifySize() function to PaymentServer#5665
jgarzik merged 1 commit into
bitcoin:masterfrom
Diapolo:pr_size

Conversation

@Diapolo

@Diapolo Diapolo commented Jan 15, 2015

Copy link
Copy Markdown
  • add static verifySize() function to PaymentServer and move the logging
    on error into the function
  • the function checks if the size is allowed as per BIP70

@laanwj laanwj added the GUI label Jan 15, 2015
@jonasschnelli

Copy link
Copy Markdown
Contributor

I would also strongly recommend to add a Unit-Test for verifySize().
We should no longer add implementations without test-coverage.
And i assume this is easy to test with another payment request in the fixtures.

@Diapolo

Diapolo commented Jan 30, 2015

Copy link
Copy Markdown
Author

@jonasschnelli As verifySize() IS used in PaymentServer::readPaymentRequestFromFile() we already have test coverage :). IMHO it doesn't make sense to spam paymentrequestdata.h with 50001 Bytes of garbage just to re-test verifySize() again. What do you think?

@jonasschnelli

Copy link
Copy Markdown
Contributor

@Diapolo IMO we should add the 50001 bytes test. You might use this forged payment request http://jonasschnelli.ch/r1422608371.bitcoinpaymentrequest

I also tried to test PaymentServer::readPaymentRequestFromFile with 50001 random bytes. But there is no distinction between parsing error and size error (returns only a bool).
Is there a change to test the QWarning within a QT unit test? Just a little string comparison?

@Diapolo

Diapolo commented Jan 30, 2015

Copy link
Copy Markdown
Author

@jonasschnelli I'm fine with directly using verifySize() instead of PaymentServer::readPaymentRequestFromFile() (which can then be private again ^^). But we don't need a real invalid playment request for this check IMHO. As the check is triggerd by just if > 50000 bytes rule it can be random garbage data.

What do you mean by Is there a change to test the QWarning within a QT unit test? Just a little string comparison??

@jonasschnelli

Copy link
Copy Markdown
Contributor

Tested, reviewed, stepped ACK.

nit: misses unit test

bildschirmfoto 2015-01-30 um 10 10 42

@jonasschnelli

Copy link
Copy Markdown
Contributor

@Diapolo: sounds even better. I would recommend to just pass 50001 bytes through PaymentServer::verifySize. I understand that the test looks very trivial know. But the idea of test are that they give guidelines when extending the implementation.

@Diapolo

Diapolo commented Jan 30, 2015

Copy link
Copy Markdown
Author

@jonasschnelli Updated, I hope this is fine now?

@jonasschnelli

Copy link
Copy Markdown
Contributor

tested ACK

@Diapolo

Diapolo commented Feb 3, 2015

Copy link
Copy Markdown
Author

Anything left to do for me to get this and other related pulls merged ;)?

@Diapolo

Diapolo commented Feb 26, 2015

Copy link
Copy Markdown
Author

Ping

@Diapolo

Diapolo commented Mar 9, 2015

Copy link
Copy Markdown
Author

@laanwj Mind giving this the final ACK ;)?

@jonasschnelli

Copy link
Copy Markdown
Contributor

ReACK

@Diapolo

Diapolo commented Mar 21, 2015

Copy link
Copy Markdown
Author

@laanwj ping

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are you removing this test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

To be able to make readPaymentRequestFromFile private again, which I changed once and wasn't happy with it :). The function could also fail, if the file failed to open, which isn't what this test is for anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you want to be able to test a private methods you could use a friend class / function. E.g. inside the class do

friend class PaymentServerTester;

Then do the testing in a class PaymentServerTester.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@laanwj It's not necessary here, but thanks for that C++ lesson :).

@Diapolo

Diapolo commented Apr 12, 2015

Copy link
Copy Markdown
Author

@jonasschnelli Maybe you can help me understand what's preventing this pull from getting merged?

@Diapolo

Diapolo commented May 31, 2015

Copy link
Copy Markdown
Author

@laanwj @jonasschnelli Ping

@laanwj

laanwj commented Jun 4, 2015

Copy link
Copy Markdown
Member

@Diapolo because you removed the test for, unrelated, PaymentServer::readPaymentRequestFromFile

@Diapolo

Diapolo commented Jun 5, 2015

Copy link
Copy Markdown
Author

@laanwj As I said, I just made PaymentServer::readPaymentRequestFromFile() public, because I hacked the former unit-test. That function isn't reliable as unit-test because it can also fail if the file could not be opened (returns false then), which isn't what the test assumes, as we want to verify the DoS protection.

@jgarzik

jgarzik commented Jul 23, 2015

Copy link
Copy Markdown
Contributor

ut ACK

@Diapolo

Diapolo commented Jul 24, 2015

Copy link
Copy Markdown
Author

@laanwj Fixed merge-conflict, ready now.

- add static verifySize() function to PaymentServer and move the logging
  on error into the function
- also use the new function in the unit test
- the function checks if the size is allowed as per BIP70
@Diapolo

Diapolo commented Aug 10, 2015

Copy link
Copy Markdown
Author

@laanwj Ping

@Diapolo

Diapolo commented Sep 9, 2015

Copy link
Copy Markdown
Author

Final ping!

@jgarzik
jgarzik merged commit be942de into bitcoin:master Sep 15, 2015
jgarzik pushed a commit that referenced this pull request Sep 15, 2015
@Diapolo
Diapolo deleted the pr_size branch September 15, 2015 21:04
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants