Skip to content

Commit

Permalink
backups: add shared message backup test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
akonradi-signal authored May 24, 2024
1 parent e925c5d commit 31d6015
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 53 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0
id: filter
Expand Down Expand Up @@ -108,11 +110,13 @@ jobs:
toolchain: "$(cat rust-toolchain)"
- version: stable
toolchain: "${LIBSIGNAL_MINIMUM_SUPPORTED_RUST_VERSION}"

timeout-minutes: 45

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: sudo apt-get update && sudo apt-get install protobuf-compiler

Expand Down Expand Up @@ -234,6 +238,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: sudo apt-get update && sudo apt-get install gcc-multilib g++-multilib protobuf-compiler

Expand Down Expand Up @@ -264,6 +270,7 @@ jobs:

- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
# Download all commits so we can search for the merge base with origin/main.
fetch-depth: 0

Expand Down Expand Up @@ -306,6 +313,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: rustup toolchain install $(cat rust-toolchain) --profile minimal

Expand Down Expand Up @@ -362,6 +371,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: rustup toolchain install $(cat rust-toolchain) --profile minimal

Expand Down Expand Up @@ -397,6 +408,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: brew install protobuf swiftlint

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ios_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- name: Checking run eligibility
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/jni_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- name: Checking run eligibility
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand Down Expand Up @@ -96,6 +98,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: rustup toolchain install $(cat rust-toolchain) --profile minimal

Expand All @@ -115,6 +119,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- name: Download built libraries
id: download
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
- run: pip3 install flake8 mypy
- run: shellcheck **/*.sh bin/verify_duplicate_crates bin/adb-run-test
- run: python3 -m flake8 .
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- name: Checking run eligibility
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand Down Expand Up @@ -104,6 +106,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: node/docker-prebuildify.sh

Expand All @@ -121,6 +125,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: rustup toolchain install $(cat rust-toolchain) --profile minimal

Expand All @@ -140,6 +146,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/slow_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
has-changes: ${{ steps.check.outputs.has-changes }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
- run: git log --after '24 hours ago' --exit-code || echo 'has-changes=true' >> $GITHUB_OUTPUT
id: check

Expand All @@ -34,6 +36,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
- run: make -C java java_test
- name: Upload JNI libraries
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
Expand Down Expand Up @@ -66,6 +70,8 @@ jobs:
sudo udevadm trigger --name-match=kvm
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- name: Download JNI libraries
id: download
Expand Down Expand Up @@ -113,6 +119,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
- run: node/docker-prebuildify.sh
- run: yarn tsc && yarn test
working-directory: node
Expand All @@ -128,6 +136,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
- run: rustup toolchain install $(cat rust-toolchain) --profile minimal --target aarch64-pc-windows-msvc
# install nasm compiler for boring
- name: Install nasm
Expand Down Expand Up @@ -160,6 +170,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: rustup toolchain install $(cat rust-toolchain) --profile minimal --target x86_64-apple-ios,aarch64-apple-ios,aarch64-apple-ios-sim --component rust-src

Expand Down Expand Up @@ -192,6 +204,8 @@ jobs:

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive

- run: sudo apt-get update && sudo apt-get install gcc-multilib g++-multilib protobuf-compiler

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "rust/message-backup/tests/res/Signal-Message-Backup-Tests"]
path = rust/message-backup/tests/res/Signal-Message-Backup-Tests
url = https://github.com/signalapp/Signal-Message-Backup-Tests.git
2 changes: 1 addition & 1 deletion node/ts/test/new_account.binproto.encrypted
1 change: 1 addition & 0 deletions rust/message-backup/tests/res/Signal-Message-Backup-Tests
1 change: 1 addition & 0 deletions rust/message-backup/tests/res/test-cases/valid

This file was deleted.

51 changes: 34 additions & 17 deletions rust/message-backup/tests/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,30 @@ const BACKUP_PURPOSE: Purpose = Purpose::RemoteBackup;
#[dir_test(
dir: "$CARGO_MANIFEST_DIR/tests/res/test-cases",
glob: "valid/*.jsonproto",
postfix: "binproto"
postfix: "jsonproto"
)]
fn is_valid_json_proto(input: Fixture<&str>) {
let json_contents = input.into_content();
let json_contents = serde_json::from_str(json_contents).expect("invalid JSON");
let json_array = assert_matches!(json_contents, serde_json::Value::Array(contents) => contents);
let binary =
let binproto =
libsignal_message_backup::backup::convert_from_json(json_array).expect("failed to convert");
validate_proto(&binproto)
}

// Check via the library interface.
let input = Cursor::new(&*binary);
let reader = BackupReader::new_unencrypted(input, BACKUP_PURPOSE);
validate(reader);

// The CLI tool should agree.
validator_command()
.arg("-")
.args(["--purpose", BACKUP_PURPOSE.into()])
.write_stdin(binary)
.ok()
.expect("command failed");
#[dir_test(
dir: "$CARGO_MANIFEST_DIR/tests/res/test-cases",
glob: "valid/*.binproto",
postfix: "binproto"
loader: read_file
)]
fn is_valid_binary_proto(input: Fixture<Vec<u8>>) {
validate_proto(input.content())
}

#[dir_test(
dir: "$CARGO_MANIFEST_DIR/tests/res/test-cases",
glob: "valid/*.binproto.encrypted",
glob: "valid-encrypted/*.binproto.encrypted",
loader: PathBuf::from,
postfix: "encrypted"
)]
Expand Down Expand Up @@ -98,10 +96,10 @@ fn invalid_jsonproto(input: Fixture<PathBuf>) {
serde_json::from_str(&std::fs::read_to_string(path).expect("failed to read"))
.expect("invalid JSON");
let json_array = assert_matches!(json_contents, serde_json::Value::Array(contents) => contents);
let binary =
let binproto =
libsignal_message_backup::backup::convert_from_json(json_array).expect("failed to convert");

let input = Cursor::new(&*binary);
let input = Cursor::new(&*binproto);
let reader = BackupReader::new_unencrypted(input, Purpose::RemoteBackup);

let ReadResult {
Expand All @@ -123,10 +121,29 @@ fn invalid_jsonproto(input: Fixture<PathBuf>) {
assert_eq!(text, expected_text);
}

fn read_file(path: &str) -> Vec<u8> {
std::fs::read(path).expect("can read")
}

fn write_expected_error() -> bool {
std::env::var_os("OVERWRITE_EXPECTED_OUTPUT").is_some()
}

fn validate_proto(binproto: &[u8]) {
// Check via the library interface.
let input = Cursor::new(binproto);
let reader = BackupReader::new_unencrypted(input, BACKUP_PURPOSE);
validate(reader);

// The CLI tool should agree.
validator_command()
.arg("-")
.args(["--purpose", BACKUP_PURPOSE.into()])
.write_stdin(binproto)
.ok()
.expect("command failed");
}

fn validate(mut reader: BackupReader<impl AsyncRead + Unpin + VerifyHmac>) {
reader.visitor = |msg| println!("{msg:#?}");

Expand Down

0 comments on commit 31d6015

Please sign in to comment.