From d5251f4ba560e6247254f374d6ee7beffd9853e1 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Fri, 1 Nov 2024 10:24:18 +0100 Subject: [PATCH] sign: move TestSigningBackend to lib We need to make `TestSigningBackend` available for cli tests, as we are implementing the `jj sign` command in following changes. --- lib/src/lib.rs | 3 ++- lib/src/signing.rs | 5 +++++ .../src/test_signing_backend.rs | 18 ++++++++++++++++++ lib/tests/test_signing.rs | 2 +- lib/testutils/src/lib.rs | 1 - 5 files changed, 26 insertions(+), 3 deletions(-) rename lib/{testutils => }/src/test_signing_backend.rs (69%) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d629ba88c1d..5f07cc5e603 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -75,7 +75,6 @@ pub mod repo_path; pub mod revset; mod revset_parser; pub mod rewrite; -#[cfg(feature = "testing")] pub mod secret_backend; pub mod settings; pub mod signing; @@ -86,6 +85,8 @@ pub mod stacked_table; pub mod store; pub mod str_util; pub mod submodule_store; +#[cfg(feature = "testing")] +pub mod test_signing_backend; pub mod time_util; pub mod transaction; pub mod tree; diff --git a/lib/src/signing.rs b/lib/src/signing.rs index a15384cbb7a..3f224270613 100644 --- a/lib/src/signing.rs +++ b/lib/src/signing.rs @@ -25,6 +25,7 @@ use crate::backend::CommitId; use crate::gpg_signing::GpgBackend; use crate::settings::UserSettings; use crate::ssh_signing::SshBackend; +use crate::test_signing_backend::TestSigningBackend; /// A status of the signature, part of the [Verification] type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -167,6 +168,10 @@ impl Signer { // Box::new(X509Backend::from_settings(settings)?) as Box, ]; + if cfg!(feature = "testing") { + backends.push(Box::new(TestSigningBackend) as Box); + } + let main_backend = settings .signing_backend() .map(|backend| { diff --git a/lib/testutils/src/test_signing_backend.rs b/lib/src/test_signing_backend.rs similarity index 69% rename from lib/testutils/src/test_signing_backend.rs rename to lib/src/test_signing_backend.rs index 8d1d3369b9f..5e99dee4962 100644 --- a/lib/testutils/src/test_signing_backend.rs +++ b/lib/src/test_signing_backend.rs @@ -1,3 +1,20 @@ +// Copyright 2023 The Jujutsu Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Generic APIs to work with cryptographic signatures created and verified by +//! various backends. + use hex::ToHex; use jj_lib::content_hash::blake2b_hash; use jj_lib::signing::SigStatus; @@ -6,6 +23,7 @@ use jj_lib::signing::SignResult; use jj_lib::signing::SigningBackend; use jj_lib::signing::Verification; +/// A test signing backend that uses a simple hash-based signature format. #[derive(Debug)] pub struct TestSigningBackend; diff --git a/lib/tests/test_signing.rs b/lib/tests/test_signing.rs index a65da07b5c2..ca40a03411a 100644 --- a/lib/tests/test_signing.rs +++ b/lib/tests/test_signing.rs @@ -7,9 +7,9 @@ use jj_lib::signing::SigStatus; use jj_lib::signing::SignBehavior; use jj_lib::signing::Signer; use jj_lib::signing::Verification; +use jj_lib::test_signing_backend::TestSigningBackend; use test_case::test_case; use testutils::create_random_commit; -use testutils::test_signing_backend::TestSigningBackend; use testutils::write_random_commit; use testutils::TestRepoBackend; use testutils::TestWorkspace; diff --git a/lib/testutils/src/lib.rs b/lib/testutils/src/lib.rs index c9fe5f99644..d88faef4e02 100644 --- a/lib/testutils/src/lib.rs +++ b/lib/testutils/src/lib.rs @@ -64,7 +64,6 @@ use tempfile::TempDir; use crate::test_backend::TestBackend; pub mod test_backend; -pub mod test_signing_backend; pub fn hermetic_libgit2() { // libgit2 respects init.defaultBranch (and possibly other config