Skip to content

Commit

Permalink
revert intersects geometry validation (#550)
Browse files Browse the repository at this point in the history
* revert intersects geometry validation

* update changelog and prep for 2.2.2 release
  • Loading branch information
Phil Varner authored Jul 6, 2023
1 parent 9a53182 commit 6877c29
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 74 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.2.2] - 2023-07-06

### Changed

- Revert validation of Search intersects geometry added in 2.0.0, as it was too strict
and rejected some usable geometries.

## [2.2.1] - 2023-07-06

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "stac-server",
"description": "A STAC API running on stac-server",
"version": "2.2.1",
"version": "2.2.2",
"repository": "https://github.com/stac-utils/stac-server",
"author": "Alireza Jazayeri, Matthew Hanson <matt.a.hanson@gmail.com>, Sean Harkins",
"license": "MIT",
Expand Down
26 changes: 13 additions & 13 deletions src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pickBy, assign, get as getNested } from 'lodash-es'
import extent from '@mapbox/extent'
import { DateTime } from 'luxon'
import AWS from 'aws-sdk'
import geojsonhint from '@mapbox/geojsonhint'
// import geojsonhint from '@mapbox/geojsonhint'
import { isIndexNotFoundError } from './database.js'
import logger from './logger.js'

Expand Down Expand Up @@ -618,18 +618,18 @@ const searchItems = async function (collectionId, queryParameters, backend, endp

logger.info('Search parameters (processed): %j', searchParams)

try { // Attempt to catch invalid geometry before querying Search
const hints = geometry ? geojsonhint.hint(geometry, {}) : []

if (hints.length > 0) {
return {
statusCode: 400,
body: hints.map(({ message }) => ({ message }))
}
}
} catch (e) {
logger.error(e)
}
// try { // Attempt to catch invalid geometry before querying Search
// const hints = geometry ? geojsonhint.hint(geometry, {}) : []

// if (hints.length > 0) {
// return {
// statusCode: 400,
// body: hints.map(({ message }) => ({ message }))
// }
// }
// } catch (e) {
// logger.error(e)
// }

let esResponse
try {
Expand Down
121 changes: 63 additions & 58 deletions tests/system/test-api-search-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename) // eslint-disable-line no-unused-vars
const intersectsGeometry = fs.readFileSync(path.resolve(__dirname, '../fixtures/stac/intersectsGeometry.json'), 'utf8')

const fixture = (filepath) => fs.readFileSync(path.resolve(__dirname, filepath), 'utf8')
// const fixture = (filepath) => fs.readFileSync(path.resolve(__dirname, filepath), 'utf8')

const ingestEntities = async (fixtures) => {
await ingestItems(
Expand Down Expand Up @@ -420,63 +420,68 @@ test('/search preserve intersects geometry in next link', async (t) => {
t.deepEqual(nextLink.body.intersects, intersectsGeometry)
})

test('POST /search using bad geometry, expecting useful error messages', async (t) => {
let response = null

response = await t.context.api.client.post('search', {
json: {
intersects: fixture('../fixtures/geometry/badGeoUnclosed.json')
}
})
t.is(response.statusCode, 400)
t.deepEqual(response.body, [{ message: 'the first and last positions in a LinearRing of coordinates must be the same' }])

response = await t.context.api.client.post('search', {
json: {
intersects: fixture('../fixtures/geometry/badGeoRightHandRule.json')
}
})
t.is(response.statusCode, 400)
t.deepEqual(response.body, [{ message: 'Polygons and MultiPolygons should follow the right-hand rule' }])

response = await t.context.api.client.post('search', {
json: {
intersects: fixture('../fixtures/geometry/badGeoFourPoints.json')
}
})
t.is(response.statusCode, 400)
t.deepEqual(response.body, [
{
reason: 'failed to create query: at least 4 polygon points required'
},
{
reason: 'failed to create query: at least 4 polygon points required'
}
])

response = await t.context.api.client.post('search', {
json: {
intersects: fixture('../fixtures/geometry/badGeoDuplicateConsecutive.json')
}
})
t.is(response.statusCode, 400)
t.deepEqual(response.body, [
{
reason: 'failed to create query: Provided shape has duplicate consecutive coordinates at: (POINT (100.0 1.0))'
},
{
reason: 'failed to create query: Provided shape has duplicate consecutive coordinates at: (POINT (100.0 1.0))'
}
])

response = await t.context.api.client.post('search', {
json: {
intersects: fixture('../fixtures/geometry/badGeoRightHandRule2.json')
}
})
t.is(response.statusCode, 400)
t.deepEqual(response.body, [{ message: 'Polygons and MultiPolygons should follow the right-hand rule' }])
})
// test('POST /search using bad geometry, expecting useful error messages', async (t) => {
// let response = null

// response = await t.context.api.client.post('search', {
// json: {
// intersects: fixture('../fixtures/geometry/badGeoUnclosed.json')
// }
// })
// t.is(response.statusCode, 400)
// t.deepEqual(response.body,
// [{ message: 'the first and last positions in a LinearRing of coordinates must be the same' }])

// response = await t.context.api.client.post('search', {
// json: {
// intersects: fixture('../fixtures/geometry/badGeoRightHandRule.json')
// }
// })
// t.is(response.statusCode, 400)
// t.deepEqual(response.body,
// [{ message: 'Polygons and MultiPolygons should follow the right-hand rule' }])

// response = await t.context.api.client.post('search', {
// json: {
// intersects: fixture('../fixtures/geometry/badGeoFourPoints.json')
// }
// })
// t.is(response.statusCode, 400)
// t.deepEqual(response.body, [
// {
// reason: 'failed to create query: at least 4 polygon points required'
// },
// {
// reason: 'failed to create query: at least 4 polygon points required'
// }
// ])

// response = await t.context.api.client.post('search', {
// json: {
// intersects: fixture('../fixtures/geometry/badGeoDuplicateConsecutive.json')
// }
// })
// t.is(response.statusCode, 400)
// t.deepEqual(response.body, [
// {
// reason: 'failed to create query:
// Provided shape has duplicate consecutive coordinates at: (POINT (100.0 1.0))'
// },
// {
// reason: 'failed to create query:
// Provided shape has duplicate consecutive coordinates at: (POINT (100.0 1.0))'
// }
// ])

// response = await t.context.api.client.post('search', {
// json: {
// intersects: fixture('../fixtures/geometry/badGeoRightHandRule2.json')
// }
// })
// t.is(response.statusCode, 400)
// t.deepEqual(response.body,
// [{ message: 'Polygons and MultiPolygons should follow the right-hand rule' }])
// })

test('/search preserve bbox in prev and next links', async (t) => {
const bbox = [-180, -90, 180, 90]
Expand Down

0 comments on commit 6877c29

Please sign in to comment.