Skip to content

Commit

Permalink
Fix desktop tests for bugfix and stable (#395)
Browse files Browse the repository at this point in the history
* fix build and lint problems

* fix coveralls workflow by setting a working toolchain
  • Loading branch information
kaczmarczyck committed Nov 1, 2021
1 parent c6f9c7e commit 64b0ae7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
toolchain: nightly-2020-06-10
args: --features "with_ctap1,with_nfc,std" --no-fail-fast
env:
CARGO_INCREMENTAL: '0'
Expand Down
11 changes: 10 additions & 1 deletion deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,16 @@ def checked_command_output(self, cmd, env=None, cwd=None):
def update_rustc_if_needed(self):
target_toolchain_fullstring = "stable"
with open("rust-toolchain", "r", encoding="utf-8") as f:
target_toolchain_fullstring = f.readline().strip()
content = f.readlines()
if len(content) == 1:
# Old format, only the build is stored
target_toolchain_fullstring = content[0].strip()
else:
# New format
for line in content:
if line.startswith("channel"):
channel = line.strip().split("=", maxsplit=1)[1].strip()
target_toolchain_fullstring = channel.strip('"')
target_toolchain = target_toolchain_fullstring.split("-", maxsplit=1)
if len(target_toolchain) == 1:
# If we target the stable version of rust, we won't have a date
Expand Down
2 changes: 2 additions & 0 deletions examples/nfct_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ mod example {
use libtock_drivers::timer::Timestamp;

#[derive(Copy, Clone, Debug, PartialEq)]
// The actual lint upper_case_acronyms is not supported in all toolchains.
#[allow(clippy::all)]
enum ReturnCode {
/// Operation completed successfully
SUCCESS,
Expand Down
38 changes: 19 additions & 19 deletions src/ctap/apdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl From<&[u8; APDU_HEADER_LEN]> for ApduHeader {

#[cfg_attr(test, derive(Clone, Debug))]
#[derive(PartialEq)]
/// The APDU cases
/// The Apdu cases
pub enum Case {
Le1,
Lc1Data,
Expand All @@ -97,15 +97,15 @@ pub enum ApduType {
#[cfg_attr(test, derive(Clone, Debug))]
#[allow(dead_code)]
#[derive(PartialEq)]
pub struct APDU {
pub struct Apdu {
pub header: ApduHeader,
pub lc: u16,
pub data: Vec<u8>,
pub le: u32,
pub case_type: ApduType,
}

impl TryFrom<&[u8]> for APDU {
impl TryFrom<&[u8]> for Apdu {
type Error = ApduStatusCode;

fn try_from(frame: &[u8]) -> Result<Self, ApduStatusCode> {
Expand All @@ -119,7 +119,7 @@ impl TryFrom<&[u8]> for APDU {

if payload.is_empty() {
// Lc is zero-bytes in length
return Ok(APDU {
return Ok(Apdu {
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
lc: 0x00,
data: Vec::new(),
Expand All @@ -132,7 +132,7 @@ impl TryFrom<&[u8]> for APDU {
if payload.len() == 1 {
// There is only one byte in the payload, that byte cannot be Lc because that would
// entail at *least* one another byte in the payload (for the command data)
return Ok(APDU {
return Ok(Apdu {
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
lc: 0x00,
data: Vec::new(),
Expand All @@ -148,7 +148,7 @@ impl TryFrom<&[u8]> for APDU {
if payload.len() == 1 + (byte_0 as usize) && byte_0 != 0 {
// Lc is one-byte long and since the size specified by Lc covers the rest of the
// payload there's no Le at the end
return Ok(APDU {
return Ok(Apdu {
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
lc: byte_0.into(),
data: payload[1..].to_vec(),
Expand All @@ -160,7 +160,7 @@ impl TryFrom<&[u8]> for APDU {
// Lc is one-byte long and since the size specified by Lc covers the rest of the
// payload with ONE additional byte that byte must be Le
let last_byte: u32 = (*payload.last().unwrap()).into();
return Ok(APDU {
return Ok(Apdu {
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
lc: byte_0.into(),
data: payload[1..(payload.len() - 1)].to_vec(),
Expand All @@ -186,9 +186,9 @@ impl TryFrom<&[u8]> for APDU {
if byte_0 == 0 && extended_apdu_le_len <= 3 {
// If first byte is zero AND the next two bytes can be parsed as a big-endian
// length that covers the rest of the block (plus few additional bytes for Le), we
// have an extended-length APDU
// have an extended-length Apdu
let last_byte: u32 = (*payload.last().unwrap()).into();
return Ok(APDU {
return Ok(Apdu {
header: array_ref!(header, 0, APDU_HEADER_LEN).into(),
lc: extended_apdu_lc as u16,
data: payload[3..(payload.len() - extended_apdu_le_len)].to_vec(),
Expand Down Expand Up @@ -243,16 +243,16 @@ impl TryFrom<&[u8]> for APDU {
mod test {
use super::*;

fn pass_frame(frame: &[u8]) -> Result<APDU, ApduStatusCode> {
APDU::try_from(frame)
fn pass_frame(frame: &[u8]) -> Result<Apdu, ApduStatusCode> {
Apdu::try_from(frame)
}

#[test]
fn test_case_type_1() {
let frame: [u8; 4] = [0x00, 0x12, 0x00, 0x80];
let response = pass_frame(&frame);
assert!(response.is_ok());
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0x12,
Expand All @@ -271,7 +271,7 @@ mod test {
fn test_case_type_2_short() {
let frame: [u8; 5] = [0x00, 0xb0, 0x00, 0x00, 0x0f];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0xb0,
Expand All @@ -290,7 +290,7 @@ mod test {
fn test_case_type_2_short_le() {
let frame: [u8; 5] = [0x00, 0xb0, 0x00, 0x00, 0x00];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0xb0,
Expand All @@ -310,7 +310,7 @@ mod test {
let frame: [u8; 7] = [0x00, 0xa4, 0x00, 0x0c, 0x02, 0xe1, 0x04];
let payload = [0xe1, 0x04];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0xa4,
Expand All @@ -332,7 +332,7 @@ mod test {
];
let payload = [0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0xa4,
Expand All @@ -354,7 +354,7 @@ mod test {
];
let payload = [0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0xa4,
Expand Down Expand Up @@ -396,7 +396,7 @@ mod test {
];
let payload: &[u8] = &frame[7..frame.len() - 2];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0x02,
Expand All @@ -423,7 +423,7 @@ mod test {
];
let payload: &[u8] = &frame[7..frame.len() - 2];
let response = pass_frame(&frame);
let expected = APDU {
let expected = Apdu {
header: ApduHeader {
cla: 0x00,
ins: 0x01,
Expand Down
6 changes: 3 additions & 3 deletions src/ctap/ctap1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use super::apdu::{ApduStatusCode, APDU};
use super::apdu::{Apdu, ApduStatusCode};
use super::hid::ChannelID;
use super::status_code::Ctap2StatusCode;
use super::CtapState;
Expand Down Expand Up @@ -82,7 +82,7 @@ impl TryFrom<&[u8]> for U2fCommand {
type Error = Ctap1StatusCode;

fn try_from(message: &[u8]) -> Result<Self, Ctap1StatusCode> {
let apdu: APDU = match APDU::try_from(message) {
let apdu: Apdu = match Apdu::try_from(message) {
Ok(apdu) => apdu,
Err(apdu_status_code) => {
return Err(Ctap1StatusCode::try_from(apdu_status_code).unwrap())
Expand All @@ -91,7 +91,7 @@ impl TryFrom<&[u8]> for U2fCommand {

let lc = apdu.lc as usize;

// ISO7816 APDU Header format. Each cell is 1 byte. Note that the CTAP flavor always
// ISO7816 Apdu Header format. Each cell is 1 byte. Note that the CTAP flavor always
// encodes the length on 3 bytes and doesn't use the field "Le" (Length Expected).
// We keep the 2 byte of "Le" for the packet length in mind, but always ignore its value.
// Lc is using big-endian encoding
Expand Down
6 changes: 3 additions & 3 deletions src/ctap/hid/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ mod test {
}

#[test]
#[allow(clippy::eq_op)]
fn test_hid_packet_iterator_max_packets() {
let mut payload = vec![0xFF; 64 - 7];
for i in 0..128 {
Expand All @@ -244,14 +245,13 @@ mod test {
payload,
};

let mut expected_packets = Vec::new();
expected_packets.push([
let mut expected_packets = vec![[
0x12, 0x34, 0x56, 0x78, 0xAB, 0x1D, 0xB9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
]);
]];
for i in 0..128 {
let mut packet: HidPacket = [0; 64];
packet[0] = 0x12;
Expand Down
2 changes: 1 addition & 1 deletion tools/heapviz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Apache-2.0"
edition = "2018"

[dependencies]
clap = "2.33.1"
clap = "~2.27.*"
lazy_static = "1.4.0"
ncurses = "5.99.0"
regex = "1"

0 comments on commit 64b0ae7

Please sign in to comment.