Closed gianluca-nitti closed 7 years ago
Is this one still relevant?
Yes. I did some further investigation and I found out that the non-determinism is due to the usage of CertificateGenerator
, i.e. the signature byte arrays are generated by a fixed-seed RNG, but the certificates to sign (private) and verify (public) them are generated by the CertificateGenerator
class thus always different.
To make the test deterministic I could make a mock object for the CertificateGenerator
class which always returns the same certs.
But the test is actually showing an incorrect behavior in the code which should probably be corrected. I think the way to go is splitting this test case in multiple deterministic ones that cover both the cases that are now failing and the ones which are succeeding, then find a way to make them all pass.
Update - I did more debugging and found out that even by providing fixed client and server certificate pairs the test can fail, and the real cause of the non-determinism of this test is the random handshake data generated by AuthenticationHandshakeHandlerImpl
(the class being tested) to be signed by the client.
The good news is that I noticed that the exception is raised when signing the handshake message and not when verifying it, so the problematic part is when the test simulates a client; the server's behavior, in my understanding, is correct. It's not possible to send a "bad" handshake reply from a client to the server which would crash the server; it's a client that, given an invalid private certificate, may fail to use it to sign the handshake reply.
At this point - unless anyone has a better idea - I'm considering just removing this test method; I don't know how I could make it fully deterministic since generating random handshakes to be signed by the client (using the private certificate) is part of the expected behavior of the class being tested. I noticed that the "equivalent" code (for regular Terasology clients) in the main repository hasn't any tests.
Adding this mainly as a note to myself for when I have the time to fix it.
As the title says, the unit test
AuthenticationHandshakeHandlerTest.testBadSignature
is not fully deterministic (it uses some randomly generated values) and can sometimes fail with the following exception:I thought that the random generator was properly seeded to always produce the same numbers but looks like it isn't. This failure happened about 2 or 3 times in two months, always when I was working on completely separate classes from the one this code tests and I was just running all the tests before committing (which I do multiple times a day when I work on the server).