use der_parser::der::parse_der;
use rpki::data_model::tal::Tal;

#[test]
fn decode_tal_fixtures_smoke() {
    let fixtures = [
        "tests/fixtures/tal/afrinic.tal",
        "tests/fixtures/tal/apnic-rfc7730-https.tal",
        "tests/fixtures/tal/arin.tal",
        "tests/fixtures/tal/lacnic.tal",
        "tests/fixtures/tal/ripe-ncc.tal",
    ];

    for path in fixtures {
        let raw = std::fs::read(path).expect("read TAL fixture");
        let tal = Tal::decode_bytes(&raw).expect("decode TAL fixture");

        assert!(
            !tal.ta_uris.is_empty(),
            "TA URI list must be non-empty: {path}"
        );
        assert!(
            !tal.subject_public_key_info_der.is_empty(),
            "SPKI DER must be non-empty: {path}"
        );

        for u in &tal.ta_uris {
            assert!(
                matches!(u.scheme(), "rsync" | "https"),
                "scheme must be allowed: {u}"
            );
            assert!(
                !u.path().ends_with('/'),
                "TA URI must not be a directory: {u}"
            );
        }

        // SPKI DER must be parseable as a DER object (typically a SEQUENCE).
        let (rem, _obj) = parse_der(&tal.subject_public_key_info_der).expect("parse spki DER");
        assert!(
            rem.is_empty(),
            "SPKI DER must not have trailing bytes: {path}"
        );
    }
}
