4
0

icon_integration_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package api_test
  4. import (
  5. "errors"
  6. "testing"
  7. miniflux "miniflux.app/v2/client"
  8. "miniflux.app/v2/internal/http/server/servertest"
  9. )
  10. func TestGetFeedIcon(t *testing.T) {
  11. t.Parallel()
  12. testConfig := requireIntegrationTestConfig(t)
  13. fixture := servertest.NewFeedFixture(t)
  14. regularUserClient, _ := testConfig.newRegularUser(t)
  15. feedID := fixture.Subscribe(t, regularUserClient)
  16. icon, err := regularUserClient.FeedIcon(feedID)
  17. if err != nil {
  18. t.Fatal(err)
  19. }
  20. if icon == nil {
  21. t.Fatalf(`Invalid icon, got nil`)
  22. }
  23. if icon.MimeType != "image/png" {
  24. t.Fatalf(`Invalid mime type, got %q`, icon.MimeType)
  25. }
  26. if len(icon.Data) == 0 {
  27. t.Fatalf(`Invalid data, got empty`)
  28. }
  29. icon, err = regularUserClient.Icon(icon.ID)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. if icon == nil {
  34. t.Fatalf(`Invalid icon, got nil`)
  35. }
  36. if icon.MimeType != "image/png" {
  37. t.Fatalf(`Invalid mime type, got %q`, icon.MimeType)
  38. }
  39. if len(icon.Data) == 0 {
  40. t.Fatalf(`Invalid data, got empty`)
  41. }
  42. }
  43. func TestGetFeedIconWithInexistingFeedID(t *testing.T) {
  44. t.Parallel()
  45. testConfig := requireIntegrationTestConfig(t)
  46. client := testConfig.newAdminClient()
  47. _, err := client.FeedIcon(123456789)
  48. if !errors.Is(err, miniflux.ErrNotFound) {
  49. t.Fatalf(`Fetching the icon of an inexisting feed should raise an error, got %v`, err)
  50. }
  51. }
  52. func TestGetIconWithInexistingIconID(t *testing.T) {
  53. t.Parallel()
  54. testConfig := requireIntegrationTestConfig(t)
  55. client := testConfig.newAdminClient()
  56. _, err := client.Icon(123456789)
  57. if !errors.Is(err, miniflux.ErrNotFound) {
  58. t.Fatalf(`Fetching an inexisting icon should return a "not found" error, got %v`, err)
  59. }
  60. }
  61. func TestGetIconByIconIDFromAnotherUser(t *testing.T) {
  62. t.Parallel()
  63. testConfig := requireIntegrationTestConfig(t)
  64. fixture := servertest.NewFeedFixture(t)
  65. // The owner subscribes to a feed, which fetches and stores its icon.
  66. ownerClient, _ := testConfig.newRegularUser(t)
  67. feedID := fixture.Subscribe(t, ownerClient)
  68. ownerIcon, err := ownerClient.FeedIcon(feedID)
  69. if err != nil {
  70. t.Fatal(err)
  71. }
  72. if ownerIcon == nil {
  73. t.Fatalf(`Invalid icon, got nil`)
  74. }
  75. // The owner can fetch its own icon by icon ID.
  76. if _, err := ownerClient.Icon(ownerIcon.ID); err != nil {
  77. t.Fatalf(`The owner should be able to fetch its own icon, got %v`, err)
  78. }
  79. // Another user without access to that feed must not be able to fetch the icon.
  80. otherClient, _ := testConfig.newRegularUser(t)
  81. if _, err := otherClient.Icon(ownerIcon.ID); !errors.Is(err, miniflux.ErrNotFound) {
  82. t.Fatalf(`Fetching an icon owned by another user should return a "not found" error, got %v`, err)
  83. }
  84. }