| 1 |
package e2e_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/url" |
| 5 |
"time" |
| 6 |
|
| 7 |
"github.com/onsi/ginkgo/v2" |
| 8 |
"github.com/onsi/gomega" |
| 9 |
|
| 10 |
"github.com/nicholas-fedor/shoutrrr/internal/testutils" |
| 11 |
"github.com/nicholas-fedor/shoutrrr/pkg/services/chat/xmpp" |
| 12 |
) |
| 13 |
|
| 14 |
var _ = ginkgo.Describe("XMPP E2E", func() { |
| 15 |
sendURL := func(rawURL, message string) { |
| 16 |
ginkgo.GinkgoHelper() |
| 17 |
|
| 18 |
serviceURL, err := url.Parse(rawURL) |
| 19 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 20 |
|
| 21 |
probe, err := startInbox(serviceURL) |
| 22 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 23 |
|
| 24 |
defer probe.close() |
| 25 |
|
| 26 |
service := &xmpp.Service{} |
| 27 |
err = service.Initialize(serviceURL, testutils.TestLogger()) |
| 28 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 29 |
gomega.Expect(service.Send(message, nil)).To(gomega.Succeed()) |
| 30 |
gomega.Eventually(probe.bodies). |
| 31 |
WithTimeout(5 * time.Second). |
| 32 |
Should(gomega.Receive(gomega.Equal(message))) |
| 33 |
} |
| 34 |
|
| 35 |
ginkgo.It("should send a 1:1 chat over STARTTLS", func() { |
| 36 |
sendURL(envOrSkip("SHOUTRRR_XMPP_URL"), "E2E Test: STARTTLS chat") |
| 37 |
}) |
| 38 |
|
| 39 |
ginkgo.It("should send a 1:1 chat over implicit TLS", func() { |
| 40 |
sendURL(envOrSkip("SHOUTRRR_XMPP_TLS_URL"), "E2E Test: implicit TLS chat") |
| 41 |
}) |
| 42 |
|
| 43 |
ginkgo.It("should send a 1:1 chat over plaintext when disabletls is set", func() { |
| 44 |
sendURL(envOrSkip("SHOUTRRR_XMPP_PLAIN_URL"), "E2E Test: plaintext chat") |
| 45 |
}) |
| 46 |
|
| 47 |
ginkgo.It("should send to an open MUC", func() { |
| 48 |
sendURL(envOrSkip("SHOUTRRR_XMPP_MUC_URL"), "E2E Test: open MUC") |
| 49 |
}) |
| 50 |
|
| 51 |
ginkgo.It("should send to a password-protected MUC", func() { |
| 52 |
sendURL(envOrSkip("SHOUTRRR_XMPP_MUC_PASSWORD_URL"), "E2E Test: protected MUC") |
| 53 |
}) |
| 54 |
|
| 55 |
ginkgo.It("should fail with bad credentials", func() { |
| 56 |
rawURL := envOrSkip("SHOUTRRR_XMPP_URL") |
| 57 |
serviceURL, err := url.Parse(rawURL) |
| 58 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 59 |
|
| 60 |
serviceURL.User = url.UserPassword("sender", "wrong-password") |
| 61 |
|
| 62 |
service := &xmpp.Service{} |
| 63 |
err = service.Initialize(serviceURL, testutils.TestLogger()) |
| 64 |
gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 65 |
gomega.Expect(service.Send("should fail", nil)).To(gomega.MatchError(xmpp.ErrAuthenticationFailed)) |
| 66 |
}) |
| 67 |
}) |