Skip to content

Commit

Permalink
sign: move TestSigningBackend to lib
Browse files Browse the repository at this point in the history
We need to make `TestSigningBackend` available for cli tests, as we are
implementing the `jj sign` command in following changes.
  • Loading branch information
pylbrecht committed Nov 8, 2024
1 parent b0eb776 commit 332902e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -167,6 +168,10 @@ impl Signer {
// Box::new(X509Backend::from_settings(settings)?) as Box<dyn SigningBackend>,
];

if cfg!(feature = "testing") {
backends.push(Box::new(TestSigningBackend) as Box<dyn SigningBackend>);
}

let main_backend = settings
.signing_backend()
.map(|backend| {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/tests/test_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion lib/testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ use tempfile::TempDir;
use crate::test_backend::TestBackendFactory;

pub mod test_backend;
pub mod test_signing_backend;

pub fn hermetic_libgit2() {
// libgit2 respects init.defaultBranch (and possibly other config
Expand Down

0 comments on commit 332902e

Please sign in to comment.