-
Notifications
You must be signed in to change notification settings - Fork 140
fix: surface SMTP failures from gmail share endpoint to UI #5164
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
Merged
mengw15
merged 9 commits into
apache:main
from
mengw15:fix/5161-gmail-share-error-feedback
May 24, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ba9d0b5
fix: surface SMTP failures from gmail share endpoint to UI
mengw15 fe9290d
Merge branch 'main' into fix/5161-gmail-share-error-feedback
mengw15 2988313
Merge branch 'main' into fix/5161-gmail-share-error-feedback
mengw15 58f651d
fix: return 400 BadRequest for invalid email format
mengw15 315dbf8
test: add GmailResourceSpec covering invalid-email → 400
mengw15 c374d18
test: cover 502 SMTP-failure branch in GmailResourceSpec
mengw15 b0346e4
Merge branch 'main' into fix/5161-gmail-share-error-feedback
mengw15 ac749e1
Merge branch 'main' into fix/5161-gmail-share-error-feedback
mengw15 c83723f
Merge branch 'main' into fix/5161-gmail-share-error-feedback
mengw15 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
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
amber/src/test/scala/org/apache/texera/web/resource/GmailResourceSpec.scala
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.texera.web.resource | ||
|
|
||
| import org.apache.texera.auth.SessionUser | ||
| import org.apache.texera.dao.jooq.generated.enums.UserRoleEnum | ||
| import org.apache.texera.dao.jooq.generated.tables.pojos.User | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
|
|
||
| import javax.ws.rs.{BadRequestException, WebApplicationException} | ||
|
|
||
| class GmailResourceSpec extends AnyFlatSpec { | ||
|
|
||
| private def newSessionUser(): SessionUser = { | ||
| val user = new User | ||
| user.setUid(Integer.valueOf(1)) | ||
| user.setName("test") | ||
| user.setRole(UserRoleEnum.REGULAR) | ||
| user.setEmail("test@example.com") | ||
| new SessionUser(user) | ||
| } | ||
|
|
||
| it should "throw BadRequestException (HTTP 400) when the receiver fails email-format validation" in { | ||
| val resource = new GmailResource() | ||
| val msg = EmailMessage( | ||
| receiver = "not-a-valid-email", | ||
| subject = "subj", | ||
| content = "body" | ||
| ) | ||
| val ex = intercept[BadRequestException] { | ||
| resource.sendEmailRequest(msg, newSessionUser()) | ||
| } | ||
| assert(ex.getResponse.getStatus == 400) | ||
| } | ||
|
|
||
| it should "throw WebApplicationException with HTTP 502 when sendEmail fails for a non-validation reason" in { | ||
| // In the test environment `UserSystemConfig.gmail` defaults to "", so | ||
| // `createMimeMessage`'s `new InternetAddress(senderGmail)` raises an | ||
| // `AddressException` deterministically — without any network or SMTP | ||
| // server contact — and `sendEmail` returns `Left("Failed to send email: | ||
| // ...")`. The resource then maps that `Left` to a 502 BadGateway. | ||
| val resource = new GmailResource() | ||
| val msg = EmailMessage( | ||
| receiver = "valid@example.com", | ||
| subject = "subj", | ||
| content = "body" | ||
| ) | ||
| val ex = intercept[WebApplicationException] { | ||
| resource.sendEmailRequest(msg, newSessionUser()) | ||
| } | ||
| assert( | ||
| !ex.isInstanceOf[BadRequestException], | ||
| s"expected non-validation failure, but got BadRequestException: ${ex.getMessage}" | ||
| ) | ||
| assert(ex.getResponse.getStatus == 502) | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
frontend/src/app/common/service/gmail/gmail.service.spec.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { TestBed } from "@angular/core/testing"; | ||
| import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing"; | ||
| import { GmailService } from "./gmail.service"; | ||
| import { NotificationService } from "../notification/notification.service"; | ||
|
|
||
| describe("GmailService", () => { | ||
| let service: GmailService; | ||
| let httpTestingController: HttpTestingController; | ||
| let notificationSpy: { success: ReturnType<typeof vi.fn>; error: ReturnType<typeof vi.fn> }; | ||
|
|
||
| beforeEach(() => { | ||
| notificationSpy = { success: vi.fn(), error: vi.fn() }; | ||
| TestBed.configureTestingModule({ | ||
| imports: [HttpClientTestingModule], | ||
| providers: [GmailService, { provide: NotificationService, useValue: notificationSpy }], | ||
| }); | ||
| service = TestBed.inject(GmailService); | ||
| httpTestingController = TestBed.inject(HttpTestingController); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| httpTestingController.verify(); | ||
| }); | ||
|
|
||
| it("should show a success toast when the backend accepts the send request", () => { | ||
| service.sendEmail("subj", "body", "to@example.com"); | ||
|
|
||
| const req = httpTestingController.expectOne(r => r.url.endsWith("/gmail/send") && r.method === "PUT"); | ||
| req.flush(null); | ||
|
|
||
| expect(notificationSpy.success).toHaveBeenCalledWith("Email sent successfully"); | ||
| expect(notificationSpy.error).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should show an error toast when the backend returns an HTTP error (e.g. SMTP failure)", () => { | ||
| service.sendEmail("subj", "body", "to@example.com"); | ||
|
|
||
| const req = httpTestingController.expectOne(r => r.url.endsWith("/gmail/send") && r.method === "PUT"); | ||
| req.flush("Failed to send email: 535-5.7.8 Username and Password not accepted", { | ||
| status: 502, | ||
| statusText: "Bad Gateway", | ||
| }); | ||
|
|
||
| expect(notificationSpy.error).toHaveBeenCalledWith("Failed to send email. Please try again or contact admin."); | ||
| expect(notificationSpy.success).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.