8000 Add `PUT /api/v1/trusted_publishing/tokens` API endpoint by Turbo87 · Pull Request #11131 · rust-lang/crates.io · GitHub
[go: up one dir, main page]

Skip to content

Add PUT /api/v1/trusted_publishing/tokens API endpoint #11131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
trustpub: Add MockOidcKeyStore::with_test_key() fn
  • Loading branch information
Turbo87 committed Jun 2, 2025
commit 8d16fa09d270dba6ee5e95b4469c512494c038bd
3 changes: 2 additions & 1 deletion crates/crates_io_trustpub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2024"
workspace = true

[features]
test-helpers = ["dep:mockall"]
test-helpers = ["dep:mockall", "dep:serde_json"]

[dependencies]
anyhow = "=1.0.98"
Expand All @@ -18,6 +18,7 @@ mockall = { version = "=0.13.1", optional = true }
reqwest = { version = "=0.12.15", features = ["gzip", "json"] }
regex = "=1.11.1"
serde = { version = "=1.0.219", features = ["derive"] }
serde_json = { version = "=1.0.140", optional = true }
thiserror = "=2.0.12"
tokio = { version = "=1.45.1", features = ["sync"] }
tracing = "=0.1.41"
Expand Down
18 changes: 18 additions & 0 deletions crates/crates_io_trustpub/src/keystore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ pub trait OidcKeyStore: Send + Sync {
/// is an error while fetching the key, it will return an error.
async fn get_oidc_key(&self, key_id: &str) -> anyhow::Result<Option<DecodingKey>>;
}

#[cfg(feature = "test-helpers")]
impl MockOidcKeyStore {
/// Creates a new instance of [`MockOidcKeyStore`] based on the RSA keys
/// provided in the [`crate::test_keys`] module.
pub fn with_test_key() -> Self {
use crate::test_keys::{DECODING_KEY, KEY_ID};
use mockall::predicate::*;

let mut mock = Self::new();

mock.expect_get_oidc_key()
.with(eq(KEY_ID))
.returning(|_| Ok(Some(DECODING_KEY.clone())));

mock
}
}
2 changes: 1 addition & 1 deletion crates/crates_io_trustpub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

pub mod github;
pub mod keystore;
#[cfg(test)]
#[cfg(any(test, feature = "test-helpers"))]
pub mod test_keys;
1 change: 0 additions & 1 deletion crates/crates_io_trustpub/src/test_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub(crate) const KEY_ID: &str = "c0ffee";
static ENCODING_KEY: LazyLock<EncodingKey> =
LazyLock::new(|| EncodingKey::from_rsa_pem(PRIVATE_KEY_PEM).unwrap());

#[allow(unused)]
pub(crate) static DECODING_KEY: LazyLock<DecodingKey> = LazyLock::new(|| {
let jwk = serde_json::from_str(PUBLIC_KEY_JWK).unwrap();
DecodingKey::from_jwk(&jwk).unwrap()
Expand Down
0