use mockito::Server;
use sigstore_verification::{AttestationError, verify_github_attestation_with_base_url};
use std::io::Write;
use tempfile::NamedTempFile;
#[tokio::test]
async fn test_verify_with_base_url_queries_custom_host() {
let mut server = Server::new_async().await;
let mock = server
.mock(
"GET",
mockito::Matcher::Regex(r"^/repos/owner/repo/attestations/sha256:.+$".into()),
)
.match_query(mockito::Matcher::Any)
.match_header("authorization", "Bearer ghes-token")
.match_header("x-github-api-version", "2022-11-28")
.with_status(200)
.with_body(r#"{"attestations":[]}"#)
.create_async()
.await;
let mut tmp = NamedTempFile::new().unwrap();
tmp.write_all(b"test artifact contents").unwrap();
tmp.flush().unwrap();
let result = verify_github_attestation_with_base_url(
tmp.path(),
"owner",
"repo",
Some("ghes-token"),
None,
&server.url(),
)
.await;
assert!(matches!(result, Err(AttestationError::NoAttestations)));
mock.assert_async().await;
}