Skip to content

Commit

Permalink
[fix] Linter errors & test update
Browse files Browse the repository at this point in the history
  • Loading branch information
lpascal-ledger committed Feb 28, 2024
1 parent d0a8456 commit e043f78
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 85 deletions.
8 changes: 0 additions & 8 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install cmocka
run: |
sudo apt update
Expand All @@ -37,7 +37,7 @@ jobs:
lcov --directory . -b "$(realpath build/)" --add-tracefile coverage.base --add-tracefile coverage.capture -o coverage.info
lcov --directory . -b "$(realpath build/)" --remove coverage.info '*/unit-tests/*' -o coverage.info
genhtml coverage.info -o coverage
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: code-coverage
path: tests/unit/coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Lint
uses: DoozyX/[email protected]
Expand All @@ -32,7 +32,7 @@ jobs:

steps:
- name: Clone
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
1 change: 0 additions & 1 deletion src/apdu_handlers/dump_metadatas.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "io.h"
#include "password_ui_flows.h"


int dump_metadatas() {
if (app_state.user_approval == false) {
app_state.bytes_transferred = 0;
Expand Down
1 change: 0 additions & 1 deletion src/apdu_handlers/load_metadatas.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "metadata.h"
#include "password_ui_flows.h"


int load_metadatas(uint8_t p1, uint8_t p2, const buf_t *input) {
if ((p1 != 0 && p1 != P1_LAST_CHUNK) || p2 != 0) {
return io_send_sw(SW_WRONG_P1P2);
Expand Down
2 changes: 0 additions & 2 deletions src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@
#include "password_ui_flows.h"
#include "password_typing.h"


const internalStorage_t N_storage_real;
app_state_t app_state;
volatile unsigned int G_led_status;


void app_main() {
int input_len = 0;

Expand Down
5 changes: 1 addition & 4 deletions src/error.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "error.h"


static const message_pair_t ERR_MESSAGES[5] = {
// OK
{},
Expand All @@ -11,9 +10,7 @@ static const message_pair_t ERR_MESSAGES[5] = {
// ERR_NO_METADATA
{"Erase Error", "Database already empty"},
// ERR_METADATA_ENTRY_TOO_BIG
{"Write Error", "Entry is too big"}
};

{"Write Error", "Entry is too big"}};

message_pair_t get_error(const error_type_t error) {
return ERR_MESSAGES[error];
Expand Down
2 changes: 0 additions & 2 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define SW_APPNAME_TOO_LONG 0xB000
#define SW_METADATAS_PARSING_ERROR 0x6F10


typedef enum error_type_e {
OK = 0,
ERR_NO_MORE_SPACE_AVAILABLE = 1,
Expand All @@ -20,5 +19,4 @@ typedef enum error_type_e {
ERR_METADATA_ENTRY_TOO_BIG = 4
} error_type_t;


message_pair_t get_error(const error_type_t error);
86 changes: 41 additions & 45 deletions src/hid_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@

static const uint8_t TWOPOWER[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};


typedef struct mapping_s {
uint8_t qwerty;
uint8_t azerty;
} mapping_t;


static const mapping_t MAP[] = {
// alt mask from ascii 0x20
{0x00, 0x08},
Expand Down Expand Up @@ -60,40 +58,40 @@ static const mapping_t MAP[] = {
{0x00, 0x00},
{0x78, 0x00},
// key codes from ascii 0x20
{0x2c, 0x2c}, // ' ' (i = 32 - 8)
{0x1e, 0x38}, // '!'
{0x34, 0x20}, // '"'
{0x20, 0x20}, // '#'
{0x21, 0x30}, // '$'
{0x22, 0x34}, // '%'
{0x24, 0x1e}, // '&'
{0x34, 0x21}, // '''
{0x26, 0x22}, // '('
{0x27, 0x2d}, // ')'
{0x25, 0x32}, // '*'
{0x2e, 0x2e}, // '+'
{0x36, 0x10}, // ','
{0x2d, 0x23}, // '-'
{0x37, 0x36}, // '.'
{0x38, 0x37}, // '/'
{0x27, 0x27}, // '0' (i = 48 - 8)
{0x1e, 0x1e}, // '1'
{0x2c, 0x2c}, // ' ' (i = 32 - 8)
{0x1e, 0x38}, // '!'
{0x34, 0x20}, // '"'
{0x20, 0x20}, // '#'
{0x21, 0x30}, // '$'
{0x22, 0x34}, // '%'
{0x24, 0x1e}, // '&'
{0x34, 0x21}, // '''
{0x26, 0x22}, // '('
{0x27, 0x2d}, // ')'
{0x25, 0x32}, // '*'
{0x2e, 0x2e}, // '+'
{0x36, 0x10}, // ','
{0x2d, 0x23}, // '-'
{0x37, 0x36}, // '.'
{0x38, 0x37}, // '/'
{0x27, 0x27}, // '0' (i = 48 - 8)
{0x1e, 0x1e}, // '1'
{0x1f, 0x1f},
{0x20, 0x20},
{0x21, 0x21},
{0x22, 0x22},
{0x23, 0x23},
{0x24, 0x24},
{0x25, 0x25},
{0x26, 0x26}, // '9'
{0x33, 0x37}, // ':'
{0x33, 0x36}, // ';'
{0x36, 0x64}, // '<'
{0x2e, 0x2e}, // '='
{0x37, 0x64}, // '>'
{0x38, 0x10}, // '?'
{0x1f, 0x27}, // '@'
{0x04, 0x14}, // 'A' (i = 65 - 8)
{0x26, 0x26}, // '9'
{0x33, 0x37}, // ':'
{0x33, 0x36}, // ';'
{0x36, 0x64}, // '<'
{0x2e, 0x2e}, // '='
{0x37, 0x64}, // '>'
{0x38, 0x10}, // '?'
{0x1f, 0x27}, // '@'
{0x04, 0x14}, // 'A' (i = 65 - 8)
{0x05, 0x05},
{0x06, 0x06},
{0x07, 0x07},
Expand All @@ -118,14 +116,14 @@ static const mapping_t MAP[] = {
{0x1a, 0x1d},
{0x1b, 0x1b},
{0x1c, 0x1c},
{0x1d, 0x1a}, // 'Z' (i = 90 - 8)
{0x2f, 0x22}, // '['
{0x31, 0x25}, // '\'
{0x30, 0x2D}, // ']'
{0x23, 0x26}, // '^'
{0x2d, 0x25}, // '_'
{0x35, 0x24}, // '`'
{0x04, 0x14}, // 'a' (i = 97 - 8)
{0x1d, 0x1a}, // 'Z' (i = 90 - 8)
{0x2f, 0x22}, // '['
{0x31, 0x25}, // '\'
{0x30, 0x2D}, // ']'
{0x23, 0x26}, // '^'
{0x2d, 0x25}, // '_'
{0x35, 0x24}, // '`'
{0x04, 0x14}, // 'a' (i = 97 - 8)
{0x05, 0x05},
{0x06, 0x06},
{0x07, 0x07},
Expand All @@ -150,25 +148,23 @@ static const mapping_t MAP[] = {
{0x1a, 0x1d},
{0x1b, 0x1b},
{0x1c, 0x1c},
{0x1d, 0x1a}, // 'z' (i = 122 - 8)
{0x2f, 0x21}, // '{'
{0x31, 0x23}, // '|'
{0x30, 0x2e}, // '}'
{0x35, 0x1f}, // '~' (i = 126 - 8)
{0x1d, 0x1a}, // 'z' (i = 122 - 8)
{0x2f, 0x21}, // '{'
{0x31, 0x23}, // '|'
{0x30, 0x2e}, // '}'
{0x35, 0x1f}, // '~' (i = 126 - 8)
};

#if 0
// a good test string
out = "a&b~c#d {e\"f'g(h -i _j)k=l+m [n |o \\p^q @r ]s }t$u!v:w/x;y.z,A?B <C >D`EFGHIJKLMNOPQRSTUVWXYZ0123456789";
#endif


static uint8_t get_char(uint8_t index, hid_mapping_t mapping) {
// all mapping != AZERTY fall back to QWERTY + some adjustements
// all mapping != AZERTY fall back to QWERTY + some adjustments
return (mapping == HID_MAPPING_AZERTY ? MAP[index].azerty : MAP[index].qwerty);
}


void map_char(hid_mapping_t mapping, uint8_t key, uint8_t *out) {
uint8_t keyDiv8, twoPower, keyCode;
bool altUsed, shiftUsed;
Expand Down
1 change: 0 additions & 1 deletion src/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "metadata.h"
#include "globals.h"


error_type_t write_metadata(uint8_t *data, uint8_t dataSize) {
if (dataSize > MAX_METANAME) {
dataSize = MAX_METANAME;
Expand Down
1 change: 0 additions & 1 deletion src/password_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <cx.h>
#include <password_generation.h>


static const char *SETS[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", // 26
"abcdefghijklmnopqrstuvwxyz", // 26
"0123456789", // 10
Expand Down
6 changes: 3 additions & 3 deletions src/password_typing.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include "password_typing.h"
#include "globals.h"


#define REPORT_SIZE 8
static const uint8_t EMPTY_REPORT[REPORT_SIZE] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t SPACE_REPORT[REPORT_SIZE] = {0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t CAPS_REPORT[REPORT_SIZE] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t CAPS_LOCK_REPORT[REPORT_SIZE] = {0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t CAPS_LOCK_REPORT[REPORT_SIZE] =
{0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t ENTER_REPORT[REPORT_SIZE] = {0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00};

bool entropyProvided;
Expand Down Expand Up @@ -47,7 +47,7 @@ static void usb_write_wait(unsigned char *buf) {
static void usb_write_wait(__attribute__((unused)) unsigned char *buf) {
return;
}
#endif // TESTING
#endif // TESTING

bool type_password(uint8_t *data,
uint32_t dataSize,
Expand Down
1 change: 0 additions & 1 deletion src/password_typing.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <password_generation.h>


bool type_password(uint8_t *data,
uint32_t dataSize,
uint8_t *out,
Expand Down
6 changes: 3 additions & 3 deletions src/password_ui_flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void ui_request_user_approval(message_pair_t *msg) {
display_approval_page(msg);
}

#else // if defined(TARGET_STAX)
#else // if defined(TARGET_STAX)

#include "keyboard.h"
#include "options.h"
Expand Down Expand Up @@ -232,7 +232,7 @@ static void toggle_password_setting(uint8_t caller_id, uint8_t symbols_bitflag);
static void create_password_entry();
#if defined(TARGET_NANOS)
static void display_nickname_explanation();
#endif // #if defined(TARGET_NANOS)
#endif // #if defined(TARGET_NANOS)
static void enter_password_nickname();

// clang-format off
Expand Down Expand Up @@ -635,4 +635,4 @@ void ui_idle() {
}
}

#endif // else( if defined(TARGET_STAX) )
#endif // else( if defined(TARGET_STAX) )
1 change: 0 additions & 1 deletion src/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "password_typing.h"
#include "tests.h"


/* Takes a metadata as an input (charset + seed) and returns a 20 char password*/
int test_generate_password(const buf_t *input) {
uint8_t enabledSets = input->bytes[0];
Expand Down
Binary file modified tests/functional/snapshots/stax/all_passwords_deleted_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/functional/snapshots/stax/password_created_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/functional/snapshots/stax/password_deleted_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions tests/functional/stax/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def format_instructions(instructions: Iterable[Union[NavIns, CustomNavInsID]]) -

@pytest.mark.use_on_firmware("stax")
def test_immediate_quit(navigator):
navigator.navigate(format_instructions([CustomNavInsID.HOME_TO_QUIT]),
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False)
with pytest.raises(ConnectionError):
navigator.navigate(format_instructions([CustomNavInsID.HOME_TO_QUIT]),
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False)


@pytest.mark.use_on_firmware("stax")
Expand All @@ -25,9 +26,10 @@ def test_settings_screens(navigator):
CustomNavInsID.SETTINGS_TO_HOME,
CustomNavInsID.HOME_TO_QUIT
])
navigator.navigate(instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False)
with pytest.raises(ConnectionError):
navigator.navigate(instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False)


@pytest.mark.use_on_firmware("stax")
Expand Down Expand Up @@ -81,7 +83,6 @@ def test_create_password(navigator, functional_test_directory):
NavIns(CustomNavInsID.KEYBOARD_WRITE, ("e", )),
NavIns(CustomNavInsID.KEYBOARD_WRITE, ("w", )),
CustomNavInsID.KEYBOARD_TO_CONFIRM,
NavIns(NavInsID.WAIT, (2.5, )),
# return to list to see the newly created password
CustomNavInsID.MENU_TO_DISPLAY,
])
Expand Down

0 comments on commit e043f78

Please sign in to comment.