Debian Codegraph @

testing/integration/matrix/auth_test.go

raw symbols SCIP
1 package matrix_testscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/
2
3 import (
4 "net/urlscip-go gomod github.com/golang/go/src . `net/url`/"
5 "testingscip-go gomod github.com/golang/go/src . testing/"
6
7 "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/"
8
9 "github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/"
10 )
11
12 // TestServiceInitializeWithTokenOnly tests the token-only authentication flow.
13 // This tests the URL format matrix://:[email protected] where
14 // the username is empty and the password is the access token.
15 // We test via Config directly to avoid network calls.
16 func TestServiceInitializeWithTokenOnlyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceInitializeWithTokenOnly().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
17 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
18
19 tests := []struct {
20 name string
21 serviceURL string
22 wantUser string
23 wantPass string
24 }{
25 {
26 name: "token-only auth with access token",
27 serviceURL: "matrix://:[email protected]",
28 wantUser: "",
29 wantPass: "syt_xxx_token",
30 },
31 {
32 name: "token-only auth with longer token",
33 serviceURL: "matrix://:[email protected]",
34 wantUser: "",
35 wantPass: "syt_1234567890abcdefghijklmnopqrstuvwxyz",
36 },
37 {
38 name: "token-only auth with special chars in token",
39 serviceURL: "matrix://:[email protected]",
40 wantUser: "",
41 wantPass: "syt_test-token_123",
42 },
43 }
44
45 for _, tt := range tests {
46 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
47 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
48
49 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL)
50 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "URL should be parseable for %s", tt.name)
51
52 // Use Config directly to avoid network calls
53 config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{}
54 err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL)
55
56 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Expected no error for %s", tt.name)
57 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.wantUser, config.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User.,
58 "User should be empty for token-only auth in %s", tt.name)
59 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.wantPass, config.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password.,
60 "Password should be set to token for %s", tt.name)
61 })
62 }
63 }
64
65 // TestServiceInitializeWithUserAndToken tests that when both user and token
66 // are provided via config (not via service), the config is set correctly.
67 func TestServiceInitializeWithUserAndTokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceInitializeWithUserAndToken().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
68 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
69
70 tests := []struct {
71 name string
72 serviceURL string
73 wantUser string
74 wantPass string
75 }{
76 {
77 name: "user and token provided",
78 serviceURL: "matrix://user:[email protected]",
79 wantUser: "user",
80 wantPass: "syt_xxx",
81 },
82 {
83 name: "user with token as password",
84 serviceURL: "matrix://myuser:[email protected]",
85 wantUser: "myuser",
86 wantPass: "$ecret_t0k3n",
87 },
88 }
89
90 for _, tt := range tests {
91 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
92 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
93
94 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL)
95 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "URL should be parseable for %s", tt.name)
96
97 // Use Config directly to avoid network calls
98 config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{}
99 err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL)
100
101 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Expected no error for %s", tt.name)
102 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.wantUser, config.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User.,
103 "User mismatch for %s", tt.name)
104 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.wantPass, config.Passwordscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Password.,
105 "Password mismatch for %s", tt.name)
106 })
107 }
108 }
109
110 // TestServiceInitializeTokenOnlyWithRooms tests token-only auth with room configuration.
111 // Rooms are set directly on the config struct, not via URL params (since URL only supports one room).
112 func TestServiceInitializeTokenOnlyWithRoomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/testing/integration/matrix_test`/TestServiceInitializeTokenOnlyWithRooms().(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
113 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
114
115 tests := []struct {
116 name string
117 serviceURL string
118 rooms []string
119 expectedRooms []string
120 }{
121 {
122 name: "token-only with room set directly",
123 serviceURL: "matrix://:[email protected]",
124 rooms: []string{"#test:example.com"},
125 expectedRooms: []string{"#test:example.com"},
126 },
127 {
128 name: "token-only with multiple rooms set directly",
129 serviceURL: "matrix://:[email protected]",
130 rooms: []string{"#room1:example.com", "#room2:example.com"},
131 expectedRooms: []string{"#room1:example.com", "#room2:example.com"},
132 },
133 }
134
135 for _, tt := range tests {
136 t.Runscip-go gomod github.com/golang/go/src . testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src . testing/.Tscip-go gomod github.com/golang/go/src . testing/T#) {
137 t.Parallelscip-go gomod github.com/golang/go/src . testing/T#Parallel().()
138
139 parsedURL, err := urlscip-go gomod github.com/golang/go/src . `net/url`/.Parsescip-go gomod github.com/golang/go/src . `net/url`/Parse().(tt.serviceURL)
140 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "URL should be parseable for %s", tt.name)
141
142 // Set rooms directly on config
143 config := &matrixscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/.Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#{
144 Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms.: tt.rooms,
145 }
146 err = config.SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#SetURL().(parsedURL)
147
148 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/NoError().(t, err, "Expected no error for %s", tt.name)
149 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Emptyscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Empty().(t, config.Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#User.,
150 "User should be empty for token-only auth in %s", tt.name)
151 requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, tt.expectedRooms, config.Roomsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/matrix`/Config#Rooms.,
152 "Rooms mismatch for %s", tt.name)
153 })
154 }
155 }