Debian Codegraph @

testing/e2e/ntfy/authentication_test.go

raw
1 package e2e_test
2
3 import (
4 "os"
5
6 "github.com/onsi/ginkgo/v2"
7 "github.com/onsi/gomega"
8
9 "github.com/nicholas-fedor/shoutrrr/pkg/services/push/ntfy"
10 )
11
12 var _ = ginkgo.Describe("ntfy E2E Authentication Tests", func() {
13 ginkgo.When("running e2e tests against a real ntfy server", func() {
14 ginkgo.BeforeEach(func() {
15 if !isNtfyServerAvailable() {
16 ginkgo.Skip("ntfy server not available, skipping e2e tests")
17 }
18 })
19
20 ginkgo.It("should send a message with basic authentication", func() {
21 username := os.Getenv("SHOUTRRR_NTFY_USERNAME")
22 password := os.Getenv("SHOUTRRR_NTFY_PASSWORD")
23
24 if username == "" || password == "" {
25 ginkgo.Skip("ntfy credentials not configured, skipping auth test")
26 }
27
28 serviceURLStr := buildServiceURL()
29 service := initializeService(serviceURLStr)
30
31 topic := service.Config.Topic
32 message := "E2E Test: Authenticated message"
33
34 gomega.Expect(service.Send(message, nil)).NotTo(gomega.HaveOccurred())
35
36 verifyMessageReceived(topic, message)
37 })
38
39 ginkgo.It("should send a message with username-only authentication", func() {
40 username := os.Getenv("SHOUTRRR_NTFY_USERNAME")
41 password := os.Getenv("SHOUTRRR_NTFY_PASSWORD")
42
43 if username == "" || password != "" {
44 ginkgo.Skip("username-only auth not configured, skipping test")
45 }
46
47 serviceURLStr := buildServiceURL()
48 service := initializeService(serviceURLStr)
49
50 topic := service.Config.Topic
51 message := "E2E Test: Username-only auth message"
52
53 gomega.Expect(service.Send(message, nil)).NotTo(gomega.HaveOccurred())
54
55 verifyMessageReceived(topic, message)
56 })
57 })
58
59 ginkgo.When("no server is configured", func() {
60 ginkgo.It("should return the correct service ID", func() {
61 service := &ntfy.Service{}
62 gomega.Expect(service.GetID()).To(gomega.Equal("ntfy"))
63 })
64 })
65 })