Skip to content

Commit

Permalink
chore: remove non encryption boundary fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
tshuli committed Jan 9, 2024
1 parent 74b124b commit c2b1a33
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 771 deletions.
11 changes: 1 addition & 10 deletions __tests__/e2e/encrypt-submission.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import mongoose from 'mongoose'
import { featureFlags } from 'shared/constants/feature-flags'
import {
BasicField,
FormAuthType,
FormResponseMode,
MyInfoAttribute,
} from 'shared/types'

import { IFeatureFlagModel, IFormModel } from 'src/types'
import { IFormModel } from 'src/types'

import {
ALL_FIELDS as _ALL_FIELDS,
Expand Down Expand Up @@ -43,20 +42,12 @@ const runEncryptSubmissionTest = createSubmissionTestRunnerForResponseMode(

let db: mongoose.Connection
let Form: IFormModel
let FeatureFlags: IFeatureFlagModel

test.describe('Storage form submission', () => {
test.beforeAll(async () => {
// Create models
db = await makeMongooseFixtures()
Form = makeModel(db, 'form.server.model', 'Form')
// TODO(FRM-1232): Remove this once old storage submission endpoint (/submissions/encrypt) is removed
// Add feature flag model and set encryption boundary shift to true
FeatureFlags = makeModel(db, 'feature_flag.server.model', 'FeatureFlags')
await FeatureFlags.create({
name: featureFlags.encryptionBoundaryShift,
enabled: true,
})
})
test.afterAll(async () => {
// Clean up db
Expand Down
157 changes: 47 additions & 110 deletions frontend/src/features/public-form/PublicFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SubmitHandler } from 'react-hook-form'
import { useNavigate } from 'react-router-dom'
import { useDisclosure } from '@chakra-ui/react'
import { datadogLogs } from '@datadog/browser-logs'
import { useFeatureIsOn, useGrowthBook } from '@growthbook/growthbook-react'
import { useGrowthBook } from '@growthbook/growthbook-react'
import { differenceInMilliseconds, isPast } from 'date-fns'
import get from 'lodash/get'
import simplur from 'simplur'
Expand Down Expand Up @@ -290,16 +290,11 @@ export const PublicFormProvider = ({
}
}, [data?.form.form_fields, toast, vfnToastIdRef])

const enableVirusScanner = useFeatureIsOn(
featureFlags.encryptionBoundaryShiftVirusScanner,
)

const {
submitEmailModeFormMutation,
submitEmailModeFormFetchMutation,
submitStorageModeClearFormMutation,
submitStorageModeClearFormFetchMutation,
submitStorageModeClearFormWithVirusScanningMutation,
submitStorageModeFormMutation,
submitStorageModeFormFetchMutation,
submitMultirespondentFormMutation,
updateMultirespondentSubmissionMutation,
} = usePublicFormMutations(formId, previousSubmissionId)
Expand Down Expand Up @@ -514,7 +509,7 @@ export const PublicFormProvider = ({
},
})

return submitStorageModeClearFormFetchMutation
return submitStorageModeFormFetchMutation
.mutateAsync(
{
...formData,
Expand Down Expand Up @@ -570,111 +565,55 @@ export const PublicFormProvider = ({
},
})

// TODO (FRM-1413): Move to main return statement once virus scanner has been fully rolled out
if (enableVirusScanner) {
return submitStorageModeClearFormWithVirusScanningMutation
.mutateAsync(
{
...formData,
...formPaymentData,
},
{
onSuccess: ({
submissionId,
return submitStorageModeFormMutation
.mutateAsync(
{
...formData,
...formPaymentData,
},
{
onSuccess: ({
submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
})
},
},
)
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
{
meta: {
...logMeta,
responseMode: 'storage',
method: 'axios',
error,
},
},
)

if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch()
} else {
showErrorToast(error, form)
}
})
}

return (
submitStorageModeClearFormMutation
.mutateAsync(
{
...formData,
...formPaymentData,
})
},
},
)
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(
`handleSubmitForm: submit with virus scan`,
{
onSuccess: ({
submissionId,
timestamp,
// payment forms will have non-empty paymentData field
paymentData,
}) => {
trackSubmitForm(form)

if (paymentData) {
navigate(getPaymentPageUrl(formId, paymentData.paymentId))
storePaymentMemory(paymentData.paymentId)
return
}
setSubmissionData({
id: submissionId,
timestamp,
})
},
},
)
// Using catch since we are using mutateAsync and react-hook-form will continue bubbling this up.
.catch(async (error) => {
// TODO(#5826): Remove when we have resolved the Network Error
datadogLogs.logger.warn(`handleSubmitForm: ${error.message}`, {
meta: {
...logMeta,
responseMode: 'storage',
method: 'axios',
error: {
message: error.message,
stack: error.stack,
},
error,
},
})
},
)

if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
if (/Network Error/i.test(error.message)) {
axiosDebugFlow()
// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch()
} else {
showErrorToast(error, form)
}
})
)
// defaults to the safest option of storage submission without virus scanning
return submitStorageFormWithFetch()
} else {
showErrorToast(error, form)
}
})
}
case FormResponseMode.Multirespondent:
return (
Expand Down Expand Up @@ -704,17 +643,15 @@ export const PublicFormProvider = ({
showErrorToast,
getCaptchaResponse,
previousSubmissionId,
submitMultirespondentFormMutation,
updateMultirespondentSubmissionMutation,
submitMultirespondentFormMutation,
submitEmailModeFormFetchMutation,
submitEmailModeFormMutation,
enableVirusScanner,
submitStorageModeClearFormMutation,
submitStorageModeClearFormFetchMutation,
submitStorageModeFormMutation,
submitStorageModeFormFetchMutation,
navigate,
formId,
storePaymentMemory,
submitStorageModeClearFormWithVirusScanningMutation,
],
)

Expand Down
68 changes: 16 additions & 52 deletions frontend/src/features/public-form/PublicFormService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { PresignedPost } from 'aws-sdk/clients/s3'
import axios from 'axios'

import {
ENCRYPTION_BOUNDARY_SHIFT_SUBMISSION_VERSION,
MULTIRESPONDENT_FORM_SUBMISSION_VERSION,
VIRUS_SCANNER_SUBMISSION_VERSION,
} from '~shared/constants'
Expand Down Expand Up @@ -181,7 +180,9 @@ export const submitEmailModeForm = async ({
).then(({ data }) => data)
}

export const submitStorageModeClearForm = async ({
// TODO (#5826): Fallback mutation using Fetch. Remove once network error is resolved
// Submit storage mode form with virus scanning (storage v2.1+)
export const submitStorageModeFormWithFetch = async ({
formFields,
formLogics,
formInputs,
Expand All @@ -192,63 +193,26 @@ export const submitStorageModeClearForm = async ({
responseMetadata,
paymentProducts,
payments,
}: SubmitStorageFormClearArgs) => {
fieldIdToQuarantineKeyMap,
}: SubmitStorageFormWithVirusScanningArgs) => {
const filteredInputs = filterHiddenInputs({
formFields,
formInputs,
formLogics,
})

const formData = createClearSubmissionFormData({
formFields,
formInputs: filteredInputs,
responseMetadata,
paymentReceiptEmail,
paymentProducts,
payments,
version: ENCRYPTION_BOUNDARY_SHIFT_SUBMISSION_VERSION,
})

return ApiService.post<SubmissionResponseDto>(
`${PUBLIC_FORMS_ENDPOINT}/${formId}/submissions/storage`,
formData,
const formData = createClearSubmissionWithVirusScanningFormData(
{
params: {
captchaResponse: String(captchaResponse),
captchaType: captchaType,
},
formFields,
formInputs: filteredInputs,
responseMetadata,
paymentReceiptEmail,
paymentProducts,
payments,
version: VIRUS_SCANNER_SUBMISSION_VERSION,
},
).then(({ data }) => data)
}

// TODO (#5826): Fallback mutation using Fetch. Remove once network error is resolved
export const submitStorageModeClearFormWithFetch = async ({
formFields,
formLogics,
formInputs,
formId,
captchaResponse = null,
captchaType = '',
paymentReceiptEmail,
responseMetadata,
paymentProducts,
payments,
}: SubmitStorageFormClearArgs) => {
const filteredInputs = filterHiddenInputs({
formFields,
formInputs,
formLogics,
})

const formData = createClearSubmissionFormData({
formFields,
formInputs: filteredInputs,
responseMetadata,
paymentReceiptEmail,
paymentProducts,
payments,
version: ENCRYPTION_BOUNDARY_SHIFT_SUBMISSION_VERSION,
})
fieldIdToQuarantineKeyMap,
)

// Add captcha response to query string
const queryString = new URLSearchParams({
Expand All @@ -271,7 +235,7 @@ export const submitStorageModeClearFormWithFetch = async ({
}

// Submit storage mode form with virus scanning (storage v2.1+)
export const submitStorageModeClearFormWithVirusScanning = async ({
export const submitStorageModeForm = async ({
formFields,
formLogics,
formInputs,
Expand Down
Loading

0 comments on commit c2b1a33

Please sign in to comment.