use rpki::data_model::oid::{OID_CT_RPKI_MANIFEST, OID_SHA256, OID_SIGNED_DATA};
use rpki::data_model::signed_object::{EeKeyUsageSummary, RpkiSignedObject};

#[test]
fn decode_manifest_signed_object_smoke() {
    let der = std::fs::read(
        "tests/fixtures/repository/rpki.cernet.net/repo/cernet/0/05FC9C5B88506F7C0D3F862C8895BED67E9F8EBA.mft",
    )
    .expect("read MFT fixture");

    let so = RpkiSignedObject::decode_der(&der).expect("decode signed object");

    assert_eq!(so.content_info_content_type, OID_SIGNED_DATA);
    assert_eq!(so.signed_data.version, 3);
    assert_eq!(
        so.signed_data.digest_algorithms,
        vec![OID_SHA256.to_string()]
    );
    assert_eq!(
        so.signed_data.encap_content_info.econtent_type,
        OID_CT_RPKI_MANIFEST
    );
    assert_eq!(so.signed_data.certificates.len(), 1);
    assert!(
        !so.signed_data.certificates[0]
            .sia_signed_object_uris
            .is_empty()
    );
    assert!(
        so.signed_data.certificates[0]
            .sia_signed_object_uris
            .iter()
            .any(|u| u.starts_with("rsync://"))
    );
    assert!(
        !so.signed_data.certificates[0]
            .tbs_certificate_der
            .is_empty(),
        "expected cached tbsCertificate DER"
    );
    assert!(
        !so.signed_data.certificates[0].signature_bytes.is_empty(),
        "expected cached EE signature bytes"
    );
    assert_eq!(
        so.signed_data.certificates[0].key_usage_summary,
        EeKeyUsageSummary::DigitalSignatureOnly
    );
    assert_eq!(so.signed_data.signer_infos.len(), 1);
    println!("{so:#?}")
}
