Skip to content

Commit 8200249

Browse files
committed
add ENABLE_COLLECTIONS_AUTHX
1 parent 1897fe7 commit 8200249

13 files changed

+42
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2222

2323
- To all endpoints that depend on collections, add support for a query parameter (GET)
2424
or body field (POST) `_collections` that will filter to only those collections, but
25-
will not reveal that in link contents.
25+
will not reveal that in link contents. This is controlled by the "ENABLE_COLLECTIONS_AUTHX"
2626

2727
## [3.11.0] - 2025-03-27
2828

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ There are some settings that should be reviewed and updated as needeed in the se
583583
| REQUEST_LOGGING_FORMAT | Express request logging format to use. Any of the [Morgan predefined formats](https://github.com/expressjs/morgan#predefined-formats). | tiny |
584584
| STAC_API_URL | The root endpoint of this API | Inferred from request |
585585
| ENABLE_TRANSACTIONS_EXTENSION | Boolean specifying if the [Transaction Extension](https://github.com/radiantearth/stac-api-spec/tree/master/ogcapi-features/extensions/transaction) should be activated | false |
586-
| ENABLE_CONTEXT_EXTENSION | Boolean specifying if the [Context Extension](https://github.com/stac-api-extensions/context) should be activated | false |
586+
| ENABLE_CONTEXT_EXTENSION | Boolean specifying if the [Context Extension](https://github.com/stac-api-extensions/context) should be activated | false |
587587
| STAC_API_ROOTPATH | The path to append to URLs if this is not deployed at the server root. For example, if the server is deployed without a custom domain name, it will have the stage name (e.g., dev) in the path. | "" |
588588
| PRE_HOOK | The name of a Lambda function to be called as the pre-hook. | none |
589589
| POST_HOOK | The name of a Lambda function to be called as the post-hook. | none |
@@ -598,6 +598,7 @@ There are some settings that should be reviewed and updated as needeed in the se
598598
| CORS_CREDENTIALS | Configure whether or not to send the `Access-Control-Allow-Credentials` CORS header. Header will be sent if set to `true`. | none |
599599
| CORS_METHODS | Configure whether or not to send the `Access-Control-Allow-Methods` CORS header. Expects a comma-delimited string, e.g., `GET,PUT,POST`. | `GET,HEAD,PUT,PATCH,POST,DELETE` |
600600
| CORS_HEADERS | Configure whether or not to send the `Access-Control-Allow-Headers` CORS header. Expects a comma-delimited string, e.g., `Content-Type,Authorization`. If not specified, defaults to reflecting the headers specified in the request’s `Access-Control-Request-Headers` header. | none |
601+
| ENABLE_COLLECTIONS_AUTHX | Enables support for hidden `_collections` query parameter / field when set to `true`. | none |
601602

602603
Additionally, the credential for OpenSearch must be configured, as decribed in the
603604
section [Populating and accessing credentials](#populating-and-accessing-credentials).
@@ -1110,6 +1111,8 @@ parameter named (for GET requests) or body JSON field (for POST requests) named
11101111
to filter the collections a user has access to. This parameter/field will be excluded
11111112
from pagination links, so it does not need to be removed on egress.
11121113

1114+
This feature must be enabled with the `ENABLE_COLLECTIONS_AUTHX` configuration.
1115+
11131116
The endpoints this applies to are:
11141117

11151118
- /collections

src/lib/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ const extractIds = function (params) {
336336
}
337337

338338
const extractAllowedCollectionIds = function (params) {
339-
return parseIds(params._collections)
339+
return process.env['ENABLE_COLLECTIONS_AUTHX'] === 'true'
340+
? parseIds(params._collections)
341+
: undefined
340342
}
341343

342344
const extractCollectionIds = function (params) {

tests/system/test-api-collection-items-get.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ test('GET /collections/:collectionId/items for non-existent collection returns 4
9494

9595
test('GET /collections/:collectionId/items with restriction returns filtered collections', async (t) => {
9696
const { collectionId } = t.context
97+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
9798

9899
const path = `collections/${collectionId}/items`
99100

tests/system/test-api-get-aggregate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ test('GET /aggregate with aggregations and filter params', async (t) => {
502502
})
503503

504504
test('GET /aggregate with restriction returns filtered collections', async (t) => {
505+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
506+
505507
const fixtureFiles = [
506508
'collection.json',
507509
'LC80100102015050LGN00.json',

tests/system/test-api-get-collection-aggregate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ test('GET /aggregate with aggregation not supported by this collection', async (
169169
})
170170

171171
test('GET /collections/:collectionId/aggregate with restriction returns filtered collections', async (t) => {
172+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
173+
172174
const collectionId = 'landsat-8-l1'
173175

174176
const path = `collections/${collectionId}/aggregate`

tests/system/test-api-get-collection-aggregations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ test('GET /collections/:collectionId/aggregations returns default aggregations f
131131
})
132132

133133
test('GET /collections/:collectionId/aggregations with restriction returns filtered collections', async (t) => {
134+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
135+
134136
const { collectionId } = t.context
135137

136138
const path = `collections/${collectionId}/aggregations`

tests/system/test-api-get-collection-queryables.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ test.only('GET /collection/:collectionId/queryables for collection with unsuppor
113113
})
114114

115115
test('GET /collections/:collectionId/queryables with restriction returns filtered collections', async (t) => {
116+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
117+
116118
const { collectionId } = t.context
117119

118120
const path = `collections/${collectionId}/queryables`

tests/system/test-api-get-collection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ test('GET /collection/:collectionId for non-existent collection returns Not Foun
6161
})
6262

6363
test('GET /collections/:collectionId with restriction returns filtered collections', async (t) => {
64+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
65+
6466
const { collectionId } = t.context
6567

6668
t.is((await t.context.api.client.get(`collections/${collectionId}`,

tests/system/test-api-get-collections.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,25 @@ test('GET /collections has a content type of "application/json', async (t) => {
5151
})
5252

5353
test('GET /collections with restriction returns filtered collections', async (t) => {
54+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
55+
5456
await refreshIndices()
5557

5658
const { collectionId } = t.context
5759

60+
// disable collections filtering
61+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'not true'
62+
63+
t.is((await t.context.api.client.get(
64+
'collections', {
65+
searchParams: { _collections: 'not-a-collection' } }
66+
)
67+
).collections.length, 1)
68+
69+
// enable collections filtering
70+
71+
process.env['ENABLE_COLLECTIONS_AUTHX'] = 'true'
72+
5873
t.is((await t.context.api.client.get(
5974
'collections', {
6075
searchParams: { _collections: `${collectionId},foo,bar` } }

0 commit comments

Comments
 (0)