firebase-admin-edge 1.1.0 → 2.0.0
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/README.md +102 -405
- package/dist/app-check/app-check-endpoints.d.ts +31 -0
- package/dist/app-check/app-check-endpoints.d.ts.map +1 -0
- package/dist/app-check/app-check-endpoints.js +75 -0
- package/dist/app-check/app-check-endpoints.js.map +1 -0
- package/dist/app-check/app-check-jwt.d.ts +16 -0
- package/dist/app-check/app-check-jwt.d.ts.map +1 -0
- package/dist/app-check/app-check-jwt.js +59 -0
- package/dist/app-check/app-check-jwt.js.map +1 -0
- package/dist/app-check/app-check.d.ts +43 -0
- package/dist/app-check/app-check.d.ts.map +1 -0
- package/dist/app-check/app-check.js +141 -0
- package/dist/app-check/app-check.js.map +1 -0
- package/dist/auth/auth-blocking-types.d.ts +44 -0
- package/dist/auth/auth-blocking-types.d.ts.map +1 -0
- package/dist/auth/auth-blocking-types.js +2 -0
- package/dist/auth/auth-blocking-types.js.map +1 -0
- package/dist/auth/auth-config-types.d.ts +146 -0
- package/dist/auth/auth-config-types.d.ts.map +1 -0
- package/dist/auth/auth-config-types.js +2 -0
- package/dist/auth/auth-config-types.js.map +1 -0
- package/dist/auth/auth-config.d.ts +15 -0
- package/dist/auth/auth-config.d.ts.map +1 -0
- package/dist/auth/auth-config.js +413 -0
- package/dist/auth/auth-config.js.map +1 -0
- package/dist/auth/auth-emulator.d.ts +7 -0
- package/dist/auth/auth-emulator.d.ts.map +1 -0
- package/dist/auth/auth-emulator.js +24 -0
- package/dist/auth/auth-emulator.js.map +1 -0
- package/dist/auth/auth-endpoint-errors.d.ts +2 -0
- package/dist/auth/auth-endpoint-errors.d.ts.map +1 -1
- package/dist/auth/auth-endpoint-errors.js +20 -1
- package/dist/auth/auth-endpoint-errors.js.map +1 -1
- package/dist/auth/auth-error-codes.d.ts +12 -0
- package/dist/auth/auth-error-codes.d.ts.map +1 -1
- package/dist/auth/auth-error-codes.js +12 -0
- package/dist/auth/auth-error-codes.js.map +1 -1
- package/dist/auth/email-action-request.d.ts +40 -0
- package/dist/auth/email-action-request.d.ts.map +1 -0
- package/dist/auth/email-action-request.js +80 -0
- package/dist/auth/email-action-request.js.map +1 -0
- package/dist/auth/email-link.d.ts +24 -0
- package/dist/auth/email-link.d.ts.map +1 -0
- package/dist/auth/email-link.js +103 -0
- package/dist/auth/email-link.js.map +1 -0
- package/dist/auth/firebase-admin-auth.d.ts +60 -12
- package/dist/auth/firebase-admin-auth.d.ts.map +1 -1
- package/dist/auth/firebase-admin-auth.js +455 -64
- package/dist/auth/firebase-admin-auth.js.map +1 -1
- package/dist/auth/firebase-auth-endpoints.d.ts +94 -4
- package/dist/auth/firebase-auth-endpoints.d.ts.map +1 -1
- package/dist/auth/firebase-auth-endpoints.js +304 -64
- package/dist/auth/firebase-auth-endpoints.js.map +1 -1
- package/dist/auth/firebase-auth.d.ts +78 -4
- package/dist/auth/firebase-auth.d.ts.map +1 -1
- package/dist/auth/firebase-auth.js +101 -8
- package/dist/auth/firebase-auth.js.map +1 -1
- package/dist/auth/firebase-jwt.d.ts +19 -10
- package/dist/auth/firebase-jwt.d.ts.map +1 -1
- package/dist/auth/firebase-jwt.js +176 -39
- package/dist/auth/firebase-jwt.js.map +1 -1
- package/dist/auth/firebase-types.d.ts +3 -0
- package/dist/auth/firebase-types.d.ts.map +1 -1
- package/dist/auth/google-oauth.d.ts +0 -1
- package/dist/auth/google-oauth.d.ts.map +1 -1
- package/dist/auth/google-oauth.js +16 -86
- package/dist/auth/google-oauth.js.map +1 -1
- package/dist/auth/project-config-manager.d.ts +10 -0
- package/dist/auth/project-config-manager.d.ts.map +1 -0
- package/dist/auth/project-config-manager.js +22 -0
- package/dist/auth/project-config-manager.js.map +1 -0
- package/dist/auth/provider-credential.d.ts +43 -0
- package/dist/auth/provider-credential.d.ts.map +1 -0
- package/dist/auth/provider-credential.js +107 -0
- package/dist/auth/provider-credential.js.map +1 -0
- package/dist/auth/provider-session.d.ts +10 -0
- package/dist/auth/provider-session.d.ts.map +1 -0
- package/dist/auth/provider-session.js +28 -0
- package/dist/auth/provider-session.js.map +1 -0
- package/dist/auth/tenant-manager.d.ts +17 -0
- package/dist/auth/tenant-manager.d.ts.map +1 -0
- package/dist/auth/tenant-manager.js +59 -0
- package/dist/auth/tenant-manager.js.map +1 -0
- package/dist/auth/user-batch.d.ts +21 -0
- package/dist/auth/user-batch.d.ts.map +1 -0
- package/dist/auth/user-batch.js +49 -0
- package/dist/auth/user-batch.js.map +1 -0
- package/dist/auth/user-import.d.ts +55 -0
- package/dist/auth/user-import.d.ts.map +1 -0
- package/dist/auth/user-import.js +208 -0
- package/dist/auth/user-import.js.map +1 -0
- package/dist/auth/user-request.d.ts +10 -0
- package/dist/auth/user-request.d.ts.map +1 -1
- package/dist/auth/user-request.js +56 -0
- package/dist/auth/user-request.js.map +1 -1
- package/dist/db/aggregate.d.ts +49 -0
- package/dist/db/aggregate.d.ts.map +1 -0
- package/dist/db/aggregate.js +115 -0
- package/dist/db/aggregate.js.map +1 -0
- package/dist/db/bulk-writer.d.ts +55 -0
- package/dist/db/bulk-writer.d.ts.map +1 -0
- package/dist/db/bulk-writer.js +257 -0
- package/dist/db/bulk-writer.js.map +1 -0
- package/dist/db/bundle-builder.d.ts +17 -0
- package/dist/db/bundle-builder.d.ts.map +1 -0
- package/dist/db/bundle-builder.js +118 -0
- package/dist/db/bundle-builder.js.map +1 -0
- package/dist/db/bytes.d.ts +12 -0
- package/dist/db/bytes.d.ts.map +1 -0
- package/dist/db/bytes.js +49 -0
- package/dist/db/bytes.js.map +1 -0
- package/dist/db/collection-group.d.ts +14 -0
- package/dist/db/collection-group.d.ts.map +1 -0
- package/dist/db/collection-group.js +43 -0
- package/dist/db/collection-group.js.map +1 -0
- package/dist/db/collection-reference.d.ts +21 -0
- package/dist/db/collection-reference.d.ts.map +1 -0
- package/dist/db/collection-reference.js +46 -0
- package/dist/db/collection-reference.js.map +1 -0
- package/dist/db/document-reference.d.ts +41 -0
- package/dist/db/document-reference.d.ts.map +1 -0
- package/dist/db/document-reference.js +125 -0
- package/dist/db/document-reference.js.map +1 -0
- package/dist/db/document-snapshot.d.ts +31 -0
- package/dist/db/document-snapshot.d.ts.map +1 -0
- package/dist/db/document-snapshot.js +103 -0
- package/dist/db/document-snapshot.js.map +1 -0
- package/dist/db/explain.d.ts +28 -0
- package/dist/db/explain.d.ts.map +1 -0
- package/dist/db/explain.js +61 -0
- package/dist/db/explain.js.map +1 -0
- package/dist/db/field-path.d.ts +10 -0
- package/dist/db/field-path.d.ts.map +1 -0
- package/dist/db/field-path.js +65 -0
- package/dist/db/field-path.js.map +1 -0
- package/dist/db/field-value.d.ts +17 -0
- package/dist/db/field-value.d.ts.map +1 -0
- package/dist/db/field-value.js +57 -0
- package/dist/db/field-value.js.map +1 -0
- package/dist/db/filter.d.ts +20 -0
- package/dist/db/filter.d.ts.map +1 -0
- package/dist/db/filter.js +48 -0
- package/dist/db/filter.js.map +1 -0
- package/dist/db/firestore-converter.d.ts +11 -0
- package/dist/db/firestore-converter.d.ts.map +1 -0
- package/dist/db/firestore-converter.js +14 -0
- package/dist/db/firestore-converter.js.map +1 -0
- package/dist/db/firestore-document.d.ts +62 -0
- package/dist/db/firestore-document.d.ts.map +1 -0
- package/dist/db/firestore-document.js +238 -0
- package/dist/db/firestore-document.js.map +1 -0
- package/dist/db/firestore-endpoints.d.ts +41 -0
- package/dist/db/firestore-endpoints.d.ts.map +1 -0
- package/dist/db/firestore-endpoints.js +735 -0
- package/dist/db/firestore-endpoints.js.map +1 -0
- package/dist/db/firestore-error-codes.d.ts +24 -0
- package/dist/db/firestore-error-codes.d.ts.map +1 -0
- package/dist/db/firestore-error-codes.js +24 -0
- package/dist/db/firestore-error-codes.js.map +1 -0
- package/dist/db/firestore-logging.d.ts +23 -0
- package/dist/db/firestore-logging.d.ts.map +1 -0
- package/dist/db/firestore-logging.js +41 -0
- package/dist/db/firestore-logging.js.map +1 -0
- package/dist/db/firestore-path.d.ts +4 -0
- package/dist/db/firestore-path.d.ts.map +1 -0
- package/dist/db/firestore-path.js +37 -0
- package/dist/db/firestore-path.js.map +1 -0
- package/dist/db/firestore-results.d.ts +12 -0
- package/dist/db/firestore-results.d.ts.map +1 -0
- package/dist/db/firestore-results.js +19 -0
- package/dist/db/firestore-results.js.map +1 -0
- package/dist/db/firestore-settings.d.ts +22 -0
- package/dist/db/firestore-settings.d.ts.map +1 -0
- package/dist/db/firestore-settings.js +83 -0
- package/dist/db/firestore-settings.js.map +1 -0
- package/dist/db/firestore-telemetry.d.ts +21 -0
- package/dist/db/firestore-telemetry.d.ts.map +1 -0
- package/dist/db/firestore-telemetry.js +84 -0
- package/dist/db/firestore-telemetry.js.map +1 -0
- package/dist/db/firestore-types.d.ts +25 -0
- package/dist/db/firestore-types.d.ts.map +1 -0
- package/dist/db/firestore-types.js +2 -0
- package/dist/db/firestore-types.js.map +1 -0
- package/dist/db/firestore.d.ts +151 -0
- package/dist/db/firestore.d.ts.map +1 -0
- package/dist/db/firestore.js +505 -0
- package/dist/db/firestore.js.map +1 -0
- package/dist/db/geo-point.d.ts +11 -0
- package/dist/db/geo-point.d.ts.map +1 -0
- package/dist/db/geo-point.js +29 -0
- package/dist/db/geo-point.js.map +1 -0
- package/dist/db/json-stream.d.ts +3 -0
- package/dist/db/json-stream.d.ts.map +1 -0
- package/dist/db/json-stream.js +117 -0
- package/dist/db/json-stream.js.map +1 -0
- package/dist/db/pipeline-expression.d.ts +293 -0
- package/dist/db/pipeline-expression.d.ts.map +1 -0
- package/dist/db/pipeline-expression.js +1436 -0
- package/dist/db/pipeline-expression.js.map +1 -0
- package/dist/db/pipeline-query.d.ts +6 -0
- package/dist/db/pipeline-query.d.ts.map +1 -0
- package/dist/db/pipeline-query.js +91 -0
- package/dist/db/pipeline-query.js.map +1 -0
- package/dist/db/pipeline.d.ts +120 -0
- package/dist/db/pipeline.d.ts.map +1 -0
- package/dist/db/pipeline.js +396 -0
- package/dist/db/pipeline.js.map +1 -0
- package/dist/db/query-document-snapshot.d.ts +2 -0
- package/dist/db/query-document-snapshot.d.ts.map +1 -0
- package/dist/db/query-document-snapshot.js +2 -0
- package/dist/db/query-document-snapshot.js.map +1 -0
- package/dist/db/query-partition.d.ts +14 -0
- package/dist/db/query-partition.d.ts.map +1 -0
- package/dist/db/query-partition.js +32 -0
- package/dist/db/query-partition.js.map +1 -0
- package/dist/db/query-request.d.ts +96 -0
- package/dist/db/query-request.d.ts.map +1 -0
- package/dist/db/query-request.js +283 -0
- package/dist/db/query-request.js.map +1 -0
- package/dist/db/query.d.ts +129 -0
- package/dist/db/query.d.ts.map +1 -0
- package/dist/db/query.js +468 -0
- package/dist/db/query.js.map +1 -0
- package/dist/db/recursive-delete.d.ts +6 -0
- package/dist/db/recursive-delete.d.ts.map +1 -0
- package/dist/db/recursive-delete.js +38 -0
- package/dist/db/recursive-delete.js.map +1 -0
- package/dist/db/snapshot-listener.d.ts +10 -0
- package/dist/db/snapshot-listener.d.ts.map +1 -0
- package/dist/db/snapshot-listener.js +71 -0
- package/dist/db/snapshot-listener.js.map +1 -0
- package/dist/db/timestamp.d.ts +29 -0
- package/dist/db/timestamp.d.ts.map +1 -0
- package/dist/db/timestamp.js +98 -0
- package/dist/db/timestamp.js.map +1 -0
- package/dist/db/transaction.d.ts +44 -0
- package/dist/db/transaction.d.ts.map +1 -0
- package/dist/db/transaction.js +177 -0
- package/dist/db/transaction.js.map +1 -0
- package/dist/db/value-equality.d.ts +3 -0
- package/dist/db/value-equality.d.ts.map +1 -0
- package/dist/db/value-equality.js +29 -0
- package/dist/db/value-equality.js.map +1 -0
- package/dist/db/vector-query.d.ts +38 -0
- package/dist/db/vector-query.d.ts.map +1 -0
- package/dist/db/vector-query.js +110 -0
- package/dist/db/vector-query.js.map +1 -0
- package/dist/db/vector-value.d.ts +8 -0
- package/dist/db/vector-value.d.ts.map +1 -0
- package/dist/db/vector-value.js +25 -0
- package/dist/db/vector-value.js.map +1 -0
- package/dist/db/write-batch.d.ts +25 -0
- package/dist/db/write-batch.d.ts.map +1 -0
- package/dist/db/write-batch.js +72 -0
- package/dist/db/write-batch.js.map +1 -0
- package/dist/db/write-request.d.ts +36 -0
- package/dist/db/write-request.d.ts.map +1 -0
- package/dist/db/write-request.js +257 -0
- package/dist/db/write-request.js.map +1 -0
- package/dist/firebase-edge-server.d.ts +143 -36
- package/dist/firebase-edge-server.d.ts.map +1 -1
- package/dist/firebase-edge-server.js +466 -257
- package/dist/firebase-edge-server.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/rest-fetch.d.ts +1 -1
- package/dist/rest-fetch.d.ts.map +1 -1
- package/dist/storage/storage-acl.d.ts +48 -0
- package/dist/storage/storage-acl.d.ts.map +1 -0
- package/dist/storage/storage-acl.js +101 -0
- package/dist/storage/storage-acl.js.map +1 -0
- package/dist/storage/storage-bucket-endpoints.d.ts +10 -0
- package/dist/storage/storage-bucket-endpoints.d.ts.map +1 -0
- package/dist/storage/storage-bucket-endpoints.js +514 -0
- package/dist/storage/storage-bucket-endpoints.js.map +1 -0
- package/dist/storage/storage-bucket-types.d.ts +183 -0
- package/dist/storage/storage-bucket-types.d.ts.map +1 -0
- package/dist/storage/storage-bucket-types.js +2 -0
- package/dist/storage/storage-bucket-types.js.map +1 -0
- package/dist/storage/storage-bucket.d.ts +122 -0
- package/dist/storage/storage-bucket.d.ts.map +1 -0
- package/dist/storage/storage-bucket.js +544 -0
- package/dist/storage/storage-bucket.js.map +1 -0
- package/dist/storage/storage-channel.d.ts +10 -0
- package/dist/storage/storage-channel.d.ts.map +1 -0
- package/dist/storage/storage-channel.js +15 -0
- package/dist/storage/storage-channel.js.map +1 -0
- package/dist/storage/storage-checksum.d.ts +35 -0
- package/dist/storage/storage-checksum.d.ts.map +1 -0
- package/dist/storage/storage-checksum.js +312 -0
- package/dist/storage/storage-checksum.js.map +1 -0
- package/dist/storage/storage-endpoints.d.ts +14 -0
- package/dist/storage/storage-endpoints.d.ts.map +1 -0
- package/dist/storage/storage-endpoints.js +721 -0
- package/dist/storage/storage-endpoints.js.map +1 -0
- package/dist/storage/storage-file.d.ts +126 -0
- package/dist/storage/storage-file.d.ts.map +1 -0
- package/dist/storage/storage-file.js +604 -0
- package/dist/storage/storage-file.js.map +1 -0
- package/dist/storage/storage-hmac-key.d.ts +26 -0
- package/dist/storage/storage-hmac-key.d.ts.map +1 -0
- package/dist/storage/storage-hmac-key.js +45 -0
- package/dist/storage/storage-hmac-key.js.map +1 -0
- package/dist/storage/storage-iam.d.ts +20 -0
- package/dist/storage/storage-iam.d.ts.map +1 -0
- package/dist/storage/storage-iam.js +43 -0
- package/dist/storage/storage-iam.js.map +1 -0
- package/dist/storage/storage-md5.d.ts +11 -0
- package/dist/storage/storage-md5.d.ts.map +1 -0
- package/dist/storage/storage-md5.js +96 -0
- package/dist/storage/storage-md5.js.map +1 -0
- package/dist/storage/storage-notification.d.ts +24 -0
- package/dist/storage/storage-notification.d.ts.map +1 -0
- package/dist/storage/storage-notification.js +40 -0
- package/dist/storage/storage-notification.js.map +1 -0
- package/dist/storage/storage-progress.d.ts +4 -0
- package/dist/storage/storage-progress.d.ts.map +1 -0
- package/dist/storage/storage-progress.js +17 -0
- package/dist/storage/storage-progress.js.map +1 -0
- package/dist/storage/storage-reference-endpoints.d.ts +63 -0
- package/dist/storage/storage-reference-endpoints.d.ts.map +1 -0
- package/dist/storage/storage-reference-endpoints.js +276 -0
- package/dist/storage/storage-reference-endpoints.js.map +1 -0
- package/dist/storage/storage-reference-helpers.d.ts +12 -0
- package/dist/storage/storage-reference-helpers.d.ts.map +1 -0
- package/dist/storage/storage-reference-helpers.js +72 -0
- package/dist/storage/storage-reference-helpers.js.map +1 -0
- package/dist/storage/storage-reference-signing.d.ts +40 -0
- package/dist/storage/storage-reference-signing.d.ts.map +1 -0
- package/dist/storage/storage-reference-signing.js +289 -0
- package/dist/storage/storage-reference-signing.js.map +1 -0
- package/dist/storage/storage-reference-types.d.ts +76 -0
- package/dist/storage/storage-reference-types.d.ts.map +1 -0
- package/dist/storage/storage-reference-types.js +2 -0
- package/dist/storage/storage-reference-types.js.map +1 -0
- package/dist/storage/storage-results.d.ts +8 -0
- package/dist/storage/storage-results.d.ts.map +1 -0
- package/dist/storage/storage-results.js +32 -0
- package/dist/storage/storage-results.js.map +1 -0
- package/dist/storage/storage-resumable.d.ts +18 -0
- package/dist/storage/storage-resumable.d.ts.map +1 -0
- package/dist/storage/storage-resumable.js +166 -0
- package/dist/storage/storage-resumable.js.map +1 -0
- package/dist/storage/storage-retry.d.ts +9 -0
- package/dist/storage/storage-retry.d.ts.map +1 -0
- package/dist/storage/storage-retry.js +104 -0
- package/dist/storage/storage-retry.js.map +1 -0
- package/dist/storage/storage-signed-url.d.ts +9 -0
- package/dist/storage/storage-signed-url.d.ts.map +1 -0
- package/dist/storage/storage-signed-url.js +96 -0
- package/dist/storage/storage-signed-url.js.map +1 -0
- package/dist/storage/storage-special-endpoints.d.ts +10 -0
- package/dist/storage/storage-special-endpoints.d.ts.map +1 -0
- package/dist/storage/storage-special-endpoints.js +394 -0
- package/dist/storage/storage-special-endpoints.js.map +1 -0
- package/dist/storage/storage-special-types.d.ts +154 -0
- package/dist/storage/storage-special-types.d.ts.map +1 -0
- package/dist/storage/storage-special-types.js +2 -0
- package/dist/storage/storage-special-types.js.map +1 -0
- package/dist/storage/storage-types.d.ts +251 -0
- package/dist/storage/storage-types.d.ts.map +1 -0
- package/dist/storage/storage-types.js +2 -0
- package/dist/storage/storage-types.js.map +1 -0
- package/dist/storage/storage-upload-stream.d.ts +41 -0
- package/dist/storage/storage-upload-stream.d.ts.map +1 -0
- package/dist/storage/storage-upload-stream.js +335 -0
- package/dist/storage/storage-upload-stream.js.map +1 -0
- package/dist/storage/storage-xml-signing.d.ts +17 -0
- package/dist/storage/storage-xml-signing.d.ts.map +1 -0
- package/dist/storage/storage-xml-signing.js +144 -0
- package/dist/storage/storage-xml-signing.js.map +1 -0
- package/dist/storage/storage.d.ts +152 -0
- package/dist/storage/storage.d.ts.map +1 -0
- package/dist/storage/storage.js +532 -0
- package/dist/storage/storage.js.map +1 -0
- package/dist/utils/token-cache.d.ts.map +1 -1
- package/dist/utils/token-cache.js +3 -2
- package/dist/utils/token-cache.js.map +1 -1
- package/package.json +22 -6
- package/dist/auth/auth-endpoint-errors.test.d.ts +0 -2
- package/dist/auth/auth-endpoint-errors.test.d.ts.map +0 -1
- package/dist/auth/auth-endpoint-errors.test.js +0 -411
- package/dist/auth/auth-endpoint-errors.test.js.map +0 -1
- package/dist/auth/errors.test.d.ts +0 -2
- package/dist/auth/errors.test.d.ts.map +0 -1
- package/dist/auth/errors.test.js +0 -123
- package/dist/auth/errors.test.js.map +0 -1
- package/dist/auth/firebase-admin-auth.test.d.ts +0 -2
- package/dist/auth/firebase-admin-auth.test.d.ts.map +0 -1
- package/dist/auth/firebase-admin-auth.test.js +0 -923
- package/dist/auth/firebase-admin-auth.test.js.map +0 -1
- package/dist/auth/firebase-auth-endpoints.test.d.ts +0 -2
- package/dist/auth/firebase-auth-endpoints.test.d.ts.map +0 -1
- package/dist/auth/firebase-auth-endpoints.test.js +0 -957
- package/dist/auth/firebase-auth-endpoints.test.js.map +0 -1
- package/dist/auth/firebase-auth.test.d.ts +0 -2
- package/dist/auth/firebase-auth.test.d.ts.map +0 -1
- package/dist/auth/firebase-auth.test.js +0 -167
- package/dist/auth/firebase-auth.test.js.map +0 -1
- package/dist/auth/firebase-jwt.test.d.ts +0 -2
- package/dist/auth/firebase-jwt.test.d.ts.map +0 -1
- package/dist/auth/firebase-jwt.test.js +0 -164
- package/dist/auth/firebase-jwt.test.js.map +0 -1
- package/dist/auth/github-oauth.d.ts +0 -19
- package/dist/auth/github-oauth.d.ts.map +0 -1
- package/dist/auth/github-oauth.js +0 -145
- package/dist/auth/github-oauth.js.map +0 -1
- package/dist/auth/github-oauth.test.d.ts +0 -2
- package/dist/auth/github-oauth.test.d.ts.map +0 -1
- package/dist/auth/github-oauth.test.js +0 -202
- package/dist/auth/github-oauth.test.js.map +0 -1
- package/dist/auth/google-oauth.test.d.ts +0 -2
- package/dist/auth/google-oauth.test.d.ts.map +0 -1
- package/dist/auth/google-oauth.test.js +0 -200
- package/dist/auth/google-oauth.test.js.map +0 -1
- package/dist/auth/oauth.d.ts +0 -3
- package/dist/auth/oauth.d.ts.map +0 -1
- package/dist/auth/oauth.js +0 -48
- package/dist/auth/oauth.js.map +0 -1
- package/dist/auth/oauth.test.d.ts +0 -2
- package/dist/auth/oauth.test.d.ts.map +0 -1
- package/dist/auth/oauth.test.js +0 -109
- package/dist/auth/oauth.test.js.map +0 -1
- package/dist/auth/user-record.test.d.ts +0 -2
- package/dist/auth/user-record.test.d.ts.map +0 -1
- package/dist/auth/user-record.test.js +0 -198
- package/dist/auth/user-record.test.js.map +0 -1
- package/dist/auth/user-request.test.d.ts +0 -2
- package/dist/auth/user-request.test.d.ts.map +0 -1
- package/dist/auth/user-request.test.js +0 -269
- package/dist/auth/user-request.test.js.map +0 -1
- package/dist/firebase-edge-errors.test.d.ts +0 -2
- package/dist/firebase-edge-errors.test.d.ts.map +0 -1
- package/dist/firebase-edge-errors.test.js +0 -72
- package/dist/firebase-edge-errors.test.js.map +0 -1
- package/dist/firebase-edge-server.test.d.ts +0 -2
- package/dist/firebase-edge-server.test.d.ts.map +0 -1
- package/dist/firebase-edge-server.test.js +0 -264
- package/dist/firebase-edge-server.test.js.map +0 -1
- package/dist/rest-fetch.test.d.ts +0 -2
- package/dist/rest-fetch.test.d.ts.map +0 -1
- package/dist/rest-fetch.test.js +0 -164
- package/dist/rest-fetch.test.js.map +0 -1
|
@@ -1,923 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { FirebaseAdminAuth } from './firebase-admin-auth.js';
|
|
3
|
-
import { getAccountsInfo, createAccountAdmin, updateAccountAdmin, deleteAccountAdmin, downloadAccount, getAccountInfo, createSessionCookie as createSessionCookieEndpoint } from './firebase-auth-endpoints.js';
|
|
4
|
-
import { getToken } from './google-oauth.js';
|
|
5
|
-
import { signJWTCustomToken, verifyJWT, verifySessionJWT } from './firebase-jwt.js';
|
|
6
|
-
import { FirebaseEdgeError, FirebaseAdminAuthErrorInfo, FirebaseEndpointErrorInfo, JWTErrorInfo } from './errors.js';
|
|
7
|
-
vi.mock('./firebase-auth-endpoints.js', () => ({
|
|
8
|
-
getAccountsInfo: vi.fn(),
|
|
9
|
-
createAccountAdmin: vi.fn(),
|
|
10
|
-
updateAccountAdmin: vi.fn(),
|
|
11
|
-
deleteAccountAdmin: vi.fn(),
|
|
12
|
-
downloadAccount: vi.fn(),
|
|
13
|
-
getAccountInfo: vi.fn(),
|
|
14
|
-
createSessionCookie: vi.fn()
|
|
15
|
-
}));
|
|
16
|
-
vi.mock('./firebase-jwt.js', () => ({
|
|
17
|
-
signJWTCustomToken: vi.fn(),
|
|
18
|
-
verifyJWT: vi.fn(),
|
|
19
|
-
verifySessionJWT: vi.fn()
|
|
20
|
-
}));
|
|
21
|
-
vi.mock('./google-oauth.js', () => ({
|
|
22
|
-
getToken: vi.fn()
|
|
23
|
-
}));
|
|
24
|
-
const mockedGetToken = vi.mocked(getToken);
|
|
25
|
-
const mockedGetAccountInfo = vi.mocked(getAccountInfo);
|
|
26
|
-
const mockedCreateSessionCookieEndpoint = vi.mocked(createSessionCookieEndpoint);
|
|
27
|
-
const mockedVerifyJWT = vi.mocked(verifyJWT);
|
|
28
|
-
const mockedVerifySessionJWT = vi.mocked(verifySessionJWT);
|
|
29
|
-
const mockedSignJWTCustomToken = vi.mocked(signJWTCustomToken);
|
|
30
|
-
const serviceAccountKey = {
|
|
31
|
-
type: 'service_account',
|
|
32
|
-
project_id: 'test-project',
|
|
33
|
-
private_key_id: 'test-private-key-id',
|
|
34
|
-
private_key: 'test-private-key',
|
|
35
|
-
client_email: 'test@test-project.iam.gserviceaccount.com',
|
|
36
|
-
client_id: 'test-client-id',
|
|
37
|
-
auth_uri: 'https://accounts.google.com/o/oauth2/auth',
|
|
38
|
-
token_uri: 'https://oauth2.googleapis.com/token',
|
|
39
|
-
auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
|
|
40
|
-
client_x509_cert_url: 'https://www.googleapis.com/robot/v1/metadata/x509/test%40test-project.iam.gserviceaccount.com'
|
|
41
|
-
};
|
|
42
|
-
// Proper mock data that matches the expected types
|
|
43
|
-
const mockGoogleTokenResponse = {
|
|
44
|
-
access_token: 'test-access-token',
|
|
45
|
-
expires_in: 3600,
|
|
46
|
-
scope: 'scope',
|
|
47
|
-
token_type: 'Bearer',
|
|
48
|
-
id_token: 'test-id-token'
|
|
49
|
-
};
|
|
50
|
-
const mockUserRecord = {
|
|
51
|
-
localId: 'uid-1',
|
|
52
|
-
email: 'test@example.com',
|
|
53
|
-
emailVerified: true,
|
|
54
|
-
disabled: false
|
|
55
|
-
};
|
|
56
|
-
const mockFirebasePayload = {
|
|
57
|
-
iss: 'https://securetoken.google.com/test-project',
|
|
58
|
-
aud: 'test-project',
|
|
59
|
-
auth_time: 1000,
|
|
60
|
-
user_id: 'uid-1',
|
|
61
|
-
sub: 'uid-1',
|
|
62
|
-
iat: 1000,
|
|
63
|
-
exp: 2000,
|
|
64
|
-
email: 'test@example.com',
|
|
65
|
-
email_verified: true,
|
|
66
|
-
firebase: {
|
|
67
|
-
identities: {
|
|
68
|
-
email: ['test@example.com']
|
|
69
|
-
},
|
|
70
|
-
sign_in_provider: 'password'
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
describe('FirebaseAdminAuth', () => {
|
|
74
|
-
let auth;
|
|
75
|
-
let authWithTenant;
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
auth = new FirebaseAdminAuth(serviceAccountKey);
|
|
78
|
-
authWithTenant = new FirebaseAdminAuth(serviceAccountKey, 'test-tenant-id');
|
|
79
|
-
vi.clearAllMocks();
|
|
80
|
-
});
|
|
81
|
-
afterEach(() => {
|
|
82
|
-
vi.resetAllMocks();
|
|
83
|
-
});
|
|
84
|
-
describe('getUsers', () => {
|
|
85
|
-
beforeEach(() => {
|
|
86
|
-
mockedGetToken.mockResolvedValue({
|
|
87
|
-
data: mockGoogleTokenResponse,
|
|
88
|
-
error: null
|
|
89
|
-
});
|
|
90
|
-
vi.mocked(getAccountsInfo).mockResolvedValue({
|
|
91
|
-
data: {},
|
|
92
|
-
error: null
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
it('returns records and unmatched identifiers using one batch request', async () => {
|
|
96
|
-
const customFetch = vi.fn();
|
|
97
|
-
const instance = new FirebaseAdminAuth(serviceAccountKey, 'tenant', customFetch);
|
|
98
|
-
const ids = [{ uid: 'uid' }, { email: 'missing@example.com' }];
|
|
99
|
-
vi.mocked(getAccountsInfo).mockResolvedValue({
|
|
100
|
-
data: { users: [{ localId: 'uid' }] },
|
|
101
|
-
error: null
|
|
102
|
-
});
|
|
103
|
-
const { data, error } = await instance.getUsers(ids);
|
|
104
|
-
expect(error).toBeNull();
|
|
105
|
-
expect(data?.users[0]?.uid).toBe('uid');
|
|
106
|
-
expect(data?.notFound).toEqual([ids[1]]);
|
|
107
|
-
expect(getAccountsInfo).toHaveBeenCalledExactlyOnceWith({ localId: ['uid'], email: ['missing@example.com'] }, 'test-access-token', 'test-project', 'tenant', customFetch);
|
|
108
|
-
});
|
|
109
|
-
it('returns an empty batch without authentication or requests', async () => {
|
|
110
|
-
expect(await auth.getUsers([])).toEqual({
|
|
111
|
-
data: { users: [], notFound: [] },
|
|
112
|
-
error: null
|
|
113
|
-
});
|
|
114
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
115
|
-
expect(getAccountsInfo).not.toHaveBeenCalled();
|
|
116
|
-
});
|
|
117
|
-
it('rejects invalid inputs before authentication', async () => {
|
|
118
|
-
expect((await auth.getUsers([{ uid: '' }])).error).toBeInstanceOf(FirebaseEdgeError);
|
|
119
|
-
expect((await auth.getUsers(Array(101).fill({ uid: 'uid' }))).error).toBeInstanceOf(FirebaseEdgeError);
|
|
120
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
121
|
-
expect(getAccountsInfo).not.toHaveBeenCalled();
|
|
122
|
-
});
|
|
123
|
-
it('returns all identifiers in notFound when there are no matches', async () => {
|
|
124
|
-
expect(await auth.getUsers([{ uid: 'missing' }])).toEqual({
|
|
125
|
-
data: { users: [], notFound: [{ uid: 'missing' }] },
|
|
126
|
-
error: null
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
it('uses cached credentials', async () => {
|
|
130
|
-
const cache = {
|
|
131
|
-
getCache: vi.fn().mockResolvedValue(mockGoogleTokenResponse),
|
|
132
|
-
setCache: vi.fn()
|
|
133
|
-
};
|
|
134
|
-
const instance = new FirebaseAdminAuth(serviceAccountKey, undefined, undefined, cache);
|
|
135
|
-
expect((await instance.getUsers([{ uid: 'uid' }])).error).toBeNull();
|
|
136
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
137
|
-
expect(getAccountsInfo).toHaveBeenCalledTimes(1);
|
|
138
|
-
});
|
|
139
|
-
it('returns credential failures without a lookup', async () => {
|
|
140
|
-
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED);
|
|
141
|
-
mockedGetToken.mockResolvedValue({ data: null, error });
|
|
142
|
-
expect(await auth.getUsers([{ uid: 'uid' }])).toEqual({
|
|
143
|
-
data: null,
|
|
144
|
-
error
|
|
145
|
-
});
|
|
146
|
-
expect(getAccountsInfo).not.toHaveBeenCalled();
|
|
147
|
-
});
|
|
148
|
-
it('guards against missing access tokens', async () => {
|
|
149
|
-
mockedGetToken.mockResolvedValue({
|
|
150
|
-
data: {},
|
|
151
|
-
error: null
|
|
152
|
-
});
|
|
153
|
-
expect((await auth.getUsers([{ uid: 'uid' }])).error?.code).toBe('auth/admin-no-token-returned');
|
|
154
|
-
expect(getAccountsInfo).not.toHaveBeenCalled();
|
|
155
|
-
});
|
|
156
|
-
it('retains mapped endpoint failures as the cause', async () => {
|
|
157
|
-
const cause = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_PERMISSION_DENIED);
|
|
158
|
-
vi.mocked(getAccountsInfo).mockResolvedValue({
|
|
159
|
-
data: null,
|
|
160
|
-
error: cause
|
|
161
|
-
});
|
|
162
|
-
const result = await auth.getUsers([{ uid: 'uid' }]);
|
|
163
|
-
expect(result.data).toBeNull();
|
|
164
|
-
expect(result.error?.cause).toBe(cause);
|
|
165
|
-
});
|
|
166
|
-
it.each([null, 'not JSON', { users: [{}] }, { users: 'invalid' }])('returns structured errors for malformed responses %j', async (data) => {
|
|
167
|
-
vi.mocked(getAccountsInfo).mockResolvedValue({
|
|
168
|
-
data,
|
|
169
|
-
error: null
|
|
170
|
-
});
|
|
171
|
-
const result = await auth.getUsers([{ uid: 'uid' }]);
|
|
172
|
-
expect(result.data).toBeNull();
|
|
173
|
-
expect(result.error?.code).toBe('auth/admin-user-lookup-failed');
|
|
174
|
-
});
|
|
175
|
-
it('returns network and token exceptions rather than rejecting', async () => {
|
|
176
|
-
vi.mocked(getAccountsInfo).mockRejectedValue(new Error('offline'));
|
|
177
|
-
expect((await auth.getUsers([{ uid: 'uid' }])).error?.cause).toBeInstanceOf(Error);
|
|
178
|
-
mockedGetToken.mockRejectedValue('token failure');
|
|
179
|
-
expect((await auth.getUsers([{ uid: 'uid' }])).error?.cause).toBeInstanceOf(Error);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
describe('user management', () => {
|
|
183
|
-
beforeEach(() => {
|
|
184
|
-
mockedGetToken.mockResolvedValue({
|
|
185
|
-
data: mockGoogleTokenResponse,
|
|
186
|
-
error: null
|
|
187
|
-
});
|
|
188
|
-
mockedGetAccountInfo.mockResolvedValue({
|
|
189
|
-
data: mockUserRecord,
|
|
190
|
-
error: null
|
|
191
|
-
});
|
|
192
|
-
vi.mocked(createAccountAdmin).mockResolvedValue({
|
|
193
|
-
data: { localId: 'uid-1' },
|
|
194
|
-
error: null
|
|
195
|
-
});
|
|
196
|
-
vi.mocked(updateAccountAdmin).mockResolvedValue({
|
|
197
|
-
data: { localId: 'uid-1' },
|
|
198
|
-
error: null
|
|
199
|
-
});
|
|
200
|
-
vi.mocked(deleteAccountAdmin).mockResolvedValue({ error: null });
|
|
201
|
-
});
|
|
202
|
-
it('creates a user and reads the full record with the same credentials', async () => {
|
|
203
|
-
const customFetch = vi.fn();
|
|
204
|
-
const instance = new FirebaseAdminAuth(serviceAccountKey, 'tenant', customFetch);
|
|
205
|
-
const result = await instance.createUser({
|
|
206
|
-
email: 'test@example.com',
|
|
207
|
-
photoURL: 'https://example.com/photo',
|
|
208
|
-
disabled: false
|
|
209
|
-
});
|
|
210
|
-
expect(result.error).toBeNull();
|
|
211
|
-
expect(result.data?.uid).toBe('uid-1');
|
|
212
|
-
expect(result.data?.toJSON()).toMatchObject({
|
|
213
|
-
uid: 'uid-1',
|
|
214
|
-
email: 'test@example.com'
|
|
215
|
-
});
|
|
216
|
-
expect(createAccountAdmin).toHaveBeenCalledWith('test-project', {
|
|
217
|
-
email: 'test@example.com',
|
|
218
|
-
photoUrl: 'https://example.com/photo',
|
|
219
|
-
disabled: false
|
|
220
|
-
}, 'test-access-token', customFetch, 'tenant');
|
|
221
|
-
expect(mockedGetAccountInfo).toHaveBeenCalledWith({ uid: 'uid-1' }, 'test-access-token', 'test-project', 'tenant', customFetch);
|
|
222
|
-
expect(mockedGetToken).toHaveBeenCalledTimes(1);
|
|
223
|
-
});
|
|
224
|
-
it('updates through the existing endpoint with translated fields and tenant', async () => {
|
|
225
|
-
const result = await authWithTenant.updateUser('uid-1', {
|
|
226
|
-
displayName: null,
|
|
227
|
-
photoURL: null,
|
|
228
|
-
phoneNumber: null,
|
|
229
|
-
disabled: true
|
|
230
|
-
});
|
|
231
|
-
expect(result.error).toBeNull();
|
|
232
|
-
expect(result.data?.uid).toBe('uid-1');
|
|
233
|
-
expect(updateAccountAdmin).toHaveBeenCalledWith('test-project', 'uid-1', {
|
|
234
|
-
deleteAttribute: ['DISPLAY_NAME', 'PHOTO_URL'],
|
|
235
|
-
deleteProvider: ['phone'],
|
|
236
|
-
disableUser: true
|
|
237
|
-
}, 'test-access-token', undefined, 'test-tenant-id');
|
|
238
|
-
expect(mockedGetAccountInfo).toHaveBeenCalledWith({ uid: 'uid-1' }, 'test-access-token', 'test-project', 'test-tenant-id', undefined);
|
|
239
|
-
});
|
|
240
|
-
it('deletes without a follow-up lookup and returns void data', async () => {
|
|
241
|
-
expect(await authWithTenant.deleteUser('uid-1')).toEqual({
|
|
242
|
-
data: undefined,
|
|
243
|
-
error: null
|
|
244
|
-
});
|
|
245
|
-
expect(deleteAccountAdmin).toHaveBeenCalledWith('test-project', 'uid-1', 'test-access-token', undefined, 'test-tenant-id');
|
|
246
|
-
expect(mockedGetAccountInfo).not.toHaveBeenCalled();
|
|
247
|
-
});
|
|
248
|
-
it.each(['', 'a'.repeat(129), null])('rejects invalid UID %s before authentication', async (uid) => {
|
|
249
|
-
expect((await auth.updateUser(uid, {})).error).toBeInstanceOf(FirebaseEdgeError);
|
|
250
|
-
expect((await auth.deleteUser(uid)).error).toBeInstanceOf(FirebaseEdgeError);
|
|
251
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
252
|
-
});
|
|
253
|
-
it('rejects invalid create and update properties before authentication', async () => {
|
|
254
|
-
expect((await auth.createUser({ email: 'invalid' })).error).toBeInstanceOf(FirebaseEdgeError);
|
|
255
|
-
expect((await auth.updateUser('uid', { password: 'short' })).error).toBeInstanceOf(FirebaseEdgeError);
|
|
256
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
257
|
-
});
|
|
258
|
-
const operations = [
|
|
259
|
-
{
|
|
260
|
-
name: 'create',
|
|
261
|
-
run: () => auth.createUser({}),
|
|
262
|
-
endpoint: vi.mocked(createAccountAdmin)
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
name: 'update',
|
|
266
|
-
run: () => auth.updateUser('uid-1', {}),
|
|
267
|
-
endpoint: vi.mocked(updateAccountAdmin)
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
name: 'delete',
|
|
271
|
-
run: () => auth.deleteUser('uid-1'),
|
|
272
|
-
endpoint: vi.mocked(deleteAccountAdmin)
|
|
273
|
-
}
|
|
274
|
-
];
|
|
275
|
-
describe.each(operations)('$name errors', ({ name, run, endpoint }) => {
|
|
276
|
-
it('returns credential errors without a write', async () => {
|
|
277
|
-
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED);
|
|
278
|
-
mockedGetToken.mockResolvedValue({ data: null, error });
|
|
279
|
-
expect(await run()).toEqual({ data: null, error });
|
|
280
|
-
expect(endpoint).not.toHaveBeenCalled();
|
|
281
|
-
});
|
|
282
|
-
it('guards against missing credentials', async () => {
|
|
283
|
-
mockedGetToken.mockResolvedValue({
|
|
284
|
-
data: {},
|
|
285
|
-
error: null
|
|
286
|
-
});
|
|
287
|
-
expect((await run()).error?.code).toBe('auth/admin-no-token-returned');
|
|
288
|
-
expect(endpoint).not.toHaveBeenCalled();
|
|
289
|
-
});
|
|
290
|
-
it('preserves API errors as the cause without a readback', async () => {
|
|
291
|
-
const cause = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_USER_NOT_FOUND);
|
|
292
|
-
endpoint.mockResolvedValue({ data: null, error: cause });
|
|
293
|
-
const result = await run();
|
|
294
|
-
expect(result.data).toBeNull();
|
|
295
|
-
expect(result.error?.code).toBe(`auth/admin-${name}-user-failed`);
|
|
296
|
-
expect(result.error?.cause).toBe(cause);
|
|
297
|
-
expect(mockedGetAccountInfo).not.toHaveBeenCalled();
|
|
298
|
-
});
|
|
299
|
-
it('returns transport exceptions instead of rejecting', async () => {
|
|
300
|
-
const cause = new Error('offline');
|
|
301
|
-
endpoint.mockRejectedValue(cause);
|
|
302
|
-
const result = await run();
|
|
303
|
-
expect(result.data).toBeNull();
|
|
304
|
-
expect(result.error?.cause).toBe(cause);
|
|
305
|
-
});
|
|
306
|
-
it('returns unexpected token exceptions', async () => {
|
|
307
|
-
mockedGetToken.mockRejectedValue('token failure');
|
|
308
|
-
const result = await run();
|
|
309
|
-
expect(result.data).toBeNull();
|
|
310
|
-
expect(result.error?.code).toBe(`auth/admin-${name}-user-failed`);
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
describe.each(operations.slice(0, 2))('$name readback', ({ run, endpoint }) => {
|
|
314
|
-
it('requires a UID in the write response', async () => {
|
|
315
|
-
endpoint.mockResolvedValue({
|
|
316
|
-
data: { localId: '' },
|
|
317
|
-
error: null
|
|
318
|
-
});
|
|
319
|
-
expect((await run()).error).toBeInstanceOf(FirebaseEdgeError);
|
|
320
|
-
expect(mockedGetAccountInfo).not.toHaveBeenCalled();
|
|
321
|
-
});
|
|
322
|
-
it('returns lookup errors', async () => {
|
|
323
|
-
const error = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_USER_NOT_FOUND);
|
|
324
|
-
mockedGetAccountInfo.mockResolvedValue({
|
|
325
|
-
data: null,
|
|
326
|
-
error
|
|
327
|
-
});
|
|
328
|
-
expect(await run()).toEqual({ data: null, error });
|
|
329
|
-
});
|
|
330
|
-
it('handles a missing user in the lookup response', async () => {
|
|
331
|
-
mockedGetAccountInfo.mockResolvedValue({
|
|
332
|
-
data: null,
|
|
333
|
-
error: null
|
|
334
|
-
});
|
|
335
|
-
expect((await run()).error?.code).toBe('auth/admin-user-record-not-found');
|
|
336
|
-
});
|
|
337
|
-
it('returns conversion errors rather than rejecting', async () => {
|
|
338
|
-
mockedGetAccountInfo.mockResolvedValue({
|
|
339
|
-
data: { localId: 'uid', customAttributes: '{' },
|
|
340
|
-
error: null
|
|
341
|
-
});
|
|
342
|
-
expect((await run()).error).toBeInstanceOf(FirebaseEdgeError);
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
describe('listUsers', () => {
|
|
347
|
-
const download = vi.mocked(downloadAccount);
|
|
348
|
-
beforeEach(() => {
|
|
349
|
-
mockedGetToken.mockResolvedValue({
|
|
350
|
-
data: mockGoogleTokenResponse,
|
|
351
|
-
error: null
|
|
352
|
-
});
|
|
353
|
-
download.mockResolvedValue({ data: {}, error: null });
|
|
354
|
-
});
|
|
355
|
-
it('requests the default page and converts the result', async () => {
|
|
356
|
-
download.mockResolvedValue({
|
|
357
|
-
data: { users: [{ localId: 'uid' }], nextPageToken: 'next' },
|
|
358
|
-
error: null
|
|
359
|
-
});
|
|
360
|
-
const { data, error } = await auth.listUsers();
|
|
361
|
-
expect(error).toBeNull();
|
|
362
|
-
expect(data?.pageToken).toBe('next');
|
|
363
|
-
expect(data?.users[0]).toMatchObject({
|
|
364
|
-
uid: 'uid',
|
|
365
|
-
emailVerified: false,
|
|
366
|
-
disabled: false
|
|
367
|
-
});
|
|
368
|
-
expect(download).toHaveBeenCalledExactlyOnceWith('test-access-token', 'test-project', 1000, undefined, undefined, undefined);
|
|
369
|
-
});
|
|
370
|
-
it('forwards pagination, tenant, and custom fetch to the endpoint', async () => {
|
|
371
|
-
const customFetch = vi.fn();
|
|
372
|
-
const instance = new FirebaseAdminAuth(serviceAccountKey, 'tenant', customFetch);
|
|
373
|
-
expect(await instance.listUsers(25, 'opaque+/=')).toEqual({
|
|
374
|
-
data: { users: [] },
|
|
375
|
-
error: null
|
|
376
|
-
});
|
|
377
|
-
expect(download).toHaveBeenCalledExactlyOnceWith('test-access-token', 'test-project', 25, 'opaque+/=', 'tenant', customFetch);
|
|
378
|
-
expect(mockedGetToken).toHaveBeenCalledWith(serviceAccountKey, customFetch);
|
|
379
|
-
});
|
|
380
|
-
it('defaults an undefined page size and omits an absent page token', async () => {
|
|
381
|
-
expect(await auth.listUsers(undefined)).toEqual({
|
|
382
|
-
data: { users: [] },
|
|
383
|
-
error: null
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
it('preserves an explicitly returned empty page token', async () => {
|
|
387
|
-
download.mockResolvedValue({
|
|
388
|
-
data: { nextPageToken: '' },
|
|
389
|
-
error: null
|
|
390
|
-
});
|
|
391
|
-
expect(await auth.listUsers()).toEqual({
|
|
392
|
-
data: { users: [], pageToken: '' },
|
|
393
|
-
error: null
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
it.each([0, -1, 1001, 1.5, NaN, Infinity, null, '10'])('rejects invalid page size %s before authentication', async (size) => {
|
|
397
|
-
const result = await auth.listUsers(size);
|
|
398
|
-
expect(result.data).toBeNull();
|
|
399
|
-
expect(result.error?.code).toBe('auth/admin-api-invalid-argument');
|
|
400
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
401
|
-
expect(download).not.toHaveBeenCalled();
|
|
402
|
-
});
|
|
403
|
-
it.each(['', null, 123, {}])('rejects invalid page token %s before authentication', async (pageToken) => {
|
|
404
|
-
const result = await auth.listUsers(25, pageToken);
|
|
405
|
-
expect(result.data).toBeNull();
|
|
406
|
-
expect(result.error?.code).toBe('auth/admin-invalid-page-token');
|
|
407
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
408
|
-
expect(download).not.toHaveBeenCalled();
|
|
409
|
-
});
|
|
410
|
-
it('returns authentication errors without calling the endpoint', async () => {
|
|
411
|
-
const error = new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED);
|
|
412
|
-
mockedGetToken.mockResolvedValue({ data: null, error });
|
|
413
|
-
expect(await auth.listUsers()).toEqual({ data: null, error });
|
|
414
|
-
expect(download).not.toHaveBeenCalled();
|
|
415
|
-
});
|
|
416
|
-
it('uses cached credentials', async () => {
|
|
417
|
-
const cache = {
|
|
418
|
-
getCache: vi.fn().mockResolvedValue(mockGoogleTokenResponse),
|
|
419
|
-
setCache: vi.fn()
|
|
420
|
-
};
|
|
421
|
-
const instance = new FirebaseAdminAuth(serviceAccountKey, undefined, undefined, cache);
|
|
422
|
-
expect((await instance.listUsers()).error).toBeNull();
|
|
423
|
-
expect(mockedGetToken).not.toHaveBeenCalled();
|
|
424
|
-
expect(cache.getCache).toHaveBeenCalledWith('__cache');
|
|
425
|
-
expect(download).toHaveBeenCalledWith('test-access-token', 'test-project', 1000, undefined, undefined, undefined);
|
|
426
|
-
});
|
|
427
|
-
it('guards against a missing access token', async () => {
|
|
428
|
-
mockedGetToken.mockResolvedValue({
|
|
429
|
-
data: {},
|
|
430
|
-
error: null
|
|
431
|
-
});
|
|
432
|
-
expect((await auth.listUsers()).error?.code).toBe('auth/admin-no-token-returned');
|
|
433
|
-
expect(download).not.toHaveBeenCalled();
|
|
434
|
-
});
|
|
435
|
-
it('retains a mapped endpoint error as its cause', async () => {
|
|
436
|
-
const cause = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_PERMISSION_DENIED);
|
|
437
|
-
download.mockResolvedValue({ data: null, error: cause });
|
|
438
|
-
const result = await auth.listUsers();
|
|
439
|
-
expect(result.data).toBeNull();
|
|
440
|
-
expect(result.error?.code).toBe('auth/admin-list-users-failed');
|
|
441
|
-
expect(result.error?.cause).toBe(cause);
|
|
442
|
-
});
|
|
443
|
-
it.each([
|
|
444
|
-
null,
|
|
445
|
-
'not JSON',
|
|
446
|
-
{ users: [{ localId: 'uid', customAttributes: '{' }] },
|
|
447
|
-
{ users: [{}] },
|
|
448
|
-
{ users: 'invalid' }
|
|
449
|
-
])('returns an error for invalid endpoint data %j', async (data) => {
|
|
450
|
-
download.mockResolvedValue({ data, error: null });
|
|
451
|
-
const result = await auth.listUsers();
|
|
452
|
-
expect(result.data).toBeNull();
|
|
453
|
-
expect(result.error?.code).toBe('auth/admin-list-users-failed');
|
|
454
|
-
});
|
|
455
|
-
it('returns unexpected endpoint failures rather than rejecting', async () => {
|
|
456
|
-
const cause = new Error('offline');
|
|
457
|
-
download.mockRejectedValue(cause);
|
|
458
|
-
const result = await auth.listUsers();
|
|
459
|
-
expect(result.data).toBeNull();
|
|
460
|
-
expect(result.error?.cause).toBe(cause);
|
|
461
|
-
});
|
|
462
|
-
it('normalizes unexpected authentication failures', async () => {
|
|
463
|
-
mockedGetToken.mockRejectedValue('token failure');
|
|
464
|
-
const result = await auth.listUsers();
|
|
465
|
-
expect(result.data).toBeNull();
|
|
466
|
-
expect(result.error?.cause).toBeInstanceOf(Error);
|
|
467
|
-
});
|
|
468
|
-
});
|
|
469
|
-
describe('getUser', () => {
|
|
470
|
-
it('returns error when getToken returns an error', async () => {
|
|
471
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
472
|
-
data: null,
|
|
473
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED)
|
|
474
|
-
});
|
|
475
|
-
const result = await auth.getUser('uid-1');
|
|
476
|
-
expect(mockedGetToken).toHaveBeenCalled();
|
|
477
|
-
expect(result.data).toBeNull();
|
|
478
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
479
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED
|
|
480
|
-
.code);
|
|
481
|
-
});
|
|
482
|
-
it('returns error when getToken does not return a token', async () => {
|
|
483
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
484
|
-
data: null,
|
|
485
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED)
|
|
486
|
-
});
|
|
487
|
-
const result = await auth.getUser('uid-1');
|
|
488
|
-
expect(result.data).toBeNull();
|
|
489
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
490
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED
|
|
491
|
-
.code);
|
|
492
|
-
});
|
|
493
|
-
it('returns user when everything succeeds', async () => {
|
|
494
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
495
|
-
data: mockGoogleTokenResponse,
|
|
496
|
-
error: null
|
|
497
|
-
});
|
|
498
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
499
|
-
data: mockUserRecord,
|
|
500
|
-
error: null
|
|
501
|
-
});
|
|
502
|
-
const result = await auth.getUser('uid-1');
|
|
503
|
-
expect(mockedGetToken).toHaveBeenCalledWith(serviceAccountKey, undefined);
|
|
504
|
-
expect(mockedGetAccountInfo).toHaveBeenCalledWith({ uid: 'uid-1' }, 'test-access-token', 'test-project', undefined, undefined);
|
|
505
|
-
expect(result.data).toEqual(mockUserRecord);
|
|
506
|
-
expect(result.error).toBeNull();
|
|
507
|
-
});
|
|
508
|
-
it('returns error when getAccountInfoByUid fails', async () => {
|
|
509
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
510
|
-
data: mockGoogleTokenResponse,
|
|
511
|
-
error: null
|
|
512
|
-
});
|
|
513
|
-
const error = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_USER_NOT_FOUND);
|
|
514
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
515
|
-
data: null,
|
|
516
|
-
error
|
|
517
|
-
});
|
|
518
|
-
const result = await auth.getUser('uid-1');
|
|
519
|
-
expect(result.data).toBeNull();
|
|
520
|
-
expect(result.error).toEqual(error);
|
|
521
|
-
});
|
|
522
|
-
});
|
|
523
|
-
describe('verifyIdToken', () => {
|
|
524
|
-
it('returns error when verifyJWT fails', async () => {
|
|
525
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
526
|
-
data: null,
|
|
527
|
-
error: new Error('bad token')
|
|
528
|
-
});
|
|
529
|
-
const result = await auth.verifyIdToken('id-token');
|
|
530
|
-
expect(mockedVerifyJWT).toHaveBeenCalledWith('id-token', 'test-project', undefined);
|
|
531
|
-
expect(result.data).toBeNull();
|
|
532
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
533
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_ID_TOKEN_VERIFY_FAILED.code);
|
|
534
|
-
});
|
|
535
|
-
it('returns decoded token when not checking revoked', async () => {
|
|
536
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
537
|
-
data: mockFirebasePayload,
|
|
538
|
-
error: null
|
|
539
|
-
});
|
|
540
|
-
const result = await auth.verifyIdToken('id-token', false);
|
|
541
|
-
expect(result.data).toEqual(mockFirebasePayload);
|
|
542
|
-
expect(result.error).toBeNull();
|
|
543
|
-
});
|
|
544
|
-
it('returns error when user lookup fails during revoked check', async () => {
|
|
545
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
546
|
-
data: mockFirebasePayload,
|
|
547
|
-
error: null
|
|
548
|
-
});
|
|
549
|
-
const userError = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_INTERNAL_ERROR);
|
|
550
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
551
|
-
data: mockGoogleTokenResponse,
|
|
552
|
-
error: null
|
|
553
|
-
});
|
|
554
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
555
|
-
data: null,
|
|
556
|
-
error: userError
|
|
557
|
-
});
|
|
558
|
-
const result = await auth.verifyIdToken('id-token', true);
|
|
559
|
-
expect(result.data).toBeNull();
|
|
560
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
561
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_LOOKUP_FAILED.code);
|
|
562
|
-
});
|
|
563
|
-
it('returns ERR_NO_USER when user is null during revoked check', async () => {
|
|
564
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
565
|
-
data: mockFirebasePayload,
|
|
566
|
-
error: null
|
|
567
|
-
});
|
|
568
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
569
|
-
data: mockGoogleTokenResponse,
|
|
570
|
-
error: null
|
|
571
|
-
});
|
|
572
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
573
|
-
data: null,
|
|
574
|
-
error: null
|
|
575
|
-
});
|
|
576
|
-
const result = await auth.verifyIdToken('id-token', true);
|
|
577
|
-
expect(result.data).toBeNull();
|
|
578
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
579
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_RECORD_NOT_FOUND.code);
|
|
580
|
-
});
|
|
581
|
-
it('returns ERR_USER_DISABLED when user.disabled is true', async () => {
|
|
582
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
583
|
-
data: mockFirebasePayload,
|
|
584
|
-
error: null
|
|
585
|
-
});
|
|
586
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
587
|
-
data: mockGoogleTokenResponse,
|
|
588
|
-
error: null
|
|
589
|
-
});
|
|
590
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
591
|
-
data: { ...mockUserRecord, disabled: true },
|
|
592
|
-
error: null
|
|
593
|
-
});
|
|
594
|
-
const result = await auth.verifyIdToken('id-token', true);
|
|
595
|
-
expect(result.data).toBeNull();
|
|
596
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
597
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_DISABLED.code);
|
|
598
|
-
});
|
|
599
|
-
it('returns ERR_TOKEN_REVOKED when auth_time < tokensValidAfterTime', async () => {
|
|
600
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
601
|
-
data: mockFirebasePayload,
|
|
602
|
-
error: null
|
|
603
|
-
});
|
|
604
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
605
|
-
data: mockGoogleTokenResponse,
|
|
606
|
-
error: null
|
|
607
|
-
});
|
|
608
|
-
// tokensValidAfterTime far in the future compared to auth_time
|
|
609
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
610
|
-
data: {
|
|
611
|
-
...mockUserRecord,
|
|
612
|
-
disabled: false,
|
|
613
|
-
validSince: '2000000'
|
|
614
|
-
},
|
|
615
|
-
error: null
|
|
616
|
-
});
|
|
617
|
-
const result = await auth.verifyIdToken('id-token', true);
|
|
618
|
-
expect(result.data).toBeNull();
|
|
619
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
620
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_ID_TOKEN_REVOKED.code);
|
|
621
|
-
});
|
|
622
|
-
it('returns decoded token when not revoked', async () => {
|
|
623
|
-
const mockPayloadWithLaterAuthTime = {
|
|
624
|
-
...mockFirebasePayload,
|
|
625
|
-
auth_time: 2000
|
|
626
|
-
};
|
|
627
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
628
|
-
data: mockPayloadWithLaterAuthTime,
|
|
629
|
-
error: null
|
|
630
|
-
});
|
|
631
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
632
|
-
data: mockGoogleTokenResponse,
|
|
633
|
-
error: null
|
|
634
|
-
});
|
|
635
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
636
|
-
data: {
|
|
637
|
-
...mockUserRecord,
|
|
638
|
-
disabled: false,
|
|
639
|
-
validSince: '1000'
|
|
640
|
-
},
|
|
641
|
-
error: null
|
|
642
|
-
});
|
|
643
|
-
const result = await auth.verifyIdToken('id-token', true);
|
|
644
|
-
expect(result.data).toEqual(mockPayloadWithLaterAuthTime);
|
|
645
|
-
expect(result.error).toBeNull();
|
|
646
|
-
});
|
|
647
|
-
it('returns error when token has no decoded payload', async () => {
|
|
648
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
649
|
-
data: null,
|
|
650
|
-
error: new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_INVALID_ID_TOKEN)
|
|
651
|
-
});
|
|
652
|
-
const result = await auth.verifyIdToken('id-token');
|
|
653
|
-
expect(result.data).toBeNull();
|
|
654
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
655
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_ID_TOKEN_VERIFY_FAILED.code);
|
|
656
|
-
});
|
|
657
|
-
it('returns error when tenant ID does not match', async () => {
|
|
658
|
-
const mockPayloadWithDifferentTenant = {
|
|
659
|
-
...mockFirebasePayload,
|
|
660
|
-
firebase: {
|
|
661
|
-
...mockFirebasePayload.firebase,
|
|
662
|
-
tenant: 'different-tenant-id'
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
666
|
-
data: mockPayloadWithDifferentTenant,
|
|
667
|
-
error: null
|
|
668
|
-
});
|
|
669
|
-
const result = await authWithTenant.verifyIdToken('id-token');
|
|
670
|
-
expect(result.data).toBeNull();
|
|
671
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
672
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_TENANT_ID_INVALID.code);
|
|
673
|
-
});
|
|
674
|
-
it('returns success when tenant ID matches', async () => {
|
|
675
|
-
const mockPayloadWithCorrectTenant = {
|
|
676
|
-
...mockFirebasePayload,
|
|
677
|
-
firebase: {
|
|
678
|
-
...mockFirebasePayload.firebase,
|
|
679
|
-
tenant: 'test-tenant-id'
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
mockedVerifyJWT.mockResolvedValueOnce({
|
|
683
|
-
data: mockPayloadWithCorrectTenant,
|
|
684
|
-
error: null
|
|
685
|
-
});
|
|
686
|
-
const result = await authWithTenant.verifyIdToken('id-token', false);
|
|
687
|
-
expect(result.data).toEqual(mockPayloadWithCorrectTenant);
|
|
688
|
-
expect(result.error).toBeNull();
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
describe('createSessionCookie', () => {
|
|
692
|
-
it('returns error when getToken fails', async () => {
|
|
693
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
694
|
-
data: null,
|
|
695
|
-
error: new Error('unauthorized')
|
|
696
|
-
});
|
|
697
|
-
const result = await auth.createSessionCookie('id-token', 3600);
|
|
698
|
-
expect(result.data).toBeNull();
|
|
699
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
700
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED
|
|
701
|
-
.code);
|
|
702
|
-
});
|
|
703
|
-
it('returns error when token is missing', async () => {
|
|
704
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
705
|
-
data: null,
|
|
706
|
-
error: new FirebaseEdgeError(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED)
|
|
707
|
-
});
|
|
708
|
-
const result = await auth.createSessionCookie('id-token', 3600);
|
|
709
|
-
expect(result.data).toBeNull();
|
|
710
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
711
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SERVICE_ACCOUNT_TOKEN_FAILED
|
|
712
|
-
.code);
|
|
713
|
-
});
|
|
714
|
-
it('returns error when endpoint returns error', async () => {
|
|
715
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
716
|
-
data: mockGoogleTokenResponse,
|
|
717
|
-
error: null
|
|
718
|
-
});
|
|
719
|
-
const endpointError = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_INVALID_ARGUMENT);
|
|
720
|
-
mockedCreateSessionCookieEndpoint.mockResolvedValueOnce({
|
|
721
|
-
data: null,
|
|
722
|
-
error: endpointError
|
|
723
|
-
});
|
|
724
|
-
const result = await auth.createSessionCookie('id-token', 3600);
|
|
725
|
-
expect(mockedCreateSessionCookieEndpoint).toHaveBeenCalledWith('id-token', 'test-access-token', 'test-project', 3600, undefined, undefined);
|
|
726
|
-
expect(result.data).toBeNull();
|
|
727
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
728
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SESSION_COOKIE_CREATE_FAILED
|
|
729
|
-
.code);
|
|
730
|
-
});
|
|
731
|
-
it('returns session cookie data on success', async () => {
|
|
732
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
733
|
-
data: mockGoogleTokenResponse,
|
|
734
|
-
error: null
|
|
735
|
-
});
|
|
736
|
-
const cookieData = 'cookie-value';
|
|
737
|
-
mockedCreateSessionCookieEndpoint.mockResolvedValueOnce({
|
|
738
|
-
data: cookieData,
|
|
739
|
-
error: null
|
|
740
|
-
});
|
|
741
|
-
const result = await auth.createSessionCookie('id-token', 3600);
|
|
742
|
-
expect(result.data).toEqual(cookieData);
|
|
743
|
-
expect(result.error).toBeNull();
|
|
744
|
-
});
|
|
745
|
-
});
|
|
746
|
-
describe('verifySessionCookie', () => {
|
|
747
|
-
it('returns error when verifySessionJWT fails', async () => {
|
|
748
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
749
|
-
data: null,
|
|
750
|
-
error: new Error('bad session token')
|
|
751
|
-
});
|
|
752
|
-
const result = await auth.verifySessionCookie('session-cookie');
|
|
753
|
-
expect(result.data).toBeNull();
|
|
754
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
755
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SESSION_COOKIE_VERIFY_FAILED
|
|
756
|
-
.code);
|
|
757
|
-
});
|
|
758
|
-
it('returns data when not checking revoked', async () => {
|
|
759
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
760
|
-
data: mockFirebasePayload,
|
|
761
|
-
error: null
|
|
762
|
-
});
|
|
763
|
-
const result = await auth.verifySessionCookie('session-cookie', false);
|
|
764
|
-
expect(result.data).toEqual(mockFirebasePayload);
|
|
765
|
-
expect(result.error).toBeNull();
|
|
766
|
-
});
|
|
767
|
-
it('returns error when user lookup fails during revoked check', async () => {
|
|
768
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
769
|
-
data: mockFirebasePayload,
|
|
770
|
-
error: null
|
|
771
|
-
});
|
|
772
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
773
|
-
data: mockGoogleTokenResponse,
|
|
774
|
-
error: null
|
|
775
|
-
});
|
|
776
|
-
const error = new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_INTERNAL_ERROR);
|
|
777
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
778
|
-
data: null,
|
|
779
|
-
error
|
|
780
|
-
});
|
|
781
|
-
const result = await auth.verifySessionCookie('session-cookie', true);
|
|
782
|
-
expect(result.data).toBeNull();
|
|
783
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
784
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_LOOKUP_FAILED.code);
|
|
785
|
-
});
|
|
786
|
-
it('returns ERR_NO_USER when user is null during revoked check', async () => {
|
|
787
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
788
|
-
data: mockFirebasePayload,
|
|
789
|
-
error: null
|
|
790
|
-
});
|
|
791
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
792
|
-
data: mockGoogleTokenResponse,
|
|
793
|
-
error: null
|
|
794
|
-
});
|
|
795
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
796
|
-
data: null,
|
|
797
|
-
error: null
|
|
798
|
-
});
|
|
799
|
-
const result = await auth.verifySessionCookie('session-cookie', true);
|
|
800
|
-
expect(result.data).toBeNull();
|
|
801
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
802
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_USER_RECORD_NOT_FOUND.code);
|
|
803
|
-
});
|
|
804
|
-
it('returns decoded data when revoked check passes', async () => {
|
|
805
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
806
|
-
data: mockFirebasePayload,
|
|
807
|
-
error: null
|
|
808
|
-
});
|
|
809
|
-
mockedGetToken.mockResolvedValueOnce({
|
|
810
|
-
data: mockGoogleTokenResponse,
|
|
811
|
-
error: null
|
|
812
|
-
});
|
|
813
|
-
mockedGetAccountInfo.mockResolvedValueOnce({
|
|
814
|
-
data: mockUserRecord,
|
|
815
|
-
error: null
|
|
816
|
-
});
|
|
817
|
-
const result = await auth.verifySessionCookie('session-cookie', true);
|
|
818
|
-
expect(result.data).toEqual(mockFirebasePayload);
|
|
819
|
-
expect(result.error).toBeNull();
|
|
820
|
-
});
|
|
821
|
-
it('returns error when no decoded data returned', async () => {
|
|
822
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
823
|
-
data: null,
|
|
824
|
-
error: new FirebaseEdgeError(FirebaseEndpointErrorInfo.ENDPOINT_INVALID_SESSION_COOKIE)
|
|
825
|
-
});
|
|
826
|
-
const result = await auth.verifySessionCookie('session-cookie');
|
|
827
|
-
expect(result.data).toBeNull();
|
|
828
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
829
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_SESSION_COOKIE_VERIFY_FAILED
|
|
830
|
-
.code);
|
|
831
|
-
});
|
|
832
|
-
it('returns error when tenant ID does not match', async () => {
|
|
833
|
-
const mockPayloadWithDifferentTenant = {
|
|
834
|
-
...mockFirebasePayload,
|
|
835
|
-
firebase: {
|
|
836
|
-
...mockFirebasePayload.firebase,
|
|
837
|
-
tenant: 'wrong-tenant-id'
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
841
|
-
data: mockPayloadWithDifferentTenant,
|
|
842
|
-
error: null
|
|
843
|
-
});
|
|
844
|
-
const result = await authWithTenant.verifySessionCookie('session-cookie');
|
|
845
|
-
expect(result.data).toBeNull();
|
|
846
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
847
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_TENANT_ID_INVALID.code);
|
|
848
|
-
});
|
|
849
|
-
it('returns success when tenant ID matches', async () => {
|
|
850
|
-
const mockPayloadWithCorrectTenant = {
|
|
851
|
-
...mockFirebasePayload,
|
|
852
|
-
firebase: {
|
|
853
|
-
...mockFirebasePayload.firebase,
|
|
854
|
-
tenant: 'test-tenant-id'
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
mockedVerifySessionJWT.mockResolvedValueOnce({
|
|
858
|
-
data: mockPayloadWithCorrectTenant,
|
|
859
|
-
error: null
|
|
860
|
-
});
|
|
861
|
-
const result = await authWithTenant.verifySessionCookie('session-cookie', false);
|
|
862
|
-
expect(result.data).toEqual(mockPayloadWithCorrectTenant);
|
|
863
|
-
expect(result.error).toBeNull();
|
|
864
|
-
});
|
|
865
|
-
});
|
|
866
|
-
describe('createCustomToken', () => {
|
|
867
|
-
it('returns error when signJWTCustomToken fails', async () => {
|
|
868
|
-
mockedSignJWTCustomToken.mockResolvedValueOnce({
|
|
869
|
-
data: null,
|
|
870
|
-
error: new Error('sign failed')
|
|
871
|
-
});
|
|
872
|
-
const result = await auth.createCustomToken('uid-1');
|
|
873
|
-
expect(mockedSignJWTCustomToken).toHaveBeenCalledWith('uid-1', serviceAccountKey, {});
|
|
874
|
-
expect(result.data).toBeNull();
|
|
875
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
876
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_CUSTOM_TOKEN_CREATE_FAILED.code);
|
|
877
|
-
});
|
|
878
|
-
it('returns error when no data is returned', async () => {
|
|
879
|
-
mockedSignJWTCustomToken.mockResolvedValueOnce({
|
|
880
|
-
data: null,
|
|
881
|
-
error: new FirebaseEdgeError(JWTErrorInfo.JWT_UNKNOWN_SIGNING_ERROR)
|
|
882
|
-
});
|
|
883
|
-
const result = await auth.createCustomToken('uid-1');
|
|
884
|
-
expect(result.data).toBeNull();
|
|
885
|
-
expect(result.error).toBeInstanceOf(FirebaseEdgeError);
|
|
886
|
-
expect(result.error.code).toBe(FirebaseAdminAuthErrorInfo.ADMIN_CUSTOM_TOKEN_CREATE_FAILED.code);
|
|
887
|
-
});
|
|
888
|
-
it('returns token when successful', async () => {
|
|
889
|
-
mockedSignJWTCustomToken.mockResolvedValueOnce({
|
|
890
|
-
data: 'custom-token',
|
|
891
|
-
error: null
|
|
892
|
-
});
|
|
893
|
-
const claims = { role: 'admin' };
|
|
894
|
-
const result = await auth.createCustomToken('uid-1', claims);
|
|
895
|
-
expect(mockedSignJWTCustomToken).toHaveBeenCalledWith('uid-1', serviceAccountKey, claims);
|
|
896
|
-
expect(result.data).toBe('custom-token');
|
|
897
|
-
expect(result.error).toBeNull();
|
|
898
|
-
});
|
|
899
|
-
it('includes tenant_id claim when tenant is specified', async () => {
|
|
900
|
-
mockedSignJWTCustomToken.mockResolvedValueOnce({
|
|
901
|
-
data: 'custom-token-with-tenant',
|
|
902
|
-
error: null
|
|
903
|
-
});
|
|
904
|
-
const claims = { role: 'admin' };
|
|
905
|
-
const result = await authWithTenant.createCustomToken('uid-1', claims);
|
|
906
|
-
expect(mockedSignJWTCustomToken).toHaveBeenCalledWith('uid-1', serviceAccountKey, { ...claims, tenant_id: 'test-tenant-id' });
|
|
907
|
-
expect(result.data).toBe('custom-token-with-tenant');
|
|
908
|
-
expect(result.error).toBeNull();
|
|
909
|
-
});
|
|
910
|
-
it('does not add tenant_id when no tenant specified', async () => {
|
|
911
|
-
mockedSignJWTCustomToken.mockResolvedValueOnce({
|
|
912
|
-
data: 'custom-token',
|
|
913
|
-
error: null
|
|
914
|
-
});
|
|
915
|
-
const claims = { role: 'user' };
|
|
916
|
-
const result = await auth.createCustomToken('uid-1', claims);
|
|
917
|
-
expect(mockedSignJWTCustomToken).toHaveBeenCalledWith('uid-1', serviceAccountKey, claims);
|
|
918
|
-
expect(result.data).toBe('custom-token');
|
|
919
|
-
expect(result.error).toBeNull();
|
|
920
|
-
});
|
|
921
|
-
});
|
|
922
|
-
});
|
|
923
|
-
//# sourceMappingURL=firebase-admin-auth.test.js.map
|