Skip to content

Commit

Permalink
EDSC-3925: Snyk Vulnerabilities, Earthdata Search
Browse files Browse the repository at this point in the history
* EDSC-3925: Updating serverless, removing google-maps-dependency, updating `browserify-sign` on the `crypto-browserify` dep

* EDSC-3925: Remove the rest of the spatial-autocomplete code

* EDSC-3925: Remove unused env variables
  • Loading branch information
eudoroolivares2016 authored Nov 29, 2023
1 parent 916fb02 commit ed874ef
Show file tree
Hide file tree
Showing 7 changed files with 4,518 additions and 1,622 deletions.
5,573 changes: 4,516 additions & 1,057 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
"@edsc/geo-utils": "^1.0.4",
"@edsc/smart-handoffs": "^1.0.5",
"@edsc/timeline": "^1.1.7",
"@googlemaps/google-maps-services-js": "^3.3.41",
"@react-leaflet/core": "^2.1.0",
"@redux-devtools/extension": "^3.2.2",
"@rjsf/core": "^5.0.0-beta.13",
Expand Down Expand Up @@ -210,7 +209,7 @@
"sanitize-html": "^2.7.0",
"sass-loader": "^13.2.0",
"scatter-swap": "^0.1.0",
"serverless": "^3.33.0",
"serverless": "^3.37.0",
"serverless-finch": "^4.0.0",
"serverless-offline": "^12.0.4",
"serverless-plugin-ifelse": "git+https://git@github.com/macrouch/serverless-plugin-ifelse.git",
Expand Down
5 changes: 0 additions & 5 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ provider:

collectionCapabilitiesLambda: ${self:custom.siteName}-generateCollectionCapabilityTags

geocodingService: ${self:custom.variables.geocodingService}
geocodingIncludePolygons: ${self:custom.variables.geocodingIncludePolygons}

NODE_OPTIONS: '--enable-source-maps'

vpc:
Expand Down Expand Up @@ -126,8 +123,6 @@ custom:
obfuscationSpin: ${env:OBFUSCATION_SPIN, ''}
obfuscationSpinShapefiles: ${env:OBFUSCATION_SPIN_SHAPEFILES, ''}
orderDelaySeconds: ${env:ORDER_DELAY_SECONDS, '1'}
geocodingService: ${env:GEOCODING_SERVICE, 'nominatim'}
geocodingIncludePolygons: ${env:GEOCODING_INCLUDE_POLYGONS, 'false'}

cloudfrontToCloudwatchBucketPrefixApi:
Fn::Join:
Expand Down
322 changes: 0 additions & 322 deletions serverless/src/autocomplete/__tests__/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ import nock from 'nock'
import * as deployedEnvironment from '../../../../sharedUtils/deployedEnvironment'
import * as doSearchRequest from '../../util/cmr/doSearchRequest'
import * as getEchoToken from '../../util/urs/getEchoToken'
import * as getEnvironmentConfig from '../../../../sharedUtils/config'
import * as getGoogleMapsApiKey from '../../util/google/getGoogleMapsApiKey'
import * as getJwtToken from '../../util/getJwtToken'

import autocomplete from '../handler'

const OLD_ENV = process.env

beforeEach(() => {
jest.clearAllMocks()

jest.spyOn(deployedEnvironment, 'deployedEnvironment').mockImplementation(() => 'prod')
jest.spyOn(getJwtToken, 'getJwtToken').mockImplementation(() => 'mockJwt')
jest.spyOn(getEchoToken, 'getEchoToken').mockImplementation(() => '1234-abcd-5678-efgh')
jest.spyOn(getGoogleMapsApiKey, 'getGoogleMapsApiKey').mockImplementation(() => 'testApiKey')
})

describe('autocomplete', () => {
Expand Down Expand Up @@ -99,321 +94,4 @@ describe('autocomplete', () => {

expect(errorMessage).toEqual('Error: Code Exception Occurred')
})

describe('spatial', () => {
beforeEach(() => {
// Manage resetting ENV variables
jest.resetModules()
process.env = { ...OLD_ENV }
delete process.env.NODE_ENV
})

afterEach(() => {
// Restore any ENV variables overwritten in tests
process.env = OLD_ENV
})

describe('google', () => {
beforeEach(() => {
process.env.geocodingService = ''
})

test('correctly returns when no bounds are returned', async () => {
const event = {
body: JSON.stringify({
params: {
type: 'spatial',
q: 'Alexandria'
},
requestId: 'asdf-1234-qwer-5678'
})
}

const response = await autocomplete(event, {})

const { body } = response
const parsedBody = JSON.parse(body)
const { errors } = parsedBody
const [errorMessage] = errors

expect(errorMessage).toEqual('Error: Geocoder () not supported')
})
})

describe('google', () => {
beforeEach(() => {
process.env.geocodingService = 'google'
})

test('correctly returns when no bounds are returned', async () => {
nock(/maps.googleapis.com/)
.get(/geocode/)
.reply(200, {
results: [
{
formatted_address: 'Alexandria, VA, USA',
geometry: {
location: {
lat: 38.8048355,
lng: -77.0469214
}
},
place_id: 'ChIJ8aukkz5NtokRLAHB24Ym9dc'
}
]
})

const event = {
body: JSON.stringify({
params: {
type: 'spatial',
q: 'Alexandria'
},
requestId: 'asdf-1234-qwer-5678'
})
}

const response = await autocomplete(event, {})

const { body } = response
const parsedBody = JSON.parse(body)

expect(parsedBody).toEqual([{
name: 'Alexandria, VA, USA',
point: [
38.8048355,
-77.0469214
]
}])
})

test('correctly returns a full result', async () => {
nock(/maps.googleapis.com/)
.get(/geocode/)
.reply(200, {
results: [
{
formatted_address: 'Alexandria, VA, USA',
geometry: {
bounds: {
northeast: {
lat: 38.845011,
lng: -77.0372879
},
southwest: {
lat: 38.785216,
lng: -77.144359
}
},
location: {
lat: 38.8048355,
lng: -77.0469214
}
},
place_id: 'ChIJ8aukkz5NtokRLAHB24Ym9dc'
}
]
})

const event = {
body: JSON.stringify({
params: {
type: 'spatial',
q: 'Alexandria'
},
requestId: 'asdf-1234-qwer-5678'
})
}

const response = await autocomplete(event, {})

const { body } = response
const parsedBody = JSON.parse(body)

expect(parsedBody).toEqual([{
name: 'Alexandria, VA, USA',
point: [
38.8048355,
-77.0469214
],
bounding_box: [
-77.144359,
38.785216,
-77.0372879,
38.845011
]
}])
})
})

describe('nominatim', () => {
beforeEach(() => {
process.env.geocodingService = 'nominatim'

jest.spyOn(getEnvironmentConfig, 'getEnvironmentConfig').mockImplementation(() => ({ edscHost: 'http://localhost' }))
})

test('correctly returns a full result', async () => {
process.env.geocodingIncludePolygons = 'false'

nock(/openstreetmap/)
.get(/search/)
.reply(200, [
{
display_name: 'Alexandria, VA, USA',
lat: 38.8048355,
lon: -77.0469214,
place_id: 235545611,
boundingbox: [
-77.144359,
38.785216,
-77.0372879,
38.845011
]
}
])

const event = {
body: JSON.stringify({
params: {
type: 'spatial',
q: 'Alexandria'
},
requestId: 'asdf-1234-qwer-5678'
})
}

const response = await autocomplete(event, {})

const { body } = response
const parsedBody = JSON.parse(body)

expect(parsedBody).toEqual([{
name: 'Alexandria, VA, USA',
point: [
38.8048355,
-77.0469214
],
bounding_box: [
-77.0372879,
-77.144359,
38.845011,
38.785216
]
}])
})

test('correctly returns a full result with polygons enabled', async () => {
process.env.geocodingIncludePolygons = 'true'

nock(/openstreetmap/)
.get(/search/)
.reply(200, [
{
display_name: 'Alexandria, VA, USA',
lat: 38.8048355,
lon: -77.0469214,
place_id: 235545611,
boundingbox: [
-77.144359,
38.785216,
-77.0372879,
38.845011
],
geojson: {
type: 'Polygon',
coordinates: [
[
[
-77.144359,
38.810357
],
[
-77.143135,
38.805321
],
[
-77.139862,
38.800202
],
[
-77.1377474,
38.8007821
],
[
-77.137562,
38.798169
],
[
-77.11301,
38.802987
]
]
]
}
}
])

const event = {
body: JSON.stringify({
params: {
type: 'spatial',
q: 'Alexandria'
},
requestId: 'asdf-1234-qwer-5678'
})
}

const response = await autocomplete(event, {})

const { body } = response
const parsedBody = JSON.parse(body)

expect(parsedBody).toEqual([{
name: 'Alexandria, VA, USA',
point: [
38.8048355,
-77.0469214
],
bounding_box: [
-77.0372879,
-77.144359,
38.845011,
38.785216
],
polygon: {
type: 'Polygon',
coordinates: [
[
[
-77.144359,
38.810357
],
[
-77.143135,
38.805321
],
[
-77.139862,
38.800202
],
[
-77.1377474,
38.8007821
],
[
-77.137562,
38.798169
],
[
-77.11301,
38.802987
]
]
]
}
}])
})
})
})
})
Loading

0 comments on commit ed874ef

Please sign in to comment.