@oneuptime/common 14.0.7 → 14.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Models/DatabaseModels/Incident.ts +267 -1
- package/Models/DatabaseModels/IncidentCustomField.ts +202 -0
- package/Models/DatabaseModels/IncidentEpisode.ts +30 -0
- package/Models/DatabaseModels/IncidentTemplate.ts +126 -1
- package/Models/DatabaseModels/StatusPage.ts +55 -0
- package/Models/DatabaseModels/StatusPageSubscriber.ts +128 -0
- package/Server/API/IncidentAPI.ts +162 -0
- package/Server/API/StatusPageAPI.ts +487 -171
- package/Server/API/StatusPageSubscriberAPI.ts +63 -15
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795300000000-SkipHiddenIncidentCreatedNotifications.ts +49 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795400000000-AddIncidentStatusPageScope.ts +108 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795500000000-AddIncidentTemplateStatusPageScopeFlag.ts +33 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795600000000-AddStatusPageSubscriberUnsubscribeToken.ts +51 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795700000000-AddStatusPageSubscriberIsAddedByTeam.ts +33 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795800000000-AddIncidentCustomFieldCreateAndNotificationSettings.ts +168 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1795900000000-AddSubscriberNotificationClaimedAt.ts +44 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +14 -0
- package/Server/Infrastructure/Semaphore.ts +10 -0
- package/Server/Middleware/IdentityRateLimit.ts +108 -3
- package/Server/Middleware/SubscriberNotificationPreviewRateLimit.ts +237 -0
- package/Server/Middleware/SubscriberNotificationTestSendRateLimit.ts +304 -0
- package/Server/Services/DatabaseService.ts +93 -10
- package/Server/Services/IncidentCustomFieldService.ts +276 -1
- package/Server/Services/IncidentEpisodePublicNoteService.ts +28 -0
- package/Server/Services/IncidentEpisodeService.ts +15 -0
- package/Server/Services/IncidentEpisodeStateTimelineService.ts +27 -1
- package/Server/Services/IncidentPublicNoteService.ts +30 -1
- package/Server/Services/IncidentService.ts +1535 -65
- package/Server/Services/IncidentStateTimelineService.ts +13 -0
- package/Server/Services/IncidentTemplateService.ts +109 -0
- package/Server/Services/ScheduledMaintenancePublicNoteService.ts +30 -1
- package/Server/Services/ScheduledMaintenanceService.ts +68 -18
- package/Server/Services/SmsService.ts +10 -0
- package/Server/Services/StatusPageService.ts +65 -8
- package/Server/Services/StatusPageSubscriberNotificationTemplateService.ts +299 -37
- package/Server/Services/StatusPageSubscriberNotificationTemplateStatusPageService.ts +129 -0
- package/Server/Services/StatusPageSubscriberService.ts +1161 -64
- package/Server/Types/Markdown.ts +153 -6
- package/Server/Types/Workflow/Components/Email.ts +61 -2
- package/Server/Utils/CustomField/CustomFieldRename.ts +378 -0
- package/Server/Utils/DataSource/EgressGuard.ts +66 -21
- package/Server/Utils/Mail/PinnedSmtpSocket.ts +130 -0
- package/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.ts +10 -0
- package/Server/Utils/SSRFProtection.ts +76 -16
- package/Server/Utils/StatusPage/IncidentStatusPageScope.ts +948 -0
- package/Server/Utils/StatusPage/IncidentSubscriberAudienceBuilder.ts +656 -0
- package/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.ts +805 -0
- package/Server/Utils/StatusPage/StatusPageExclusion.ts +18 -0
- package/Server/Utils/StatusPage/StatusPageReadAccess.ts +125 -0
- package/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.ts +151 -0
- package/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.ts +70 -0
- package/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.ts +421 -0
- package/Server/Utils/StatusPage/SubscriberNotificationClaim.ts +107 -0
- package/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.ts +1049 -0
- package/Server/Utils/StatusPage/SubscriberNotificationFanOut.ts +180 -0
- package/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.ts +839 -0
- package/Server/Utils/StatusPage/SubscriberNotificationResendAccess.ts +393 -0
- package/Server/Utils/StatusPage/SubscriberNotificationRunLimit.ts +246 -0
- package/Server/Utils/StatusPage/SubscriberNotificationTiming.ts +133 -0
- package/Server/Utils/StatusPage/SubscriberTemplateIncidentRecordAccess.ts +215 -0
- package/Server/Utils/StatusPageResource.ts +51 -20
- package/Server/Utils/VM/VMAPI.ts +1 -0
- package/Server/Utils/VM/VMRunner.ts +10 -0
- package/Server/Utils/Workflow/OAuth2TokenClient.ts +10 -0
- package/Server/Views/Partials/SensitiveUrlToken.ejs +8 -5
- package/Tests/App/Accounts/RegisterVerifyEmail.test.tsx +748 -0
- package/Tests/App/Accounts/ResendVerificationEmail.test.tsx +1222 -0
- package/Tests/App/Accounts/VerificationEmailResendUtils.test.ts +797 -0
- package/Tests/App/Accounts/VerifyEmailPending.test.tsx +538 -0
- package/Tests/App/Accounts/VerifyEmailResend.test.tsx +779 -0
- package/Tests/App/Dashboard/CustomFieldsSettingsIncidentOptions.test.tsx +357 -0
- package/Tests/App/Dashboard/EventNotes.test.tsx +776 -0
- package/Tests/App/Dashboard/EventNotesPages.test.tsx +119 -0
- package/Tests/App/Dashboard/EventNotesUtil.test.ts +116 -17
- package/Tests/App/Dashboard/EventOverviewPages.test.tsx +242 -5
- package/Tests/App/Dashboard/IncidentChangeStateNotifyDefault.test.tsx +91 -1
- package/Tests/App/Dashboard/IncidentCreateDetailsStep.test.tsx +643 -0
- package/Tests/App/Dashboard/IncidentCreateFromAlerts.test.tsx +8 -1
- package/Tests/App/Dashboard/IncidentCreateStatusPageScope.test.tsx +601 -0
- package/Tests/App/Dashboard/IncidentCustomFieldTemplateVariables.test.tsx +386 -0
- package/Tests/App/Dashboard/IncidentNoteTemplatePlaceholders.test.tsx +124 -0
- package/Tests/App/Dashboard/IncidentNoteTemplateVariablesLoader.test.ts +305 -0
- package/Tests/App/Dashboard/IncidentOverviewNotifyDefault.test.tsx +112 -0
- package/Tests/App/Dashboard/IncidentSettingsRenotifyOnPublish.test.tsx +674 -0
- package/Tests/App/Dashboard/IncidentSettingsStatusPageScope.test.tsx +1051 -0
- package/Tests/App/Dashboard/IncidentTemplateCustomFields.test.tsx +384 -0
- package/Tests/App/Dashboard/IncidentTemplateStatusPageScopeCard.test.tsx +215 -0
- package/Tests/App/Dashboard/PublicNotePagesNotifyDefault.test.tsx +113 -1
- package/Tests/App/Dashboard/SubscriberAudienceSummary.test.tsx +512 -0
- package/Tests/App/Dashboard/SubscriberNotificationPreviewModal.test.tsx +837 -0
- package/Tests/App/Dashboard/SubscriberNotificationStatusLabel.test.tsx +88 -0
- package/Tests/App/Dashboard/SubscriberNotificationStatusResend.test.tsx +473 -0
- package/Tests/App/Dashboard/SubscriberTemplateLivePreview.test.tsx +196 -0
- package/Tests/App/Dashboard/TeamAddedSubscribersUnsubscribedNotice.test.tsx +248 -0
- package/Tests/App/SensitiveUrlTokenBootstrap.test.ts +64 -3
- package/Tests/App/StatusPage/StatusPageUnsubscribePage.test.tsx +412 -0
- package/Tests/Models/IncidentCustomFieldApiSchemaContract.test.ts +217 -0
- package/Tests/Models/IncidentCustomFieldCreateSettingsColumns.test.ts +252 -0
- package/Tests/Models/StatusPageSubscriberUnsubscribeColumns.test.ts +218 -0
- package/Tests/Server/API/ExpiredSessionRouteGuards.test.ts +7 -0
- package/Tests/Server/API/IncidentSubscriberAudienceAPI.test.ts +1408 -0
- package/Tests/Server/API/StatusPageIncidentScope.test.ts +1868 -0
- package/Tests/Server/API/StatusPageIncidentScopePostgres.test.ts +790 -0
- package/Tests/Server/API/StatusPageManageSubscriptionRecipient.test.ts +10 -1
- package/Tests/Server/API/StatusPageManageSubscriptionTemplateVariables.test.ts +206 -18
- package/Tests/Server/API/StatusPagePostmortemVisibility.test.ts +14 -2
- package/Tests/Server/API/StatusPageSubscriberCreateResponse.test.ts +217 -0
- package/Tests/Server/API/StatusPageSubscriberOwnership.test.ts +103 -2
- package/Tests/Server/API/StatusPageUnsubscribeAPI.test.ts +396 -0
- package/Tests/Server/Infrastructure/Postgres/AddIncidentStatusPageScopeMigration.test.ts +395 -0
- package/Tests/Server/Infrastructure/Postgres/AddIncidentTemplateStatusPageScopeFlagMigration.test.ts +150 -0
- package/Tests/Server/Infrastructure/Postgres/AddSubscriberNotificationClaimedAtMigration.test.ts +156 -0
- package/Tests/Server/Infrastructure/Postgres/SkipHiddenIncidentCreatedNotificationsMigration.test.ts +410 -0
- package/Tests/Server/Middleware/IdentityRateLimit.test.ts +551 -1
- package/Tests/Server/Middleware/SubscriberNotificationPreviewRateLimit.test.ts +238 -0
- package/Tests/Server/Middleware/SubscriberNotificationTestSendRateLimit.test.ts +245 -0
- package/Tests/Server/Services/AddStatusPageSubscriberUnsubscribeTokenMigration.test.ts +152 -0
- package/Tests/Server/Services/CrossProjectRelationWriteGuard.test.ts +221 -36
- package/Tests/Server/Services/DatabaseServiceCompareAndSetColumns.test.ts +191 -0
- package/Tests/Server/Services/IncidentCreatedRenotifyOnPublish.test.ts +681 -0
- package/Tests/Server/Services/IncidentCreatedResend.test.ts +775 -0
- package/Tests/Server/Services/IncidentCustomFieldRenamePostgres.test.ts +713 -0
- package/Tests/Server/Services/IncidentCustomFieldService.test.ts +751 -0
- package/Tests/Server/Services/IncidentCustomFieldValueValidation.test.ts +556 -0
- package/Tests/Server/Services/IncidentStatusPageScope.test.ts +2971 -0
- package/Tests/Server/Services/IncidentStatusPageScopeFeed.test.ts +131 -0
- package/Tests/Server/Services/IncidentStatusPageScopePostgres.test.ts +625 -0
- package/Tests/Server/Services/IncidentTemplateCustomFieldsCopy.test.ts +311 -0
- package/Tests/Server/Services/IncidentTemplateStatusPageScope.test.ts +363 -0
- package/Tests/Server/Services/PublicNoteEditFeedEventType.test.ts +213 -0
- package/Tests/Server/Services/PublicNoteResendAccess.test.ts +994 -0
- package/Tests/Server/Services/ScheduledMaintenanceSubscriberTemplateFormats.test.ts +289 -9
- package/Tests/Server/Services/SmsServiceFailIfNotSent.test.ts +67 -0
- package/Tests/Server/Services/StatusPageReportIncidentCounts.test.ts +610 -0
- package/Tests/Server/Services/StatusPageSubscriberAudienceCounts.test.ts +201 -0
- package/Tests/Server/Services/StatusPageSubscriberAudienceCountsPostgres.test.ts +271 -0
- package/Tests/Server/Services/StatusPageSubscriberConfirmationTemplateEscaping.test.ts +200 -0
- package/Tests/Server/Services/StatusPageSubscriberNotificationLogRedaction.test.ts +54 -0
- package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateCompile.test.ts +37 -0
- package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateIncidentRecordAccess.test.ts +772 -0
- package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateLookup.test.ts +506 -0
- package/Tests/Server/Services/StatusPageSubscriberNotificationTemplateLookupPostgres.test.ts +261 -0
- package/Tests/Server/Services/StatusPageSubscriberReport.test.ts +21 -5
- package/Tests/Server/Services/StatusPageSubscriberUnsubscribe.test.ts +1618 -0
- package/Tests/Server/Services/StatusPageSubscriberUnsubscribeLinkSenders.test.ts +373 -0
- package/Tests/Server/Services/StatusPageSubscriberUnsubscribePostgres.test.ts +388 -0
- package/Tests/Server/Services/SubscriberNotificationInFlightRequeue.test.ts +500 -0
- package/Tests/Server/Types/MarkdownEmailLinks.test.ts +320 -0
- package/Tests/Server/Types/Workflow/Components/Email.test.ts +491 -1
- package/Tests/Server/Types/Workflow/Components/EmailSmtpPinning.test.ts +398 -0
- package/Tests/Server/Utils/CustomField/CustomFieldRename.test.ts +586 -0
- package/Tests/Server/Utils/DataSource/EgressGuard.test.ts +246 -10
- package/Tests/Server/Utils/DataSource/EgressGuardDeploymentConfig.test.ts +226 -0
- package/Tests/Server/Utils/DataSource/EgressGuardPinning.test.ts +131 -0
- package/Tests/Server/Utils/DataSource/HttpFetch.test.ts +4 -0
- package/Tests/Server/Utils/EgressPolicyEnvironment.ts +45 -0
- package/Tests/Server/Utils/Mail/PinnedSmtpSocket.test.ts +409 -0
- package/Tests/Server/Utils/Monitor/MonitorCriteriaObservationBuilderUnits.test.ts +23 -0
- package/Tests/Server/Utils/SSRFProtection.test.ts +4 -0
- package/Tests/Server/Utils/SSRFProtectionCloudServiceAddresses.test.ts +4 -0
- package/Tests/Server/Utils/SSRFProtectionPrivateNetwork.test.ts +4 -0
- package/Tests/Server/Utils/SSRFProtectionResolutionDetail.test.ts +314 -0
- package/Tests/Server/Utils/StatusPage/IncidentStatusPageScope.test.ts +1699 -0
- package/Tests/Server/Utils/StatusPage/IncidentStatusPageScopeQueriesPostgres.test.ts +508 -0
- package/Tests/Server/Utils/StatusPage/IncidentSubscriberAudienceCallerPermission.test.ts +246 -0
- package/Tests/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.test.ts +1348 -0
- package/Tests/Server/Utils/StatusPage/StatusPageReadAccess.test.ts +221 -0
- package/Tests/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.test.ts +132 -0
- package/Tests/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.test.ts +155 -0
- package/Tests/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.test.ts +708 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationClaim.test.ts +255 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationClaimPostgres.test.ts +528 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.test.ts +1238 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationFanOut.test.ts +472 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.test.ts +1168 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationRunLimit.test.ts +275 -0
- package/Tests/Server/Utils/StatusPage/SubscriberNotificationTiming.test.ts +131 -0
- package/Tests/Server/Utils/StatusPageResource.test.ts +98 -0
- package/Tests/Server/Utils/VM/VMRunnerPrivateNetworkWiring.test.ts +17 -0
- package/Tests/Server/Utils/VM/VMRunnerSsrf.test.ts +75 -0
- package/Tests/Types/CustomField/CustomFieldSavedViews.test.ts +247 -0
- package/Tests/Types/CustomField/CustomFieldTemplateValues.test.ts +186 -0
- package/Tests/Types/CustomField/CustomFieldTypeCorrespondence.test.ts +48 -0
- package/Tests/Types/CustomField/CustomFieldValueFormat.test.ts +215 -0
- package/Tests/Types/CustomField/CustomFieldValueValidator.test.ts +343 -0
- package/Tests/Types/CustomField/CustomFieldVariableKey.test.ts +364 -0
- package/Tests/Types/SafeHtml.test.ts +102 -0
- package/Tests/Types/StatusPage/IncidentCreatedRenotify.test.ts +419 -0
- package/Tests/Types/StatusPage/IncidentCreatedResend.test.ts +118 -0
- package/Tests/Types/StatusPage/IncidentScopeAddedPagesNotification.test.ts +558 -0
- package/Tests/Types/StatusPage/IncidentSubscriberAudience.test.ts +284 -0
- package/Tests/Types/StatusPage/StatusPageSubscriberUnsubscribe.test.ts +341 -0
- package/Tests/Types/StatusPage/SubscriberNotificationPreview.test.ts +196 -0
- package/Tests/Types/StatusPage/SubscriberNotificationResend.test.ts +201 -0
- package/Tests/Types/StatusPage/SubscriberNotificationTemplateCompiler.test.ts +277 -0
- package/Tests/Types/StatusPage/SubscriberNotificationTemplatePreview.test.ts +179 -0
- package/Tests/Types/StatusPage/SubscriberNotificationTemplateVariables.test.ts +324 -0
- package/Tests/Types/StatusPage/SubscriberUpdateNotification.test.ts +60 -13
- package/Tests/UI/Components/CustomFields/CustomFieldFormFields.test.ts +432 -0
- package/Tests/UI/Components/CustomFields/CustomFieldModelFormFields.test.tsx +685 -0
- package/Tests/UI/Components/CustomFields/CustomFieldsDetailOrder.test.tsx +469 -0
- package/Tests/UI/Components/Forms/ModelFormCustomFieldInputs.test.tsx +325 -0
- package/Tests/UI/Components/Forms/ModelFormDropdownOptionsRefused.test.tsx +358 -0
- package/Tests/UI/Components/ModelTable/CustomFieldColumns.test.tsx +22 -0
- package/Tests/UI/Monitor/NetworkPathView.test.tsx +289 -0
- package/Tests/Utils/Incident/IncidentNoteTemplateVariables.test.ts +623 -0
- package/Tests/Utils/Markdown/MarkdownEscape.test.ts +89 -0
- package/Tests/Utils/ProbeNetworkFailureUtil.test.ts +992 -0
- package/Tests/Utils/RequestFailedDetails.test.ts +575 -0
- package/Types/CustomField/CustomFieldOrder.ts +55 -0
- package/Types/CustomField/CustomFieldSavedViews.ts +225 -0
- package/Types/CustomField/CustomFieldTemplateMerge.ts +71 -0
- package/Types/CustomField/CustomFieldType.ts +14 -0
- package/Types/CustomField/CustomFieldValueFormat.ts +161 -0
- package/Types/CustomField/CustomFieldValueValidator.ts +488 -0
- package/Types/CustomField/CustomFieldVariableKey.ts +211 -0
- package/Types/SafeHtml.ts +93 -0
- package/Types/StatusPage/IncidentCreatedRenotify.ts +224 -0
- package/Types/StatusPage/IncidentCreatedResend.ts +108 -0
- package/Types/StatusPage/IncidentScopeAddedPagesNotification.ts +343 -0
- package/Types/StatusPage/IncidentSubscriberAudience.ts +332 -0
- package/Types/StatusPage/StatusPageSubscriberUnsubscribe.ts +405 -0
- package/Types/StatusPage/SubscriberNotificationInterruption.ts +32 -0
- package/Types/StatusPage/SubscriberNotificationPreview.ts +322 -0
- package/Types/StatusPage/SubscriberNotificationResend.ts +132 -0
- package/Types/StatusPage/SubscriberNotificationTemplateCompiler.ts +180 -0
- package/Types/StatusPage/SubscriberNotificationTemplatePreview.ts +301 -0
- package/Types/StatusPage/SubscriberNotificationTemplateVariables.ts +217 -4
- package/Types/StatusPage/SubscriberUpdateNotification.ts +32 -11
- package/UI/Components/CustomFields/CustomFieldFormFields.ts +317 -0
- package/UI/Components/CustomFields/CustomFieldModelFormFields.tsx +395 -0
- package/UI/Components/CustomFields/CustomFieldsDetail.tsx +95 -55
- package/UI/Components/Forms/ModelForm.tsx +70 -8
- package/UI/Components/Forms/Validation.ts +1 -1
- package/UI/Components/ModelFormModal/ModelFormModal.tsx +2 -4
- package/UI/Components/ModelTable/AnalyticsModelTable.tsx +2 -6
- package/UI/Components/ModelTable/BaseModelTable.tsx +9 -8
- package/UI/Components/ModelTable/CustomFieldColumns.tsx +14 -1
- package/UI/Components/ModelTable/ModelTable.tsx +6 -7
- package/UI/Utils/SensitiveUrlToken.ts +10 -5
- package/Utils/API.ts +247 -2
- package/Utils/Incident/IncidentNoteTemplateVariables.ts +304 -0
- package/Utils/Markdown/MarkdownEscape.ts +65 -0
- package/Utils/ProbeNetworkFailureUtil.ts +673 -0
- package/build/dist/Models/DatabaseModels/Incident.js +267 -1
- package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
- package/build/dist/Models/DatabaseModels/IncidentCustomField.js +207 -1
- package/build/dist/Models/DatabaseModels/IncidentCustomField.js.map +1 -1
- package/build/dist/Models/DatabaseModels/IncidentEpisode.js +31 -0
- package/build/dist/Models/DatabaseModels/IncidentEpisode.js.map +1 -1
- package/build/dist/Models/DatabaseModels/IncidentTemplate.js +124 -1
- package/build/dist/Models/DatabaseModels/IncidentTemplate.js.map +1 -1
- package/build/dist/Models/DatabaseModels/StatusPage.js +56 -0
- package/build/dist/Models/DatabaseModels/StatusPage.js.map +1 -1
- package/build/dist/Models/DatabaseModels/StatusPageSubscriber.js +131 -0
- package/build/dist/Models/DatabaseModels/StatusPageSubscriber.js.map +1 -1
- package/build/dist/Server/API/IncidentAPI.js +100 -1
- package/build/dist/Server/API/IncidentAPI.js.map +1 -1
- package/build/dist/Server/API/StatusPageAPI.js +417 -176
- package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
- package/build/dist/Server/API/StatusPageSubscriberAPI.js +52 -13
- package/build/dist/Server/API/StatusPageSubscriberAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795300000000-SkipHiddenIncidentCreatedNotifications.js +41 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795300000000-SkipHiddenIncidentCreatedNotifications.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795400000000-AddIncidentStatusPageScope.js +57 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795400000000-AddIncidentStatusPageScope.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795500000000-AddIncidentTemplateStatusPageScopeFlag.js +23 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795500000000-AddIncidentTemplateStatusPageScopeFlag.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795600000000-AddStatusPageSubscriberUnsubscribeToken.js +40 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795600000000-AddStatusPageSubscriberUnsubscribeToken.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795700000000-AddStatusPageSubscriberIsAddedByTeam.js +26 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795700000000-AddStatusPageSubscriberIsAddedByTeam.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795800000000-AddIncidentCustomFieldCreateAndNotificationSettings.js +89 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795800000000-AddIncidentCustomFieldCreateAndNotificationSettings.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795900000000-AddSubscriberNotificationClaimedAt.js +29 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1795900000000-AddSubscriberNotificationClaimedAt.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Infrastructure/Semaphore.js +3 -0
- package/build/dist/Server/Infrastructure/Semaphore.js.map +1 -1
- package/build/dist/Server/Middleware/IdentityRateLimit.js +89 -3
- package/build/dist/Server/Middleware/IdentityRateLimit.js.map +1 -1
- package/build/dist/Server/Middleware/SubscriberNotificationPreviewRateLimit.js +149 -0
- package/build/dist/Server/Middleware/SubscriberNotificationPreviewRateLimit.js.map +1 -0
- package/build/dist/Server/Middleware/SubscriberNotificationTestSendRateLimit.js +190 -0
- package/build/dist/Server/Middleware/SubscriberNotificationTestSendRateLimit.js.map +1 -0
- package/build/dist/Server/Services/DatabaseService.js +56 -7
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/IncidentCustomFieldService.js +204 -8
- package/build/dist/Server/Services/IncidentCustomFieldService.js.map +1 -1
- package/build/dist/Server/Services/IncidentEpisodePublicNoteService.js +24 -0
- package/build/dist/Server/Services/IncidentEpisodePublicNoteService.js.map +1 -1
- package/build/dist/Server/Services/IncidentEpisodeService.js +14 -0
- package/build/dist/Server/Services/IncidentEpisodeService.js.map +1 -1
- package/build/dist/Server/Services/IncidentEpisodeStateTimelineService.js +26 -0
- package/build/dist/Server/Services/IncidentEpisodeStateTimelineService.js.map +1 -1
- package/build/dist/Server/Services/IncidentPublicNoteService.js +26 -1
- package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +1052 -0
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Services/IncidentStateTimelineService.js +12 -0
- package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
- package/build/dist/Server/Services/IncidentTemplateService.js +83 -0
- package/build/dist/Server/Services/IncidentTemplateService.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +26 -1
- package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js +47 -17
- package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
- package/build/dist/Server/Services/SmsService.js +2 -22
- package/build/dist/Server/Services/SmsService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageService.js +47 -9
- package/build/dist/Server/Services/StatusPageService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateService.js +237 -32
- package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateStatusPageService.js +109 -0
- package/build/dist/Server/Services/StatusPageSubscriberNotificationTemplateStatusPageService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageSubscriberService.js +925 -99
- package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
- package/build/dist/Server/Types/Markdown.js +110 -6
- package/build/dist/Server/Types/Markdown.js.map +1 -1
- package/build/dist/Server/Types/Workflow/Components/Email.js +55 -6
- package/build/dist/Server/Types/Workflow/Components/Email.js.map +1 -1
- package/build/dist/Server/Utils/CustomField/CustomFieldRename.js +211 -0
- package/build/dist/Server/Utils/CustomField/CustomFieldRename.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/EgressGuard.js +41 -12
- package/build/dist/Server/Utils/DataSource/EgressGuard.js.map +1 -1
- package/build/dist/Server/Utils/Mail/PinnedSmtpSocket.js +101 -0
- package/build/dist/Server/Utils/Mail/PinnedSmtpSocket.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js +9 -0
- package/build/dist/Server/Utils/Monitor/MonitorCriteriaObservationBuilder.js.map +1 -1
- package/build/dist/Server/Utils/SSRFProtection.js +48 -6
- package/build/dist/Server/Utils/SSRFProtection.js.map +1 -1
- package/build/dist/Server/Utils/StatusPage/IncidentStatusPageScope.js +631 -0
- package/build/dist/Server/Utils/StatusPage/IncidentStatusPageScope.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/IncidentSubscriberAudienceBuilder.js +403 -0
- package/build/dist/Server/Utils/StatusPage/IncidentSubscriberAudienceBuilder.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.js +451 -0
- package/build/dist/Server/Utils/StatusPage/IncidentTemplateVariableBuilder.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageExclusion.js +13 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageExclusion.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageReadAccess.js +91 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageReadAccess.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.js +101 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeNotice.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.js +47 -0
- package/build/dist/Server/Utils/StatusPage/StatusPageSubscriberUnsubscribeToken.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.js +273 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberIncidentEmailBuilder.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationClaim.js +73 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationClaim.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.js +722 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationDeliveryRecord.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationFanOut.js +102 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationFanOut.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.js +527 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationPreviewBuilder.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationResendAccess.js +278 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationResendAccess.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationRunLimit.js +137 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationRunLimit.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationTiming.js +103 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberNotificationTiming.js.map +1 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberTemplateIncidentRecordAccess.js +114 -0
- package/build/dist/Server/Utils/StatusPage/SubscriberTemplateIncidentRecordAccess.js.map +1 -0
- package/build/dist/Server/Utils/StatusPageResource.js +39 -7
- package/build/dist/Server/Utils/StatusPageResource.js.map +1 -1
- package/build/dist/Server/Utils/VM/VMAPI.js.map +1 -1
- package/build/dist/Server/Utils/VM/VMRunner.js +1 -0
- package/build/dist/Server/Utils/VM/VMRunner.js.map +1 -1
- package/build/dist/Server/Utils/Workflow/OAuth2TokenClient.js +3 -0
- package/build/dist/Server/Utils/Workflow/OAuth2TokenClient.js.map +1 -1
- package/build/dist/Types/CustomField/CustomFieldOrder.js +36 -0
- package/build/dist/Types/CustomField/CustomFieldOrder.js.map +1 -0
- package/build/dist/Types/CustomField/CustomFieldSavedViews.js +135 -0
- package/build/dist/Types/CustomField/CustomFieldSavedViews.js.map +1 -0
- package/build/dist/Types/CustomField/CustomFieldTemplateMerge.js +27 -0
- package/build/dist/Types/CustomField/CustomFieldTemplateMerge.js.map +1 -0
- package/build/dist/Types/CustomField/CustomFieldType.js +12 -0
- package/build/dist/Types/CustomField/CustomFieldType.js.map +1 -1
- package/build/dist/Types/CustomField/CustomFieldValueFormat.js +126 -0
- package/build/dist/Types/CustomField/CustomFieldValueFormat.js.map +1 -0
- package/build/dist/Types/CustomField/CustomFieldValueValidator.js +280 -0
- package/build/dist/Types/CustomField/CustomFieldValueValidator.js.map +1 -0
- package/build/dist/Types/CustomField/CustomFieldVariableKey.js +150 -0
- package/build/dist/Types/CustomField/CustomFieldVariableKey.js.map +1 -0
- package/build/dist/Types/SafeHtml.js +84 -0
- package/build/dist/Types/SafeHtml.js.map +1 -0
- package/build/dist/Types/StatusPage/IncidentCreatedRenotify.js +117 -0
- package/build/dist/Types/StatusPage/IncidentCreatedRenotify.js.map +1 -0
- package/build/dist/Types/StatusPage/IncidentCreatedResend.js +86 -0
- package/build/dist/Types/StatusPage/IncidentCreatedResend.js.map +1 -0
- package/build/dist/Types/StatusPage/IncidentScopeAddedPagesNotification.js +246 -0
- package/build/dist/Types/StatusPage/IncidentScopeAddedPagesNotification.js.map +1 -0
- package/build/dist/Types/StatusPage/IncidentSubscriberAudience.js +183 -0
- package/build/dist/Types/StatusPage/IncidentSubscriberAudience.js.map +1 -0
- package/build/dist/Types/StatusPage/StatusPageSubscriberUnsubscribe.js +277 -0
- package/build/dist/Types/StatusPage/StatusPageSubscriberUnsubscribe.js.map +1 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationInterruption.js +27 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationInterruption.js.map +1 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationPreview.js +190 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationPreview.js.map +1 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationResend.js +102 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationResend.js.map +1 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationTemplateCompiler.js +97 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationTemplateCompiler.js.map +1 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationTemplatePreview.js +175 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationTemplatePreview.js.map +1 -0
- package/build/dist/Types/StatusPage/SubscriberNotificationTemplateVariables.js +144 -4
- package/build/dist/Types/StatusPage/SubscriberNotificationTemplateVariables.js.map +1 -1
- package/build/dist/Types/StatusPage/SubscriberUpdateNotification.js +29 -9
- package/build/dist/Types/StatusPage/SubscriberUpdateNotification.js.map +1 -1
- package/build/dist/UI/Components/CustomFields/CustomFieldFormFields.js +169 -0
- package/build/dist/UI/Components/CustomFields/CustomFieldFormFields.js.map +1 -0
- package/build/dist/UI/Components/CustomFields/CustomFieldModelFormFields.js +212 -0
- package/build/dist/UI/Components/CustomFields/CustomFieldModelFormFields.js.map +1 -0
- package/build/dist/UI/Components/CustomFields/CustomFieldsDetail.js +64 -49
- package/build/dist/UI/Components/CustomFields/CustomFieldsDetail.js.map +1 -1
- package/build/dist/UI/Components/Forms/ModelForm.js +39 -5
- package/build/dist/UI/Components/Forms/ModelForm.js.map +1 -1
- package/build/dist/UI/Components/Forms/Validation.js +1 -1
- package/build/dist/UI/Components/Forms/Validation.js.map +1 -1
- package/build/dist/UI/Components/ModelFormModal/ModelFormModal.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/AnalyticsModelTable.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js +2 -2
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/CustomFieldColumns.js +13 -1
- package/build/dist/UI/Components/ModelTable/CustomFieldColumns.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/ModelTable.js +1 -1
- package/build/dist/UI/Components/ModelTable/ModelTable.js.map +1 -1
- package/build/dist/UI/Utils/SensitiveUrlToken.js +10 -5
- package/build/dist/UI/Utils/SensitiveUrlToken.js.map +1 -1
- package/build/dist/Utils/API.js +177 -1
- package/build/dist/Utils/API.js.map +1 -1
- package/build/dist/Utils/Incident/IncidentNoteTemplateVariables.js +155 -0
- package/build/dist/Utils/Incident/IncidentNoteTemplateVariables.js.map +1 -0
- package/build/dist/Utils/Markdown/MarkdownEscape.js +48 -0
- package/build/dist/Utils/Markdown/MarkdownEscape.js.map +1 -1
- package/build/dist/Utils/ProbeNetworkFailureUtil.js +460 -0
- package/build/dist/Utils/ProbeNetworkFailureUtil.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
import { afterEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
|
+
import { SpyInstance } from "jest-mock";
|
|
3
|
+
import HTTPErrorResponse from "../../../Types/API/HTTPErrorResponse";
|
|
4
|
+
import HTTPResponse from "../../../Types/API/HTTPResponse";
|
|
5
|
+
import Headers from "../../../Types/API/Headers";
|
|
6
|
+
import APIException from "../../../Types/Exception/ApiException";
|
|
7
|
+
import { JSONObject } from "../../../Types/JSON";
|
|
8
|
+
import API from "../../../UI/Utils/API/API";
|
|
9
|
+
import { RESEND_VERIFICATION_EMAIL_API_URL } from "../../../../App/FeatureSet/Accounts/src/Utils/ApiPaths";
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS,
|
|
12
|
+
MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS,
|
|
13
|
+
VerificationEmailResendCredential,
|
|
14
|
+
VerificationEmailResendOutcome,
|
|
15
|
+
VerificationEmailResendResult,
|
|
16
|
+
clampCooldownSeconds,
|
|
17
|
+
formatCountdown,
|
|
18
|
+
getRetryAfterSecondsFromError,
|
|
19
|
+
parseVerificationEmailResendResponse,
|
|
20
|
+
requestVerificationEmailResend,
|
|
21
|
+
} from "../../../../App/FeatureSet/Accounts/src/Utils/VerificationEmailResend";
|
|
22
|
+
import {
|
|
23
|
+
WebmailProvider,
|
|
24
|
+
getWebmailProvider,
|
|
25
|
+
} from "../../../../App/FeatureSet/Accounts/src/Utils/WebmailProvider";
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* The pure half of "resend verification email": how a wait is shown, which
|
|
29
|
+
* waits are believed, how the route's answer is read and which inbox the
|
|
30
|
+
* "Open Gmail" shortcut may point at.
|
|
31
|
+
*
|
|
32
|
+
* Every number these helpers handle arrives over the network -- the signup
|
|
33
|
+
* response, the resend response, a proxy's Retry-After header -- so most of
|
|
34
|
+
* this file feeds them the shapes a broken or hostile answer could take and
|
|
35
|
+
* checks that the screen still says something sane: no negative countdown,
|
|
36
|
+
* no countdown of weeks that locks the button for good, no "we sent it" for a
|
|
37
|
+
* body the page does not understand. The webmail cases are the same idea for
|
|
38
|
+
* an address: only an EXACT consumer domain earns a link, never a look-alike.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
const GMAIL: WebmailProvider = {
|
|
42
|
+
name: "Gmail",
|
|
43
|
+
url: "https://mail.google.com/mail/u/0/#inbox",
|
|
44
|
+
};
|
|
45
|
+
const OUTLOOK: WebmailProvider = {
|
|
46
|
+
name: "Outlook",
|
|
47
|
+
url: "https://outlook.live.com/mail/0/",
|
|
48
|
+
};
|
|
49
|
+
const YAHOO: WebmailProvider = {
|
|
50
|
+
name: "Yahoo Mail",
|
|
51
|
+
url: "https://mail.yahoo.com/",
|
|
52
|
+
};
|
|
53
|
+
const ICLOUD: WebmailProvider = {
|
|
54
|
+
name: "iCloud Mail",
|
|
55
|
+
url: "https://www.icloud.com/mail",
|
|
56
|
+
};
|
|
57
|
+
const PROTON: WebmailProvider = {
|
|
58
|
+
name: "Proton Mail",
|
|
59
|
+
url: "https://mail.proton.me/",
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const RESEND_TOKEN: string =
|
|
63
|
+
"v1.eyJ2IjoxfQ.c2lnbmF0dXJlLXNpZ25hdHVyZS1zaWduYXR1cmUtc2ln";
|
|
64
|
+
const VERIFICATION_TOKEN: string = "8f2d1c3a-4b5e-4f60-8a71-92b3c4d5e6f7";
|
|
65
|
+
|
|
66
|
+
type PostOptions = Parameters<typeof API.post>[0];
|
|
67
|
+
|
|
68
|
+
type ErrorWithHeadersFunction = (
|
|
69
|
+
statusCode: number,
|
|
70
|
+
headers: Headers,
|
|
71
|
+
) => HTTPErrorResponse;
|
|
72
|
+
|
|
73
|
+
const errorWithHeaders: ErrorWithHeadersFunction = (
|
|
74
|
+
statusCode: number,
|
|
75
|
+
headers: Headers,
|
|
76
|
+
): HTTPErrorResponse => {
|
|
77
|
+
return new HTTPErrorResponse(
|
|
78
|
+
statusCode,
|
|
79
|
+
{
|
|
80
|
+
message:
|
|
81
|
+
"Too many requests for a new verification email. Please try again later.",
|
|
82
|
+
},
|
|
83
|
+
headers,
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
jest.restoreAllMocks();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("formatCountdown", () => {
|
|
92
|
+
test.each([
|
|
93
|
+
[0, "0:00"],
|
|
94
|
+
[1, "0:01"],
|
|
95
|
+
[5, "0:05"],
|
|
96
|
+
[9, "0:09"],
|
|
97
|
+
[10, "0:10"],
|
|
98
|
+
[45, "0:45"],
|
|
99
|
+
[59, "0:59"],
|
|
100
|
+
[60, "1:00"],
|
|
101
|
+
[61, "1:01"],
|
|
102
|
+
[119, "1:59"],
|
|
103
|
+
[120, "2:00"],
|
|
104
|
+
[599, "9:59"],
|
|
105
|
+
[600, "10:00"],
|
|
106
|
+
[725, "12:05"],
|
|
107
|
+
[3599, "59:59"],
|
|
108
|
+
[3600, "60:00"],
|
|
109
|
+
])("shows %p seconds as %p in English", (seconds: number, text: string) => {
|
|
110
|
+
expect(formatCountdown(seconds, "en")).toBe(text);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("never groups the minutes, however long the wait", () => {
|
|
114
|
+
// A day: 1440 minutes. "1,440:00" would read as a different number.
|
|
115
|
+
expect(formatCountdown(24 * 60 * 60, "en")).toBe("1440:00");
|
|
116
|
+
expect(formatCountdown(100000 * 60 + 7, "en")).toBe("100000:07");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("rounds a fractional wait UP, so 0:00 is never shown while a wait remains", () => {
|
|
120
|
+
expect(formatCountdown(0.001, "en")).toBe("0:01");
|
|
121
|
+
expect(formatCountdown(0.5, "en")).toBe("0:01");
|
|
122
|
+
expect(formatCountdown(4.2, "en")).toBe("0:05");
|
|
123
|
+
expect(formatCountdown(59.01, "en")).toBe("1:00");
|
|
124
|
+
expect(formatCountdown(60.5, "en")).toBe("1:01");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test.each([
|
|
128
|
+
["a negative number", -1],
|
|
129
|
+
["a large negative number", -3600],
|
|
130
|
+
["negative zero", -0],
|
|
131
|
+
["a negative fraction", -0.5],
|
|
132
|
+
["NaN", Number.NaN],
|
|
133
|
+
["negative infinity", Number.NEGATIVE_INFINITY],
|
|
134
|
+
["positive infinity", Number.POSITIVE_INFINITY],
|
|
135
|
+
])("shows %s as 0:00", (_label: string, seconds: number) => {
|
|
136
|
+
expect(formatCountdown(seconds, "en")).toBe("0:00");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("uses ASCII digits when no language is given", () => {
|
|
140
|
+
expect(formatCountdown(65)).toMatch(/^\d+:\d\d$/);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("uses the page's own numerals for Persian, still as two parts m:ss", () => {
|
|
144
|
+
let text: string = "";
|
|
145
|
+
|
|
146
|
+
expect(() => {
|
|
147
|
+
text = formatCountdown(65, "fa");
|
|
148
|
+
}).not.toThrow();
|
|
149
|
+
|
|
150
|
+
const parts: Array<string> = text.split(":");
|
|
151
|
+
|
|
152
|
+
expect(parts).toHaveLength(2);
|
|
153
|
+
expect(parts[0]).toBe(new Intl.NumberFormat("fa").format(1));
|
|
154
|
+
expect(parts[1]).toBe(
|
|
155
|
+
new Intl.NumberFormat("fa", { minimumIntegerDigits: 2 }).format(5),
|
|
156
|
+
);
|
|
157
|
+
// Persian numerals, not the Latin ones the English page shows.
|
|
158
|
+
expect(text).not.toBe("1:05");
|
|
159
|
+
expect(text).not.toMatch(/[0-9]/);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("pads the seconds for Persian as well", () => {
|
|
163
|
+
const parts: Array<string> = formatCountdown(3, "fa").split(":");
|
|
164
|
+
|
|
165
|
+
expect(parts).toHaveLength(2);
|
|
166
|
+
expect(Array.from(parts[1] || "")).toHaveLength(2);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test.each(["hi", "ja", "de", "zh-CN", "zh-TW"])(
|
|
170
|
+
"formats for %s without throwing",
|
|
171
|
+
(locale: string) => {
|
|
172
|
+
const text: string = formatCountdown(725, locale);
|
|
173
|
+
|
|
174
|
+
expect(text.split(":")).toHaveLength(2);
|
|
175
|
+
},
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
test("falls back to ASCII digits for a language tag Intl rejects", () => {
|
|
179
|
+
expect(() => {
|
|
180
|
+
return formatCountdown(65, "not a locale!!");
|
|
181
|
+
}).not.toThrow();
|
|
182
|
+
expect(formatCountdown(65, "not a locale!!")).toBe("1:05");
|
|
183
|
+
expect(formatCountdown(725, "not a locale!!")).toBe("12:05");
|
|
184
|
+
expect(formatCountdown(-5, "not a locale!!")).toBe("0:00");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("falls back to ASCII digits when Intl itself throws", () => {
|
|
188
|
+
jest.spyOn(Intl, "NumberFormat").mockImplementation(() => {
|
|
189
|
+
throw new Error("Intl is not available");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(formatCountdown(65, "fa")).toBe("1:05");
|
|
193
|
+
expect(formatCountdown(5, "en")).toBe("0:05");
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("clampCooldownSeconds", () => {
|
|
198
|
+
test.each([
|
|
199
|
+
[0, 0],
|
|
200
|
+
[1, 1],
|
|
201
|
+
[60, 60],
|
|
202
|
+
[0.1, 1],
|
|
203
|
+
[59.5, 60],
|
|
204
|
+
[MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS, 86400],
|
|
205
|
+
[MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS + 1, 86400],
|
|
206
|
+
[Number.MAX_SAFE_INTEGER, 86400],
|
|
207
|
+
[Number.MAX_VALUE, 86400],
|
|
208
|
+
[-1, 0],
|
|
209
|
+
[-0.5, 0],
|
|
210
|
+
[-86400, 0],
|
|
211
|
+
])("clamps %p to %p", (value: number, expected: number) => {
|
|
212
|
+
expect(clampCooldownSeconds(value)).toBe(expected);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("caps a wait at one day", () => {
|
|
216
|
+
expect(MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS).toBe(86400);
|
|
217
|
+
expect(DEFAULT_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS).toBe(60);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test.each([
|
|
221
|
+
["NaN", Number.NaN],
|
|
222
|
+
["Infinity", Number.POSITIVE_INFINITY],
|
|
223
|
+
["-Infinity", Number.NEGATIVE_INFINITY],
|
|
224
|
+
["a numeric string", "60"],
|
|
225
|
+
["an empty string", ""],
|
|
226
|
+
["null", null],
|
|
227
|
+
["undefined", undefined],
|
|
228
|
+
["true", true],
|
|
229
|
+
["an object", { seconds: 60 }],
|
|
230
|
+
["an array", [60]],
|
|
231
|
+
["a bigint", BigInt(60)],
|
|
232
|
+
])("treats %s as no wait at all", (_label: string, value: unknown) => {
|
|
233
|
+
expect(clampCooldownSeconds(value)).toBe(0);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("parseVerificationEmailResendResponse", () => {
|
|
238
|
+
test("reads a sent email with the server's cooldown", () => {
|
|
239
|
+
expect(
|
|
240
|
+
parseVerificationEmailResendResponse({
|
|
241
|
+
emailSent: true,
|
|
242
|
+
alreadyVerified: false,
|
|
243
|
+
retryAfterSeconds: 60,
|
|
244
|
+
}),
|
|
245
|
+
).toEqual({
|
|
246
|
+
outcome: VerificationEmailResendOutcome.Sent,
|
|
247
|
+
retryAfterSeconds: 60,
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("reads a cooldown with how long is left", () => {
|
|
252
|
+
expect(
|
|
253
|
+
parseVerificationEmailResendResponse({
|
|
254
|
+
emailSent: false,
|
|
255
|
+
alreadyVerified: false,
|
|
256
|
+
retryAfterSeconds: 42,
|
|
257
|
+
}),
|
|
258
|
+
).toEqual({
|
|
259
|
+
outcome: VerificationEmailResendOutcome.CoolingDown,
|
|
260
|
+
retryAfterSeconds: 42,
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("reads an already verified account with no wait", () => {
|
|
265
|
+
expect(
|
|
266
|
+
parseVerificationEmailResendResponse({
|
|
267
|
+
emailSent: false,
|
|
268
|
+
alreadyVerified: true,
|
|
269
|
+
retryAfterSeconds: 0,
|
|
270
|
+
}),
|
|
271
|
+
).toEqual({
|
|
272
|
+
outcome: VerificationEmailResendOutcome.AlreadyVerified,
|
|
273
|
+
retryAfterSeconds: 0,
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test("lets 'already verified' win over everything else in the body", () => {
|
|
278
|
+
expect(
|
|
279
|
+
parseVerificationEmailResendResponse({
|
|
280
|
+
emailSent: true,
|
|
281
|
+
alreadyVerified: true,
|
|
282
|
+
retryAfterSeconds: 999,
|
|
283
|
+
}),
|
|
284
|
+
).toEqual({
|
|
285
|
+
outcome: VerificationEmailResendOutcome.AlreadyVerified,
|
|
286
|
+
retryAfterSeconds: 0,
|
|
287
|
+
});
|
|
288
|
+
expect(
|
|
289
|
+
parseVerificationEmailResendResponse({ alreadyVerified: true }),
|
|
290
|
+
).toEqual({
|
|
291
|
+
outcome: VerificationEmailResendOutcome.AlreadyVerified,
|
|
292
|
+
retryAfterSeconds: 0,
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test.each([
|
|
297
|
+
["missing", undefined],
|
|
298
|
+
["zero", 0],
|
|
299
|
+
["negative", -30],
|
|
300
|
+
["NaN", Number.NaN],
|
|
301
|
+
["a string", "60"],
|
|
302
|
+
["null", null],
|
|
303
|
+
])(
|
|
304
|
+
"falls back to the default wait when the cooldown is %s",
|
|
305
|
+
(_label: string, retryAfterSeconds: unknown) => {
|
|
306
|
+
const body: JSONObject = { emailSent: true };
|
|
307
|
+
const coolingDownBody: JSONObject = { emailSent: false };
|
|
308
|
+
|
|
309
|
+
if (retryAfterSeconds !== undefined) {
|
|
310
|
+
body["retryAfterSeconds"] = retryAfterSeconds as number;
|
|
311
|
+
coolingDownBody["retryAfterSeconds"] = retryAfterSeconds as number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
expect(parseVerificationEmailResendResponse(body)).toEqual({
|
|
315
|
+
outcome: VerificationEmailResendOutcome.Sent,
|
|
316
|
+
retryAfterSeconds:
|
|
317
|
+
DEFAULT_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS,
|
|
318
|
+
});
|
|
319
|
+
expect(parseVerificationEmailResendResponse(coolingDownBody)).toEqual({
|
|
320
|
+
outcome: VerificationEmailResendOutcome.CoolingDown,
|
|
321
|
+
retryAfterSeconds:
|
|
322
|
+
DEFAULT_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS,
|
|
323
|
+
});
|
|
324
|
+
},
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
test("clamps an absurd cooldown and rounds a fractional one up", () => {
|
|
328
|
+
expect(
|
|
329
|
+
parseVerificationEmailResendResponse({
|
|
330
|
+
emailSent: false,
|
|
331
|
+
retryAfterSeconds: 10 * 365 * 24 * 60 * 60,
|
|
332
|
+
}).retryAfterSeconds,
|
|
333
|
+
).toBe(MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS);
|
|
334
|
+
expect(
|
|
335
|
+
parseVerificationEmailResendResponse({
|
|
336
|
+
emailSent: true,
|
|
337
|
+
retryAfterSeconds: 12.2,
|
|
338
|
+
}).retryAfterSeconds,
|
|
339
|
+
).toBe(13);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test.each([
|
|
343
|
+
["undefined", undefined],
|
|
344
|
+
["null", null],
|
|
345
|
+
["an empty string", ""],
|
|
346
|
+
["a string", "emailSent"],
|
|
347
|
+
["a number", 200],
|
|
348
|
+
["true", true],
|
|
349
|
+
["false", false],
|
|
350
|
+
["an array", [{ emailSent: true }]],
|
|
351
|
+
["an empty object", {}],
|
|
352
|
+
["a truthy but non-boolean emailSent", { emailSent: "true" }],
|
|
353
|
+
["emailSent as 1", { emailSent: 1 }],
|
|
354
|
+
["a truthy but non-boolean alreadyVerified", { alreadyVerified: "yes" }],
|
|
355
|
+
["alreadyVerified false and nothing else", { alreadyVerified: false }],
|
|
356
|
+
["an unrelated body", { message: "OK" }],
|
|
357
|
+
])(
|
|
358
|
+
"refuses %s instead of claiming an email was sent",
|
|
359
|
+
(_label: string, data: unknown) => {
|
|
360
|
+
expect(() => {
|
|
361
|
+
return parseVerificationEmailResendResponse(data);
|
|
362
|
+
}).toThrow("Unexpected response to a verification email request.");
|
|
363
|
+
},
|
|
364
|
+
);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe("getRetryAfterSecondsFromError", () => {
|
|
368
|
+
test("reads the lower-cased header the browser hands back", () => {
|
|
369
|
+
expect(
|
|
370
|
+
getRetryAfterSecondsFromError(
|
|
371
|
+
errorWithHeaders(429, { "retry-after": "30" }),
|
|
372
|
+
),
|
|
373
|
+
).toBe(30);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test.each(["Retry-After", "RETRY-AFTER", "retry-After"])(
|
|
377
|
+
"finds the header spelled %s",
|
|
378
|
+
(name: string) => {
|
|
379
|
+
expect(
|
|
380
|
+
getRetryAfterSecondsFromError(errorWithHeaders(429, { [name]: "45" })),
|
|
381
|
+
).toBe(45);
|
|
382
|
+
},
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
test("finds the header among others", () => {
|
|
386
|
+
expect(
|
|
387
|
+
getRetryAfterSecondsFromError(
|
|
388
|
+
errorWithHeaders(429, {
|
|
389
|
+
"content-type": "application/json",
|
|
390
|
+
"x-request-id": "abc",
|
|
391
|
+
"retry-after": "900",
|
|
392
|
+
}),
|
|
393
|
+
),
|
|
394
|
+
).toBe(900);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("trims whitespace around the value", () => {
|
|
398
|
+
expect(
|
|
399
|
+
getRetryAfterSecondsFromError(
|
|
400
|
+
errorWithHeaders(429, { "retry-after": " 12 \t" }),
|
|
401
|
+
),
|
|
402
|
+
).toBe(12);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("accepts a numeric header value", () => {
|
|
406
|
+
expect(
|
|
407
|
+
getRetryAfterSecondsFromError(
|
|
408
|
+
errorWithHeaders(429, { "retry-after": 75 as unknown as string }),
|
|
409
|
+
),
|
|
410
|
+
).toBe(75);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test("accepts zero", () => {
|
|
414
|
+
expect(
|
|
415
|
+
getRetryAfterSecondsFromError(
|
|
416
|
+
errorWithHeaders(429, { "retry-after": "0" }),
|
|
417
|
+
),
|
|
418
|
+
).toBe(0);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test.each([
|
|
422
|
+
["a word", "soon"],
|
|
423
|
+
["an HTTP date", "Wed, 21 Oct 2015 07:28:00 GMT"],
|
|
424
|
+
["a negative number", "-5"],
|
|
425
|
+
["a fraction", "1.5"],
|
|
426
|
+
["a signed number", "+30"],
|
|
427
|
+
["an exponent", "1e3"],
|
|
428
|
+
["hex", "0x10"],
|
|
429
|
+
["an empty value", ""],
|
|
430
|
+
["only whitespace", " "],
|
|
431
|
+
["two numbers", "30 60"],
|
|
432
|
+
["a number with a unit", "30s"],
|
|
433
|
+
])("ignores %s", (_label: string, value: string) => {
|
|
434
|
+
expect(
|
|
435
|
+
getRetryAfterSecondsFromError(
|
|
436
|
+
errorWithHeaders(429, { "retry-after": value }),
|
|
437
|
+
),
|
|
438
|
+
).toBe(0);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test("ignores a header value that is neither a string nor a number", () => {
|
|
442
|
+
expect(
|
|
443
|
+
getRetryAfterSecondsFromError(
|
|
444
|
+
errorWithHeaders(429, {
|
|
445
|
+
"retry-after": { seconds: 30 } as unknown as string,
|
|
446
|
+
}),
|
|
447
|
+
),
|
|
448
|
+
).toBe(0);
|
|
449
|
+
expect(
|
|
450
|
+
getRetryAfterSecondsFromError(
|
|
451
|
+
errorWithHeaders(429, { "retry-after": null as unknown as string }),
|
|
452
|
+
),
|
|
453
|
+
).toBe(0);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test("caps a huge wait at one day", () => {
|
|
457
|
+
expect(
|
|
458
|
+
getRetryAfterSecondsFromError(
|
|
459
|
+
errorWithHeaders(429, { "retry-after": "999999999999" }),
|
|
460
|
+
),
|
|
461
|
+
).toBe(MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS);
|
|
462
|
+
expect(
|
|
463
|
+
getRetryAfterSecondsFromError(
|
|
464
|
+
errorWithHeaders(429, { "retry-after": "9".repeat(20) }),
|
|
465
|
+
),
|
|
466
|
+
).toBe(MAX_VERIFICATION_EMAIL_RESEND_COOLDOWN_IN_SECONDS);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
test("treats a value too long to be a number as no wait (the caller's default applies)", () => {
|
|
470
|
+
// 400 nines is Infinity once parsed: not a finite wait, so not believed.
|
|
471
|
+
expect(
|
|
472
|
+
getRetryAfterSecondsFromError(
|
|
473
|
+
errorWithHeaders(429, { "retry-after": "9".repeat(400) }),
|
|
474
|
+
),
|
|
475
|
+
).toBe(0);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
test("is 0 when a 429 names no wait", () => {
|
|
479
|
+
expect(getRetryAfterSecondsFromError(errorWithHeaders(429, {}))).toBe(0);
|
|
480
|
+
expect(
|
|
481
|
+
getRetryAfterSecondsFromError(
|
|
482
|
+
errorWithHeaders(429, { "x-retry-after": "30" }),
|
|
483
|
+
),
|
|
484
|
+
).toBe(0);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test("is 0 when the error carries no headers object", () => {
|
|
488
|
+
const error: HTTPErrorResponse = errorWithHeaders(429, {});
|
|
489
|
+
error.headers = undefined as unknown as Headers;
|
|
490
|
+
|
|
491
|
+
expect(getRetryAfterSecondsFromError(error)).toBe(0);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
test.each([400, 403, 404, 500, 502, 503])(
|
|
495
|
+
"ignores Retry-After on a %p",
|
|
496
|
+
(statusCode: number) => {
|
|
497
|
+
expect(
|
|
498
|
+
getRetryAfterSecondsFromError(
|
|
499
|
+
errorWithHeaders(statusCode, { "retry-after": "30" }),
|
|
500
|
+
),
|
|
501
|
+
).toBe(0);
|
|
502
|
+
},
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
test.each([
|
|
506
|
+
["a plain Error", new Error("429")],
|
|
507
|
+
["an API exception", new APIException("Network Error")],
|
|
508
|
+
["a success response", new HTTPResponse<JSONObject>(200, {}, {})],
|
|
509
|
+
[
|
|
510
|
+
"a look-alike object",
|
|
511
|
+
{ statusCode: 429, headers: { "retry-after": "30" } },
|
|
512
|
+
],
|
|
513
|
+
["a string", "429"],
|
|
514
|
+
["null", null],
|
|
515
|
+
["undefined", undefined],
|
|
516
|
+
])("is 0 for %s", (_label: string, error: unknown) => {
|
|
517
|
+
expect(getRetryAfterSecondsFromError(error)).toBe(0);
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
describe("requestVerificationEmailResend", () => {
|
|
522
|
+
// API.post is generic; this is the instance jest.spyOn hands back.
|
|
523
|
+
type PostSpy = SpyInstance<
|
|
524
|
+
(options: PostOptions) => ReturnType<typeof API.post>
|
|
525
|
+
>;
|
|
526
|
+
|
|
527
|
+
const mockPost: (
|
|
528
|
+
answer: HTTPResponse<JSONObject> | HTTPErrorResponse,
|
|
529
|
+
) => PostSpy = (
|
|
530
|
+
answer: HTTPResponse<JSONObject> | HTTPErrorResponse,
|
|
531
|
+
): PostSpy => {
|
|
532
|
+
return jest.spyOn(API, "post").mockImplementation(async () => {
|
|
533
|
+
return answer as HTTPResponse<JSONObject>;
|
|
534
|
+
});
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const onlyCall: (spy: PostSpy) => PostOptions = (
|
|
538
|
+
spy: PostSpy,
|
|
539
|
+
): PostOptions => {
|
|
540
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
541
|
+
return spy.mock.calls[0]![0];
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
test("posts a resend token to /resend-verification-email and nothing else", async () => {
|
|
545
|
+
const post: PostSpy = mockPost(
|
|
546
|
+
new HTTPResponse<JSONObject>(
|
|
547
|
+
200,
|
|
548
|
+
{ emailSent: true, alreadyVerified: false, retryAfterSeconds: 60 },
|
|
549
|
+
{},
|
|
550
|
+
),
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
const result: VerificationEmailResendResult =
|
|
554
|
+
await requestVerificationEmailResend({ resendToken: RESEND_TOKEN });
|
|
555
|
+
|
|
556
|
+
const options: PostOptions = onlyCall(post);
|
|
557
|
+
|
|
558
|
+
expect(options.url.toString()).toBe(
|
|
559
|
+
RESEND_VERIFICATION_EMAIL_API_URL.toString(),
|
|
560
|
+
);
|
|
561
|
+
expect(options.url.toString()).toMatch(/\/resend-verification-email$/);
|
|
562
|
+
expect(options.data).toEqual({ data: { resendToken: RESEND_TOKEN } });
|
|
563
|
+
expect(result).toEqual({
|
|
564
|
+
outcome: VerificationEmailResendOutcome.Sent,
|
|
565
|
+
retryAfterSeconds: 60,
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
test("posts a verification token in the same envelope", async () => {
|
|
570
|
+
const post: PostSpy = mockPost(
|
|
571
|
+
new HTTPResponse<JSONObject>(
|
|
572
|
+
200,
|
|
573
|
+
{ emailSent: false, alreadyVerified: false, retryAfterSeconds: 17 },
|
|
574
|
+
{},
|
|
575
|
+
),
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
const result: VerificationEmailResendResult =
|
|
579
|
+
await requestVerificationEmailResend({
|
|
580
|
+
verificationToken: VERIFICATION_TOKEN,
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
const options: PostOptions = onlyCall(post);
|
|
584
|
+
|
|
585
|
+
expect(options.url.toString()).toBe(
|
|
586
|
+
RESEND_VERIFICATION_EMAIL_API_URL.toString(),
|
|
587
|
+
);
|
|
588
|
+
expect(options.data).toEqual({
|
|
589
|
+
data: { verificationToken: VERIFICATION_TOKEN },
|
|
590
|
+
});
|
|
591
|
+
expect(result).toEqual({
|
|
592
|
+
outcome: VerificationEmailResendOutcome.CoolingDown,
|
|
593
|
+
retryAfterSeconds: 17,
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
test("never sends an email address or any other field the caller slipped in", async () => {
|
|
598
|
+
const post: PostSpy = mockPost(
|
|
599
|
+
new HTTPResponse<JSONObject>(200, { alreadyVerified: true }, {}),
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
await requestVerificationEmailResend({
|
|
603
|
+
resendToken: RESEND_TOKEN,
|
|
604
|
+
email: "someone-else@example.com",
|
|
605
|
+
verificationToken: VERIFICATION_TOKEN,
|
|
606
|
+
} as unknown as VerificationEmailResendCredential);
|
|
607
|
+
|
|
608
|
+
expect(onlyCall(post).data).toEqual({
|
|
609
|
+
data: { resendToken: RESEND_TOKEN },
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
test("reads an already verified account", async () => {
|
|
614
|
+
mockPost(
|
|
615
|
+
new HTTPResponse<JSONObject>(
|
|
616
|
+
200,
|
|
617
|
+
{ emailSent: false, alreadyVerified: true, retryAfterSeconds: 0 },
|
|
618
|
+
{},
|
|
619
|
+
),
|
|
620
|
+
);
|
|
621
|
+
|
|
622
|
+
await expect(
|
|
623
|
+
requestVerificationEmailResend({ resendToken: RESEND_TOKEN }),
|
|
624
|
+
).resolves.toEqual({
|
|
625
|
+
outcome: VerificationEmailResendOutcome.AlreadyVerified,
|
|
626
|
+
retryAfterSeconds: 0,
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
test.each([400, 429, 500, 503])(
|
|
631
|
+
"throws the %p response itself, so the caller can tell refusals apart",
|
|
632
|
+
async (statusCode: number) => {
|
|
633
|
+
const refusal: HTTPErrorResponse = errorWithHeaders(statusCode, {
|
|
634
|
+
"retry-after": "30",
|
|
635
|
+
});
|
|
636
|
+
mockPost(refusal);
|
|
637
|
+
|
|
638
|
+
await expect(
|
|
639
|
+
requestVerificationEmailResend({ resendToken: RESEND_TOKEN }),
|
|
640
|
+
).rejects.toBe(refusal);
|
|
641
|
+
},
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
test("passes a network failure through untouched", async () => {
|
|
645
|
+
const failure: APIException = new APIException("Network Error");
|
|
646
|
+
jest.spyOn(API, "post").mockRejectedValue(failure);
|
|
647
|
+
|
|
648
|
+
await expect(
|
|
649
|
+
requestVerificationEmailResend({ verificationToken: VERIFICATION_TOKEN }),
|
|
650
|
+
).rejects.toBe(failure);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
test("refuses a success whose body it does not understand", async () => {
|
|
654
|
+
mockPost(new HTTPResponse<JSONObject>(200, { ok: true }, {}));
|
|
655
|
+
|
|
656
|
+
await expect(
|
|
657
|
+
requestVerificationEmailResend({ resendToken: RESEND_TOKEN }),
|
|
658
|
+
).rejects.toThrow("Unexpected response to a verification email request.");
|
|
659
|
+
});
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
describe("getWebmailProvider", () => {
|
|
663
|
+
test.each([
|
|
664
|
+
["ada@gmail.com", GMAIL],
|
|
665
|
+
["ada@googlemail.com", GMAIL],
|
|
666
|
+
["ada@outlook.com", OUTLOOK],
|
|
667
|
+
["ada@hotmail.com", OUTLOOK],
|
|
668
|
+
["ada@live.com", OUTLOOK],
|
|
669
|
+
["ada@msn.com", OUTLOOK],
|
|
670
|
+
["ada@yahoo.com", YAHOO],
|
|
671
|
+
["ada@ymail.com", YAHOO],
|
|
672
|
+
["ada@rocketmail.com", YAHOO],
|
|
673
|
+
["ada@icloud.com", ICLOUD],
|
|
674
|
+
["ada@me.com", ICLOUD],
|
|
675
|
+
["ada@mac.com", ICLOUD],
|
|
676
|
+
["ada@proton.me", PROTON],
|
|
677
|
+
["ada@protonmail.com", PROTON],
|
|
678
|
+
["ada@protonmail.ch", PROTON],
|
|
679
|
+
["ada@pm.me", PROTON],
|
|
680
|
+
])("recognises %s", (email: string, provider: WebmailProvider) => {
|
|
681
|
+
expect(getWebmailProvider(email)).toEqual(provider);
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
test.each([
|
|
685
|
+
["outlook.de"],
|
|
686
|
+
["outlook.fr"],
|
|
687
|
+
["outlook.co.uk"],
|
|
688
|
+
["outlook.com.au"],
|
|
689
|
+
["hotmail.co.uk"],
|
|
690
|
+
["hotmail.fr"],
|
|
691
|
+
["hotmail.com.br"],
|
|
692
|
+
["live.co.uk"],
|
|
693
|
+
["live.com.au"],
|
|
694
|
+
["live.nl"],
|
|
695
|
+
])("recognises the regional Outlook domain %s", (domain: string) => {
|
|
696
|
+
expect(getWebmailProvider(`ada@${domain}`)).toEqual(OUTLOOK);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
test.each([
|
|
700
|
+
["yahoo.fr"],
|
|
701
|
+
["yahoo.de"],
|
|
702
|
+
["yahoo.co.uk"],
|
|
703
|
+
["yahoo.co.jp"],
|
|
704
|
+
["yahoo.com.br"],
|
|
705
|
+
["yahoo.com.au"],
|
|
706
|
+
])("recognises the regional Yahoo domain %s", (domain: string) => {
|
|
707
|
+
expect(getWebmailProvider(`ada@${domain}`)).toEqual(YAHOO);
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
test("ignores case in the domain and whitespace around the address", () => {
|
|
711
|
+
expect(getWebmailProvider("Ada.Lovelace@GMAIL.COM")).toEqual(GMAIL);
|
|
712
|
+
expect(getWebmailProvider(" ada@Gmail.com ")).toEqual(GMAIL);
|
|
713
|
+
expect(getWebmailProvider("\tada@Hotmail.Co.UK\n")).toEqual(OUTLOOK);
|
|
714
|
+
expect(getWebmailProvider("ADA@YAHOO.CO.JP")).toEqual(YAHOO);
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
test("accepts any non-empty local part, tags included", () => {
|
|
718
|
+
expect(getWebmailProvider("ada+oneuptime@gmail.com")).toEqual(GMAIL);
|
|
719
|
+
expect(getWebmailProvider("a@pm.me")).toEqual(PROTON);
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
test("hands out a copy, so nobody can rewrite the shared table", () => {
|
|
723
|
+
const first: WebmailProvider | null = getWebmailProvider("ada@gmail.com");
|
|
724
|
+
|
|
725
|
+
expect(first).not.toBeNull();
|
|
726
|
+
first!.url = "https://attacker.example.com/";
|
|
727
|
+
first!.name = "Attacker";
|
|
728
|
+
|
|
729
|
+
expect(getWebmailProvider("grace@gmail.com")).toEqual(GMAIL);
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
test.each([
|
|
733
|
+
["a look-alike that ends in another domain", "ada@gmail.com.evil.io"],
|
|
734
|
+
["a look-alike prefix", "ada@notgmail.com"],
|
|
735
|
+
["a look-alike suffix", "ada@gmail.co"],
|
|
736
|
+
["a subdomain of a provider", "ada@mail.gmail.com"],
|
|
737
|
+
["a provider as a subdomain", "ada@gmail.evil.io"],
|
|
738
|
+
["a trailing dot", "ada@gmail.com."],
|
|
739
|
+
["two at signs", "a@b@gmail.com"],
|
|
740
|
+
["an at sign in the domain", "ada@gmail.com@evil.io"],
|
|
741
|
+
["an empty local part", "@gmail.com"],
|
|
742
|
+
["an empty domain", "ada@"],
|
|
743
|
+
["no at sign", "gmail.com"],
|
|
744
|
+
["an empty string", ""],
|
|
745
|
+
["only whitespace", " "],
|
|
746
|
+
["a company domain", "ada@acme.com"],
|
|
747
|
+
["another company domain", "ada@oneuptime.com"],
|
|
748
|
+
["an unknown webmail", "ada@fastmail.com"],
|
|
749
|
+
["a regional Gmail that does not exist", "ada@gmail.de"],
|
|
750
|
+
["a three-letter country code", "ada@outlook.abc"],
|
|
751
|
+
["a numeric country code", "ada@yahoo.12"],
|
|
752
|
+
["a regional look-alike", "ada@outlook.co.uk.evil.io"],
|
|
753
|
+
["an unlisted outlook form", "ada@outlook.org.uk"],
|
|
754
|
+
["a msn regional domain (not listed)", "ada@msn.de"],
|
|
755
|
+
["an icloud regional domain (not listed)", "ada@icloud.de"],
|
|
756
|
+
["an internal space", "ada@gm ail.com"],
|
|
757
|
+
])("offers no link for %s", (_label: string, email: string) => {
|
|
758
|
+
expect(getWebmailProvider(email)).toBeNull();
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
test.each([
|
|
762
|
+
["null", null],
|
|
763
|
+
["undefined", undefined],
|
|
764
|
+
])("offers no link for %s", (_label: string, email: null | undefined) => {
|
|
765
|
+
expect(getWebmailProvider(email)).toBeNull();
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
test("offers no link for a value that is not a string at all", () => {
|
|
769
|
+
expect(
|
|
770
|
+
getWebmailProvider({ toString: "ada@gmail.com" } as unknown as string),
|
|
771
|
+
).toBeNull();
|
|
772
|
+
expect(getWebmailProvider(42 as unknown as string)).toBeNull();
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
test("every link it hands out is one of the fixed inbox URLs", () => {
|
|
776
|
+
const allowedUrls: Array<string> = [
|
|
777
|
+
GMAIL.url,
|
|
778
|
+
OUTLOOK.url,
|
|
779
|
+
YAHOO.url,
|
|
780
|
+
ICLOUD.url,
|
|
781
|
+
PROTON.url,
|
|
782
|
+
];
|
|
783
|
+
|
|
784
|
+
for (const email of [
|
|
785
|
+
'evil"onclick@gmail.com',
|
|
786
|
+
"javascript:alert(1)@gmail.com",
|
|
787
|
+
"<script>@outlook.com",
|
|
788
|
+
"x@yahoo.co.jp",
|
|
789
|
+
]) {
|
|
790
|
+
const provider: WebmailProvider | null = getWebmailProvider(email);
|
|
791
|
+
|
|
792
|
+
expect(provider).not.toBeNull();
|
|
793
|
+
expect(allowedUrls).toContain(provider!.url);
|
|
794
|
+
expect(provider!.url).not.toContain(email);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
});
|