Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion crates/geoip/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl ZoneFilter {
let country = geo_data.country.iso_code.ok_or(Error::CountryNotFound)?;

let zone_blocked = self.blocked_zones.iter().any(|blocked_zone| {
if blocked_zone.country == country {
if blocked_zone.country.eq_ignore_ascii_case(country) {
if blocked_zone.subdivisions.is_empty() {
true
} else {
Expand Down
21 changes: 21 additions & 0 deletions crates/geoip/src/block/middleware/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ async fn test_country_blocked() {
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}

/// A lowercase country code is the same block as the uppercase code MaxMind
/// returns.
#[tokio::test]
async fn test_country_blocked_ignores_ascii_case() {
let resolver = LocalResolver::new(Some(resolve_ip), None);
let blocked_countries = vec!["cu".into()];

let geoblock = GeoBlockLayer::new(resolver, blocked_countries, BlockingPolicy::Block);

let mut service = ServiceBuilder::new().layer(geoblock).service_fn(handle);

let request = Request::builder()
.header("X-Forwarded-For", "127.0.0.1")
.body(Body::empty())
.unwrap();

let response = service.ready().await.unwrap().call(request).await.unwrap();

assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
}

/// Test that a blocking list with no subdivisions doesn't block if the
/// country doesn't match.
#[tokio::test]
Expand Down