aboutsummaryrefslogtreecommitdiff
path: root/tests/pws.rs
Commit message (Collapse)AuthorAge
* Add String value to the Error::UnexpectedError variantRobin Krahl2020-01-28
| | | | | | To make debugging of unexpected errors easier, this patch adds an associated String value with a description of the unexpected behavior to the UnexpectedError variant of the Error enum.
* Introduce into_manager for DeviceRobin Krahl2019-07-09
| | | | | | | | To enable applications like nitrokey-test to go back to a manager instance from a Device instance, we add the into_manager function to the Device trait. To do that, we have to keep track of the Manager’s lifetime by adding a lifetime to Device (and then to some other traits that use Device).
* Remove PIN constants from testsRobin Krahl2019-02-04
| | | | | | In a previous commit, we introduced the DEFAULT_{ADMIN,USER}_PIN constants. Therefore we no longer need in the {ADMIN,USER}_PASSWORD constants in the util module for the tests.
* Require mutable reference if method changes device stateRobin Krahl2019-02-02
| | | | | | | | | | | | Previously, all methods that access a Nitrokey device took a reference to the device as input. This method changes methods that change the device state to require a mutable reference instead. In most case, this is straightforward as the method writes data to the device (for example write_config or change_user_pin). But there are two edge cases: - Authenticating with a PIN changes the device state as it may decrease the PIN retry counter if the authentication fails. - Generating an HOTP code changes the device state as it increases the HOTP counter.
* Add assert_any_ok macro to unit testsRobin Krahl2019-01-28
| | | | | | | | Sometimes we cannot use assert_ok! as we can’t compare the Ok value (or do not want to). For these cases, this patch adds the new assert_any_ok macro to use instead of assert!(x.is_ok()). The advantage is that the error information is not discarded but printed in a helpful error message.
* Add unwrap_ok macro to replace unwrap in unit testsRobin Krahl2019-01-28
| | | | | | The unwrap error message is not very useful. This patch adds the unwrap_ok macro that is basically the same as unwrap but prints a more readable error message.
* Add license and copyright informationRobin Krahl2019-01-23
| | | | | | | This patch adds license and copyright information to all files to make nitrokey-rs compliant with the REUSE practices [0]. [0] https://reuse.software/practices/2.0/
* Fix formatting in testsRobin Krahl2019-01-20
|
* Check specific error codes in the testsRobin Krahl2019-01-20
| | | | | | | | | | If possible, check specific error codes instead of `is_err()`. This makes the code more readable and catches bugs resulting in the wrong error code. Also, using the assert_*_err and assert_ok macros yields error messages containing the expected and the actual value. To be able to use these macros with the `get_password_safe` method, we also have to implement `Debug` for `PasswordSafe` and `Device`.
* Introduce the Error::UnexpectedError variantRobin Krahl2019-01-20
| | | | | | | The UnexpectedError variant is used when a libnitrokey function returns a value that violates the function’s contract, for example if a function returns a null pointer although it guarantees to never return null. Previously, we returned a CommandError::Unspecified in these cases.
* Refactor library errors into LibraryError enumRobin Krahl2019-01-20
| | | | | | Previously, library errors were part of the CommandError enum. As command errors and library errors are two different error types, they should be split into two enums.
* Move the CommandError::Unknown to ErrorRobin Krahl2019-01-20
| | | | | | | An error code can not only indiciate a command error, but also a library or device communication error. Therefore, the variant for an unknown error code should be placed in the top-level Error enum instead of the CommandError enum.
* Add assert_cmd_err and assert_ok macros to testsRobin Krahl2019-01-20
| | | | | | | | | These macros allow easier comparisions using the new error type. This patch fixes all tests and updates nitrokey-test to 0.2.0 so that it integrates with the new error structure. Some tests may still fail until CommunicationError::NotConnected is actually returned.
* pws: Interpret empty strings as unprogrammed slotsRobin Krahl2019-01-16
| | | | | | | | | | | | Until the last commit, all empty strings returned by the library were interepreted as errors. As the PWS functions return empty strings for unprogrammed slots, the methods to access the PWS data returned an error when querying a slot that is not programmed. Since the last commit, they return an empty string instead. This patch restores the old behavior by returning an error instead of an empty string. Yet we change the error variant: SlotNotProgrammed instead of Undefined.
* Prefer assert_eq over is_ok() checksDaniel Mueller2019-01-05
| | | | | | | | | | We experienced various problems running the tests and while they may or may not be caused by local setup issues, it is helpful to have more information than just an indication that an assertion (true/false) was violated. To that end, this change adjusts some of the assert!(<func>().is_ok()) to compare against Ok(()) instead. This way, if the result is not the Ok variant, the error code will get printed.
* Adjust PWS tests to use nitrokey-test crateDaniel Mueller2019-01-05
| | | | This change adjusts the PWS tests to use the nitrokey-test crate.
* Preserve unknown error code valuesDaniel Mueller2019-01-03
| | | | | | | | | | The CommandError::Unknown variant, which is used whenever a reported error code is not known, makes it close to impossible to determine the root cause of, say, a one-off error, because all information explaining what went wrong is discarded. With this change we adjust the Unknown variant to include the error report. In addition, we introduce a new CommandError variant, Undefined, that is used when no error code is available.
* Fix formatting using to rustfmtRobin Krahl2018-12-30
|
* Refactor tests into the top-level tests directoryRobin Krahl2018-12-16
Newer Rust versions support integration tests in a top-level tests directory. This patch refactors the existing unit tests into integration tests.