Files
visa/src/countries.rs
T
grabowski 2e009700a9
CI / secret scan (push) Successful in 4s
CI / fmt, clippy, tests (push) Successful in 42s
Phase 1: app, Kanidm login, people, passports, addresses, audit log
visa.buildfor.life keeps the immigration records of the foreigners B4L
looks after. This first phase is the base the deadlines and extension
packs build on (docs/PLAN.md, phases 2 to 7).

- One Rust binary (axum 0.8, minijinja, sqlx on PostgreSQL) with its
  templates, static files and migrations compiled in.
- Login through Kanidm (OpenID Connect with PKCE and a nonce, ES256),
  client visa-web, group visa; sessions in PostgreSQL keyed by the
  SHA-256 of the cookie. VISA_INSECURE_NO_LOGIN=1 for loopback
  development only.
- Same-site check and form token on every POST; a CSP without inline
  script or style; security headers.
- People: list with filter, page, create, edit, archive, restore.
- Passports from the machine-readable zone with check digits (ICAO
  9303 TD3); expiry warnings at 12 and 6 months.
- Addresses in Thailand in the order Thai forms use, with the house
  master and the TM.30 receipt.
- Append-only audit log of every view and change, with the names of the
  changed fields but never their values (PDPA); the Activity page.
- Invented demo people (visa seed-demo, refused when login is on).
- 40 tests: unit tests, pages with demo data, the forms, the audit log
  and the whole login against a fake OpenID provider.
- CI: gitleaks over the history, fmt, clippy and the tests against
  PostgreSQL 18; the pre-commit secret scan.
2026-11-17 16:58:48 +07:00

133 lines
2.7 KiB
Rust

//! Countries by ISO 3166-1 alpha-3 code (as passports' machine-readable
//! zones write them) and Thailand's provinces.
mod data {
include!("countries_data.rs");
}
pub use data::COUNTRIES;
/// The English short name of an alpha-3 code.
pub fn name(code: &str) -> Option<&'static str> {
COUNTRIES
.binary_search_by(|(c, _)| (*c).cmp(code))
.ok()
.map(|i| COUNTRIES[i].1)
}
pub fn is_known(code: &str) -> bool {
name(code).is_some()
}
/// `(code, "Name")` pairs sorted by name, for a select.
pub fn options() -> Vec<(&'static str, &'static str)> {
let mut v: Vec<(&str, &str)> = COUNTRIES.to_vec();
v.sort_by(|a, b| a.1.cmp(b.1));
v
}
/// The 77 provinces (76 and Bangkok) in the spelling the Department of
/// Provincial Administration uses in English.
pub static PROVINCES: &[&str] = &[
"Amnat Charoen",
"Ang Thong",
"Bangkok",
"Bueng Kan",
"Buriram",
"Chachoengsao",
"Chai Nat",
"Chaiyaphum",
"Chanthaburi",
"Chiang Mai",
"Chiang Rai",
"Chonburi",
"Chumphon",
"Kalasin",
"Kamphaeng Phet",
"Kanchanaburi",
"Khon Kaen",
"Krabi",
"Lampang",
"Lamphun",
"Loei",
"Lopburi",
"Mae Hong Son",
"Maha Sarakham",
"Mukdahan",
"Nakhon Nayok",
"Nakhon Pathom",
"Nakhon Phanom",
"Nakhon Ratchasima",
"Nakhon Sawan",
"Nakhon Si Thammarat",
"Nan",
"Narathiwat",
"Nong Bua Lamphu",
"Nong Khai",
"Nonthaburi",
"Pathum Thani",
"Pattani",
"Phang Nga",
"Phatthalung",
"Phayao",
"Phetchabun",
"Phetchaburi",
"Phichit",
"Phitsanulok",
"Phra Nakhon Si Ayutthaya",
"Phrae",
"Phuket",
"Prachinburi",
"Prachuap Khiri Khan",
"Ranong",
"Ratchaburi",
"Rayong",
"Roi Et",
"Sa Kaeo",
"Sakon Nakhon",
"Samut Prakan",
"Samut Sakhon",
"Samut Songkhram",
"Saraburi",
"Satun",
"Sing Buri",
"Sisaket",
"Songkhla",
"Sukhothai",
"Suphan Buri",
"Surat Thani",
"Surin",
"Tak",
"Trang",
"Trat",
"Ubon Ratchathani",
"Udon Thani",
"Uthai Thani",
"Uttaradit",
"Yala",
"Yasothon",
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sorted_and_complete() {
assert!(
COUNTRIES.windows(2).all(|w| w[0].0 < w[1].0),
"sorted by code"
);
assert!(COUNTRIES.len() >= 249);
assert_eq!(name("DEU"), Some("Germany"));
assert_eq!(name("THA"), Some("Thailand"));
assert_eq!(name("D"), None);
assert_eq!(PROVINCES.len(), 77);
assert!(
PROVINCES.windows(2).all(|w| w[0] < w[1]),
"provinces sorted"
);
assert_eq!(options()[0].1, "Afghanistan");
}
}