|
| 1 | +// @ts-nocheck |
| 2 | + |
| 3 | +/** |
| 4 | + * Asset Proxy System Tests |
| 5 | + * |
| 6 | + * These tests verify the asset proxy endpoints work correctly. |
| 7 | + * The env var is set before starting the API to test with proxying enabled. |
| 8 | + */ |
| 9 | + |
| 10 | +// Set env var before starting the API |
| 11 | +process.env['ASSET_PROXY_BUCKET_OPTION'] = 'ALL' |
| 12 | + |
| 13 | +/* eslint-disable import/first */ |
| 14 | +import test from 'ava' |
| 15 | +import { deleteAllIndices } from '../helpers/database.js' |
| 16 | +import { ingestItem } from '../helpers/ingest.js' |
| 17 | +import { randomId, loadFixture } from '../helpers/utils.js' |
| 18 | +import { setup } from '../helpers/system-tests.js' |
| 19 | +/* eslint-enable import/first */ |
| 20 | + |
| 21 | +test.before(async (t) => { |
| 22 | + await deleteAllIndices() |
| 23 | + const standUpResult = await setup() |
| 24 | + |
| 25 | + t.context = standUpResult |
| 26 | + |
| 27 | + t.context.collectionId = randomId('collection') |
| 28 | + |
| 29 | + const collection = await loadFixture( |
| 30 | + 'landsat-8-l1-collection.json', |
| 31 | + { id: t.context.collectionId } |
| 32 | + ) |
| 33 | + |
| 34 | + await ingestItem({ |
| 35 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 36 | + ingestTopicArn: t.context.ingestTopicArn, |
| 37 | + item: collection |
| 38 | + }) |
| 39 | + |
| 40 | + t.context.itemId = randomId('item') |
| 41 | + |
| 42 | + const item = await loadFixture( |
| 43 | + 'stac/LC80100102015082LGN00.json', |
| 44 | + { |
| 45 | + id: t.context.itemId, |
| 46 | + collection: t.context.collectionId |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + await ingestItem({ |
| 51 | + ingestQueueUrl: t.context.ingestQueueUrl, |
| 52 | + ingestTopicArn: t.context.ingestTopicArn, |
| 53 | + item |
| 54 | + }) |
| 55 | +}) |
| 56 | + |
| 57 | +test.after.always(async (t) => { |
| 58 | + if (t.context.api) await t.context.api.close() |
| 59 | +}) |
| 60 | + |
| 61 | +test('GET /collections/:collectionId/items/:itemId/assets/:assetKey - 302 redirect to presigned URL', async (t) => { |
| 62 | + const { collectionId, itemId } = t.context |
| 63 | + |
| 64 | + const response = await t.context.api.client.get( |
| 65 | + `collections/${collectionId}/items/${itemId}/assets/B1`, |
| 66 | + { |
| 67 | + resolveBodyOnly: false, |
| 68 | + throwHttpErrors: false, |
| 69 | + followRedirect: false |
| 70 | + } |
| 71 | + ) |
| 72 | + |
| 73 | + t.is(response.statusCode, 302) |
| 74 | + t.truthy(response.headers.location) |
| 75 | + t.true(response.headers.location.includes('landsat-pds')) |
| 76 | + t.true(response.headers.location.includes('X-Amz-Algorithm')) |
| 77 | + t.true(response.headers.location.includes('X-Amz-Signature')) |
| 78 | +}) |
| 79 | + |
| 80 | +test('GET /collections/:collectionId/assets/:assetKey - 302 redirect for collection assets', async (t) => { |
| 81 | + const { collectionId } = t.context |
| 82 | + |
| 83 | + const collection = await t.context.api.client.get( |
| 84 | + `collections/${collectionId}`, |
| 85 | + { resolveBodyOnly: false } |
| 86 | + ) |
| 87 | + |
| 88 | + if (!collection.body.assets || Object.keys(collection.body.assets).length === 0) { |
| 89 | + t.pass('Collection has no assets to test') |
| 90 | + return |
| 91 | + } |
| 92 | + |
| 93 | + const assetKey = Object.keys(collection.body.assets)[0] |
| 94 | + |
| 95 | + const response = await t.context.api.client.get( |
| 96 | + `collections/${collectionId}/assets/${assetKey}`, |
| 97 | + { |
| 98 | + resolveBodyOnly: false, |
| 99 | + throwHttpErrors: false, |
| 100 | + followRedirect: false |
| 101 | + } |
| 102 | + ) |
| 103 | + |
| 104 | + t.is(response.statusCode, 302) |
| 105 | + t.truthy(response.headers.location) |
| 106 | + t.true(response.headers.location.includes('X-Amz-Algorithm')) |
| 107 | +}) |
| 108 | + |
| 109 | +test('GET /collections/:collectionId/items/:itemId/assets/:assetKey - 404 for non-existent asset', async (t) => { |
| 110 | + const { collectionId, itemId } = t.context |
| 111 | + |
| 112 | + const response = await t.context.api.client.get( |
| 113 | + `collections/${collectionId}/items/${itemId}/assets/DOES_NOT_EXIST`, |
| 114 | + { |
| 115 | + resolveBodyOnly: false, |
| 116 | + throwHttpErrors: false |
| 117 | + } |
| 118 | + ) |
| 119 | + |
| 120 | + t.is(response.statusCode, 404) |
| 121 | +}) |
| 122 | + |
| 123 | +test('GET /collections/:collectionId/items/:itemId/assets/:assetKey - 404 for non-existent item', async (t) => { |
| 124 | + const { collectionId } = t.context |
| 125 | + |
| 126 | + const response = await t.context.api.client.get( |
| 127 | + `collections/${collectionId}/items/DOES_NOT_EXIST/assets/B1`, |
| 128 | + { |
| 129 | + resolveBodyOnly: false, |
| 130 | + throwHttpErrors: false |
| 131 | + } |
| 132 | + ) |
| 133 | + |
| 134 | + t.is(response.statusCode, 404) |
| 135 | +}) |
| 136 | + |
| 137 | +test('GET /collections/:collectionId/items/:itemId/assets/:assetKey - 404 for non-existent collection', async (t) => { |
| 138 | + const response = await t.context.api.client.get( |
| 139 | + 'collections/DOES_NOT_EXIST/items/DOES_NOT_EXIST/assets/B1', |
| 140 | + { |
| 141 | + resolveBodyOnly: false, |
| 142 | + throwHttpErrors: false |
| 143 | + } |
| 144 | + ) |
| 145 | + |
| 146 | + t.is(response.statusCode, 404) |
| 147 | +}) |
0 commit comments