| 218 | } |
| 219 | |
| 220 | func TestAuth(t *testing.T) { |
| 221 | t.Parallel() |
| 222 | |
| 223 | cases := []struct { |
| 224 | name string |
| 225 | cfg func() *model.ConfigConfig |
| 226 | useTlS bool |
| 227 | exposePort uint |
| 228 | expected func() *Service |
| 229 | }{ |
| 230 | { |
| 231 | name: "default", |
| 232 | cfg: getConfig, |
| 233 | useTlS: true, |
| 234 | exposePort: 0, |
| 235 | expected: expectedAuth, |
| 236 | }, |
| 237 | { |
| 238 | name: "pre-0.22.0", |
| 239 | cfg: func() *model.ConfigConfig { |
| 240 | cfg := getConfig() |
| 241 | cfg.Auth.Version = new("0.21.3") |
| 242 | |
| 243 | return cfg |
| 244 | }, |
| 245 | useTlS: true, |
| 246 | exposePort: 0, |
| 247 | expected: func() *Service { |
| 248 | svc := expectedAuth() |
| 249 | svc.Image = "nhost/auth:0.21.3" |
| 250 | svc.Labels["traefik.http.middlewares.replace-auth.replacepathregex.regex"] = "/v1(/|$$)(.*)" |
| 251 | svc.Labels["traefik.http.middlewares.replace-auth.replacepathregex.replacement"] = "/$$2" |
| 252 | svc.Labels["traefik.http.routers.auth.middlewares"] = "replace-auth" |
| 253 | svc.Labels["traefik.http.routers.auth.rule"] = "(HostRegexp(`^.+\\.auth\\.local\\.nhost\\.run$`) || Host(`local.auth.nhost.run`)) && PathPrefix(`/v1`)" |
| 254 | svc.Environment["HASURA_GRAPHQL_DATABASE_URL"] = "postgres://nhost_auth_admin@postgres:5432/local" |
| 255 | |
| 256 | return svc |
| 257 | }, |
| 258 | }, |
| 259 | { |
| 260 | name: "custom port", |
| 261 | cfg: getConfig, |
| 262 | useTlS: true, |
| 263 | exposePort: 8080, |
| 264 | expected: func() *Service { |
| 265 | svc := expectedAuth() |
| 266 | |
| 267 | svc.Environment["AUTH_SERVER_URL"] = "http://dev.auth.local.nhost.run:8080/v1" |
| 268 | svc.Ports = []Port{ |
| 269 | { |
| 270 | Mode: "ingress", |
| 271 | Target: 4000, |
| 272 | Published: "8080", |
| 273 | Protocol: "tcp", |
| 274 | }, |
| 275 | } |
| 276 | |
| 277 | return svc |