routes_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. import (
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. )
  9. func TestIsStaticAssetRoute(t *testing.T) {
  10. scenarios := []struct {
  11. path string
  12. expected bool
  13. }{
  14. {"/favicon.ico", true},
  15. {"/robots.txt", true},
  16. {"/stylesheets/checksum/light_serif.css", true},
  17. {"/js/checksum/app.js", true},
  18. {"/icon/checksum/icon-120.png", true},
  19. {"/feed-icon/external-id", true},
  20. {"/proxy/digest/url", true},
  21. {"/", false},
  22. {"/login", false},
  23. {"/manifest.json", false},
  24. {"/share/code", false},
  25. {"/unread", false},
  26. }
  27. for _, scenario := range scenarios {
  28. r := httptest.NewRequest(http.MethodGet, scenario.path, nil)
  29. if result := isStaticAssetRoute(r); result != scenario.expected {
  30. t.Errorf(`Unexpected result for %q, got %v instead of %v`, scenario.path, result, scenario.expected)
  31. }
  32. }
  33. }
  34. func TestIsSessionStartRoute(t *testing.T) {
  35. scenarios := []struct {
  36. name string
  37. env map[string]string
  38. method string
  39. path string
  40. expected bool
  41. }{
  42. {"login page", nil, http.MethodGet, "/", true},
  43. {"login page head", nil, http.MethodHead, "/", true},
  44. {"login page post", nil, http.MethodPost, "/", false},
  45. {"login form submission", nil, http.MethodPost, "/login", false},
  46. {"shared entry", nil, http.MethodGet, "/share/code", false},
  47. {"web manifest", nil, http.MethodGet, "/manifest.json", false},
  48. {"offline page", nil, http.MethodGet, "/offline", false},
  49. {"webauthn begin disabled", nil, http.MethodGet, "/webauthn/login/begin", false},
  50. {"webauthn begin enabled", map[string]string{"WEBAUTHN": "1"}, http.MethodGet, "/webauthn/login/begin", true},
  51. {"webauthn finish", map[string]string{"WEBAUTHN": "1"}, http.MethodPost, "/webauthn/login/finish", false},
  52. {"oauth2 redirect disabled", nil, http.MethodGet, "/oauth2/google/redirect", false},
  53. {"oauth2 redirect enabled", map[string]string{"OAUTH2_PROVIDER": "google"}, http.MethodGet, "/oauth2/google/redirect", true},
  54. {"oauth2 callback", map[string]string{"OAUTH2_PROVIDER": "google"}, http.MethodGet, "/oauth2/google/callback", false},
  55. }
  56. for _, scenario := range scenarios {
  57. t.Run(scenario.name, func(t *testing.T) {
  58. configureTestOptions(t, scenario.env)
  59. r := httptest.NewRequest(scenario.method, scenario.path, nil)
  60. if result := isSessionStartRoute(r); result != scenario.expected {
  61. t.Errorf(`Unexpected result for %s %q, got %v instead of %v`, scenario.method, scenario.path, result, scenario.expected)
  62. }
  63. })
  64. }
  65. }