-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add support for SendGrid categories and streamline SendGrid detection #2245
Open
Gustolandia
wants to merge
1
commit into
next
Choose a base branch
from
@invertase/Extensions/firestore-send-email/2053
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,434
−1,516
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
776 changes: 603 additions & 173 deletions
776
firestore-bigquery-export/functions/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
firestore-bigquery-export/scripts/gen-schema-view/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Mail = require("nodemailer/lib/mailer"); | ||
const { logger } = require("firebase-functions"); | ||
|
||
import { setSmtpCredentials } from "../src/helpers"; | ||
import { setSmtpCredentials, isSendGrid } from "../src/helpers"; | ||
import { Config } from "../src/types"; | ||
|
||
const consoleLogSpy = jest.spyOn(logger, "warn").mockImplementation(); | ||
|
@@ -11,7 +11,7 @@ const regex = new RegExp( | |
"^(smtp[s]*://(.*?(:[^:@]*)?@)?[^:@]+:[0-9]+(\\?[^ ]*)?)$" | ||
); | ||
|
||
describe("set server credentials helper function", () => { | ||
describe("setSmtpCredentials function", () => { | ||
test("return smtpServerDomain credentials with new password", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
|
@@ -32,26 +32,7 @@ describe("set server credentials helper function", () => { | |
expect(regex.test(config.smtpConnectionUri)).toBe(true); | ||
}); | ||
|
||
test("return smtpServerDomain credentials with new password (old deleted)", () => { | ||
const config: Config = { | ||
smtpConnectionUri: "smtps://fakeemail@gmail.com@smtp.gmail.com:465", | ||
smtpPassword: "sec#:@ret-password", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
const credentials = setSmtpCredentials(config); | ||
expect(credentials).toBeInstanceOf(Mail); | ||
expect(credentials.options.port).toBe(465); | ||
expect(credentials.options.host).toBe("smtp.gmail.com"); | ||
expect(credentials.options.auth.pass).toBe(config.smtpPassword); | ||
expect(credentials.options.secure).toBe(true); | ||
|
||
// The regex should match the smtpConnectionUri, it should be valid | ||
expect(regex.test(config.smtpConnectionUri)).toBe(true); | ||
}); | ||
|
||
test("return smtpConnectionUri credentials with old password", () => { | ||
test("return smtpServerDomain credentials with old password", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
"smtps://fakeemail@gmail.com:secret-password@smtp.gmail.com:465", | ||
|
@@ -130,7 +111,7 @@ describe("set server credentials helper function", () => { | |
expect(regex.test(config.smtpConnectionUri)).toBe(true); | ||
}); | ||
|
||
test("return valid smtpConnectionUri credentials with special chars in password config", () => { | ||
test("return valid smtpConnectionUri credentials with valid special chars in password", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
"smtp://fakeemail@gmail.com@smtp.gmail.com:465?pool=true&service=gmail", | ||
|
@@ -153,30 +134,7 @@ describe("set server credentials helper function", () => { | |
expect(regex.test(config.smtpConnectionUri)).toBe(true); | ||
}); | ||
|
||
test("return valid smtpConnectionUri credentials with valid special chars in connectionUri password", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
"smtp://fakeemail@gmail.com:4,hdhuNTbv9zMrP4&7&7%*3@smtp.gmail.com:465?pool=true&service=gmail", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
const credentials = setSmtpCredentials(config); | ||
|
||
expect(credentials).toBeInstanceOf(Mail); | ||
expect(credentials.options.port).toBe(465); | ||
expect(credentials.options.host).toBe("smtp.gmail.com"); | ||
expect(credentials.options.auth.user).toBe("fakeemail@gmail.com"); | ||
expect(credentials.options.auth.pass).toBe("4,hdhuNTbv9zMrP4&7&7%*3"); | ||
expect(credentials.options.secure).toBe(false); | ||
expect(credentials.options.pool).toBe(true); | ||
expect(credentials.options.service).toBe("gmail"); | ||
|
||
// The regex should match the smtpConnectionUri, it should be valid | ||
expect(regex.test(config.smtpConnectionUri)).toBe(true); | ||
}); | ||
|
||
test("return invalid smtpConnectionUri credentials with invalid special chars in connectionUri password", () => { | ||
test("throw error for invalid smtpConnectionUri", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
"smtp://fakeemail@gmail.com:4,h?dhuNTbv9zMrP4&7&7%*3@smtp.gmail.com:465?pool=true&service=gmail", | ||
|
@@ -185,48 +143,52 @@ describe("set server credentials helper function", () => { | |
defaultFrom: "", | ||
}; | ||
|
||
// Expect an error to be thrown | ||
expect(() => setSmtpCredentials(config)).toThrow(Error); | ||
|
||
expect(consoleLogSpy).toBeCalledWith( | ||
"Invalid URI: please reconfigure with a valid SMTP connection URI" | ||
); | ||
}); | ||
test("return valid smtpConnectionUri credentials with correct seprator", () => { | ||
}); | ||
|
||
describe("isSendGrid function", () => { | ||
test("return true for SendGrid SMTP URI", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
"smtp://fakeemail@gmail.com:4,h?dhuNTbv9zMrP4&7&7%*3@smtp.gmail.com:465?pool=true&service=gmail", | ||
smtpConnectionUri: "smtps://apikey@smtp.sendgrid.net:465", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
|
||
expect(regex.test(config.smtpConnectionUri)).toBe(true); | ||
expect(isSendGrid(config)).toBe(true); | ||
}); | ||
|
||
test("return invalid smtpConnectionUri credentials with invalid seprator", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should keep this test |
||
test("return false for non-SendGrid SMTP URI", () => { | ||
const config: Config = { | ||
smtpConnectionUri: | ||
"smtp://fakeemail@gmail.com:4,h?dhuNTbv9zMrP4&7&7%*3:smtp.gmail.com:465?pool=true&service=gmail", | ||
"smtps://fakeemail@gmail.com:secret-password@smtp.gmail.com:465", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
|
||
expect(regex.test(config.smtpConnectionUri)).toBe(false); | ||
expect(isSendGrid(config)).toBe(false); | ||
}); | ||
}); | ||
|
||
/* Test removed due to the new SendGrid transporter logic - see setSendGridTransport() | ||
test("return a SendGrid transporter if the host is smtp.sendgrid.net", () => { | ||
const config: Config = { | ||
smtpConnectionUri: "smtps://apikey@smtp.sendgrid.net:465", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
|
||
const credentials = setSmtpCredentials(config); | ||
expect(credentials.transporter.name === "nodemailer-sendgrid").toBe(true); | ||
}); | ||
*/ | ||
test("correctly detects SendGrid SMTP URI", () => { | ||
const config: Config = { | ||
smtpConnectionUri: "smtps://apikey@smtp.sendgrid.net:465", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
expect(isSendGrid(config)).toBe(true); | ||
|
||
const invalidConfig: Config = { | ||
smtpConnectionUri: "smtps://apikey@fake-sendgrid.net:465", | ||
location: "", | ||
mailCollection: "", | ||
defaultFrom: "", | ||
}; | ||
expect(isSendGrid(invalidConfig)).toBe(false); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this test is removed?